@tenphi/tasty 0.0.0-snapshot.4b32dee → 0.0.0-snapshot.4b75cd6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +418 -381
  2. package/dist/babel-types-Dc5zghyE.d.ts +18 -0
  3. package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
  4. package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
  5. package/dist/chunks/build-config--0qoqt_P.js +60 -0
  6. package/dist/chunks/build-config--0qoqt_P.js.map +1 -0
  7. package/dist/{collector-B3OsM252.js → chunks/collector-zp5BrLF0.js} +10 -127
  8. package/dist/chunks/collector-zp5BrLF0.js.map +1 -0
  9. package/dist/chunks/config-engine-BaLq8HrX.js +272 -0
  10. package/dist/chunks/config-engine-BaLq8HrX.js.map +1 -0
  11. package/dist/chunks/config-file-DlZXJMj8.js +25 -0
  12. package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
  13. package/dist/chunks/css-definitions-CfXZ3tU9.js +910 -0
  14. package/dist/chunks/css-definitions-CfXZ3tU9.js.map +1 -0
  15. package/dist/{css-resources-Cyl_axbI.js → chunks/css-resources-P7IBUUZs.js} +2 -9
  16. package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
  17. package/dist/chunks/debug--OC-WA-Q.js +502 -0
  18. package/dist/chunks/debug--OC-WA-Q.js.map +1 -0
  19. package/dist/chunks/dsl-CsFl9LGn.js +1458 -0
  20. package/dist/chunks/dsl-CsFl9LGn.js.map +1 -0
  21. package/dist/chunks/hydration-TRcz5vnk.js +41 -0
  22. package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
  23. package/dist/chunks/react-runtime-DnZ6M1Iv.js +691 -0
  24. package/dist/chunks/react-runtime-DnZ6M1Iv.js.map +1 -0
  25. package/dist/chunks/runtime-engine-J9X_h-Pw.js +2435 -0
  26. package/dist/chunks/runtime-engine-J9X_h-Pw.js.map +1 -0
  27. package/dist/chunks/runtime-state-o_v3Bj7b.js +152 -0
  28. package/dist/chunks/runtime-state-o_v3Bj7b.js.map +1 -0
  29. package/dist/{merge-styles-DuoZEsm9.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
  30. package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
  31. package/dist/chunks/style-engine-D6lC3O3G.js +5626 -0
  32. package/dist/chunks/style-engine-D6lC3O3G.js.map +1 -0
  33. package/dist/{css-writer-Bgowobbx.js → chunks/zero-engine-BnjoV04F.js} +65 -145
  34. package/dist/chunks/zero-engine-BnjoV04F.js.map +1 -0
  35. package/dist/{collector-BTVXj2hS.d.ts → collector-D2OT6I2G.d.ts} +6 -5
  36. package/dist/{config-LfIDmVHx.d.ts → config-C4ftFxgI.d.ts} +51 -47
  37. package/dist/core/index.d.ts +5 -5
  38. package/dist/core/index.js +9 -6
  39. package/dist/hydrate-CRyjjAyl.d.ts +22 -0
  40. package/dist/{index-Bm9ltvdH.d.ts → index-DxQNRj50.d.ts} +275 -244
  41. package/dist/index.d.ts +5 -5
  42. package/dist/index.js +11 -922
  43. package/dist/{merge-styles-BcLl1u_d.d.ts → merge-styles-D39qBtox.d.ts} +2 -3
  44. package/dist/ssr/astro-client.d.ts +1 -1
  45. package/dist/ssr/astro-client.js +1 -14
  46. package/dist/ssr/astro-client.js.map +1 -1
  47. package/dist/ssr/astro-middleware-extract-static.d.ts +1 -2
  48. package/dist/ssr/astro-middleware-extract-static.js +1 -1
  49. package/dist/ssr/astro-middleware-extract.d.ts +1 -2
  50. package/dist/ssr/astro-middleware-extract.js +1 -1
  51. package/dist/ssr/astro-middleware-static.d.ts +1 -2
  52. package/dist/ssr/astro-middleware-static.js +1 -12
  53. package/dist/ssr/astro-middleware-static.js.map +1 -1
  54. package/dist/ssr/astro-middleware.d.ts +1 -2
  55. package/dist/ssr/astro-middleware.js +1 -13
  56. package/dist/ssr/astro-middleware.js.map +1 -1
  57. package/dist/ssr/astro.d.ts +8 -16
  58. package/dist/ssr/astro.js +220 -1
  59. package/dist/ssr/astro.js.map +1 -0
  60. package/dist/ssr/client.d.ts +2 -0
  61. package/dist/ssr/client.js +2 -0
  62. package/dist/ssr/index.d.ts +5 -25
  63. package/dist/ssr/index.js +5 -5
  64. package/dist/ssr/index.js.map +1 -1
  65. package/dist/ssr/next-config.d.ts +3 -5
  66. package/dist/ssr/next-config.js +43 -35
  67. package/dist/ssr/next-config.js.map +1 -1
  68. package/dist/ssr/next.d.ts +3 -9
  69. package/dist/ssr/next.js +7 -38
  70. package/dist/ssr/next.js.map +1 -1
  71. package/dist/static/index.d.ts +8 -9
  72. package/dist/static/index.js +4 -22
  73. package/dist/static/index.js.map +1 -1
  74. package/dist/static/inject.d.ts +1 -2
  75. package/dist/{index-BmogEzTo.d.ts → types-CYQIhUg1.d.ts} +856 -862
  76. package/dist/zero/babel.d.ts +73 -2
  77. package/dist/zero/babel.js +81 -144
  78. package/dist/zero/babel.js.map +1 -1
  79. package/dist/zero/index.d.ts +63 -8
  80. package/dist/zero/index.js +25 -2
  81. package/dist/zero/index.js.map +1 -0
  82. package/dist/zero/next.d.ts +4 -5
  83. package/dist/zero/next.js +3 -38
  84. package/dist/zero/next.js.map +1 -1
  85. package/docs/README.md +4 -1
  86. package/docs/adoption.md +25 -17
  87. package/docs/ai-agents.md +69 -34
  88. package/docs/comparison.md +9 -8
  89. package/docs/configuration.md +204 -70
  90. package/docs/debug.md +5 -7
  91. package/docs/design-system.md +129 -15
  92. package/docs/dsl.md +327 -117
  93. package/docs/getting-started.md +81 -22
  94. package/docs/injector.md +41 -40
  95. package/docs/llms.txt +31 -0
  96. package/docs/methodology.md +48 -23
  97. package/docs/migration-v3.md +3 -3
  98. package/docs/pipeline.md +55 -28
  99. package/docs/plugins.md +22 -42
  100. package/docs/react-api.md +76 -11
  101. package/docs/runtime-benchmarks.md +182 -105
  102. package/docs/ssr.md +92 -66
  103. package/docs/styles.md +169 -33
  104. package/docs/tasty-static.md +176 -58
  105. package/harness/dev.harnesspm/rules/usage.md +12 -0
  106. package/harness/dev.harnesspm/scripts/render.mjs +329 -0
  107. package/harness/dev.harnesspm/scripts/styles.mjs +409 -0
  108. package/harness/plugin.json +20 -0
  109. package/package.json +109 -49
  110. package/tasty.config.ts +1 -0
  111. package/dist/astro-CeYENy2x.js +0 -301
  112. package/dist/astro-CeYENy2x.js.map +0 -1
  113. package/dist/async-storage-DKK-wTD4.js +0 -44
  114. package/dist/async-storage-DKK-wTD4.js.map +0 -1
  115. package/dist/babel-DWCsafYw.d.ts +0 -83
  116. package/dist/collector-B3OsM252.js.map +0 -1
  117. package/dist/config-B3gPdCqd.js +0 -12421
  118. package/dist/config-B3gPdCqd.js.map +0 -1
  119. package/dist/context-CA8YKeMn.js +0 -24
  120. package/dist/context-CA8YKeMn.js.map +0 -1
  121. package/dist/core-pCOhTNoz.js +0 -1723
  122. package/dist/core-pCOhTNoz.js.map +0 -1
  123. package/dist/css-resources-Cyl_axbI.js.map +0 -1
  124. package/dist/css-writer-Bgowobbx.js.map +0 -1
  125. package/dist/format-global-rules-DklyaXv-.js +0 -22
  126. package/dist/format-global-rules-DklyaXv-.js.map +0 -1
  127. package/dist/format-rules-XRw9u7d4.js +0 -104
  128. package/dist/format-rules-XRw9u7d4.js.map +0 -1
  129. package/dist/hydrate-CNOmZprz.js +0 -37
  130. package/dist/hydrate-CNOmZprz.js.map +0 -1
  131. package/dist/index.js.map +0 -1
  132. package/dist/keyframes-DE-OE76F.js +0 -535
  133. package/dist/keyframes-DE-OE76F.js.map +0 -1
  134. package/dist/merge-styles-DuoZEsm9.js.map +0 -1
  135. package/dist/resolve-recipes-H9NqOQuP.js +0 -144
  136. package/dist/resolve-recipes-H9NqOQuP.js.map +0 -1
  137. package/dist/ssr-collector-ref-COs_ioWl.js +0 -29
  138. package/dist/ssr-collector-ref-COs_ioWl.js.map +0 -1
@@ -1,7 +1,7 @@
1
1
  # Runtime Benchmarks
2
2
 
3
3
  Tasty keeps its performance claims in reproducible benchmarks rather than
4
- combining unlike measurements into one score. The repository measures three
4
+ combining unlike measurements into one score. The repository measures five
5
5
  different costs:
6
6
 
7
7
  1. Style parsing and generation in Node.
@@ -34,37 +34,55 @@ code paths in headless Chromium. The first checkout may require
34
34
  current `dist/` — run `pnpm build` first.
35
35
 
36
36
  Run the Node and browser suites separately so they do not compete for CPU. The
37
- browser timer has 0.1 ms resolution, so both browser benchmarks perform many
37
+ browser timer has 0.1 ms resolution, so the browser benchmarks perform many
38
38
  matched operations per sample and divide the absolute difference by the number
39
- of elements or rules. Machine load, browser versions, and CPU power will move
40
- the results.
39
+ of elements, rules or interactions. Machine load, browser versions, and CPU
40
+ power will move the results — on a loaded machine the absolute columns drift
41
+ several percent while the raw/Tasty delta holds, so read the delta.
42
+
43
+ **On a laptop, check the power state first.** Low Power Mode caps CPU frequency,
44
+ and it is the single largest source of error here — larger than background load.
45
+ Measured on the machine below, running on battery with Low Power Mode enabled
46
+ made every one of the 53 Node cases slower, by a median of 26%, and halving the
47
+ background load recovered only 3 points of that. A frequency cap scales every
48
+ case by roughly the same factor, so it does not look like noise; it looks like a
49
+ uniformly slower library. Verify before trusting a run:
50
+
51
+ ```bash
52
+ pmset -g ps | head -2 # want 'AC Power'
53
+ pmset -g | grep -i lowpowermode # want 0
54
+ ```
41
55
 
42
56
  ## Core Style Pipeline
43
57
 
44
- The following numbers are single-call throughput measured on an Apple M1 Max
45
- with Node 22:
46
-
47
- | Operation | ops/sec | Latency (mean) |
48
- | ----------------------------------------------------------- | -------------------: | -------------: |
49
- | `renderStyles` — 5 flat properties (cold) | ~60,000 | ~17 us |
50
- | `renderStyles` — state map with media/hover/modifier (cold) | ~18,500 | ~54 us |
51
- | `renderStyles` — same styles (cached) | ~5,800,000 | ~0.17 us |
52
- | `parseStateKey` — simple key like `:hover` (cold) | ~790,000 | ~1.3 us |
53
- | `parseStateKey` — complex OR/AND/NOT key (cold) | ~140,000 | ~7 us |
54
- | `parseStateKey` — any key (cached) | ~3,400,000–8,300,000 | ~0.1–0.3 us |
55
- | `parseStyle` — value tokens like `2x 4x` (cold) | ~344,000 | ~2.9 us |
56
- | `parseStyle` — color tokens (cold) | ~567,000 | ~1.8 us |
57
- | `parseStyle` — any value (cached) | ~15,250,000 | ~0.07 us |
58
+ Single-call throughput, three consecutive runs on an Apple M3 Pro with Node
59
+ 24.18.0 on AC power:
60
+
61
+ | Operation | ops/sec | Latency (mean) |
62
+ | ----------------------------------------------------------- | --------------------: | -------------: |
63
+ | `renderStyles` — 5 flat properties (cold) | 143,000–158,000 | 6.3–7.0 us |
64
+ | `renderStyles` — state map with media/hover/modifier (cold) | 31,000–36,000 | 28–32 us |
65
+ | `renderStyles` — OR state map across contexts (cold) | 13,000–14,000 | 71–76 us |
66
+ | `renderStyles` — same styles (cached) | 9,830,000–10,420,000 | ~0.10 us |
67
+ | `parseStateKey` — simple key like `:hover` (cold) | 1,910,000–1,980,000 | ~0.50 us |
68
+ | `parseStateKey` — value modifier key (cold) | 1,120,000–1,160,000 | ~0.90 us |
69
+ | `parseStateKey` — complex OR/AND/NOT key (cold) | 341,000–357,000 | 2.8–2.9 us |
70
+ | `parseStateKey` — any key (cached) | 4,900,000–16,530,000 | 0.10–0.20 us |
71
+ | `parseStyle` — value tokens like `2x 4x` (cold) | 575,000–605,000 | ~1.7 us |
72
+ | `parseStyle` — color tokens (cold) | 1,160,000–1,240,000 | 0.80–0.90 us |
73
+ | `parseStyle` — layered functions (cold) | 175,000–184,000 | 5.4–5.7 us |
74
+ | `parseStyle` — any value (cached) | 29,500,000–30,750,000 | ~0.03 us |
58
75
 
59
76
  “Cold” cases use unique inputs to bypass the relevant caches. Cached cases
60
- reuse one input and measure the LRU hot path. Expect roughly ±10% between runs.
61
- These benchmarks do not include React, DOM work, stylesheet injection, style
62
- resolution, layout, or paint.
77
+ reuse one input and measure the LRU hot path. Run-to-run spread on an idle
78
+ machine was 1–7% for most cases, rising to 10–16% for the two `renderStyles`
79
+ cold cases. These benchmarks do not include React, DOM work, stylesheet
80
+ injection, style resolution, layout, or paint.
63
81
 
64
82
  The benchmark sources are colocated with the code they exercise:
65
- [`pipeline.bench.ts`](../src/pipeline/pipeline.bench.ts),
66
- [`parseStateKey.bench.ts`](../src/pipeline/parseStateKey.bench.ts), and the
67
- parser benchmark files under [`src/parser`](../src/parser).
83
+ [`pipeline.bench.ts`](https://github.com/tenphi/tasty/blob/main/src/pipeline/pipeline.bench.ts),
84
+ [`parseStateKey.bench.ts`](https://github.com/tenphi/tasty/blob/main/src/pipeline/parseStateKey.bench.ts), and the
85
+ parser benchmark files under [`src/parser`](https://github.com/tenphi/tasty/tree/main/src/parser).
68
86
 
69
87
  ## Empty Wrapper Overhead
70
88
 
@@ -73,7 +91,7 @@ Skipping the style pipeline does not make a `tasty()` component free. Even
73
91
  tracks another fiber, and Tasty still processes and forwards the element's
74
92
  props.
75
93
 
76
- [`tasty-overhead.bench.tsx`](../src/tasty-overhead.bench.tsx) compares 10,000
94
+ [`tasty-overhead.bench.tsx`](https://github.com/tenphi/tasty/blob/main/src/tasty-overhead.bench.tsx) compares 10,000
77
95
  raw `<div className>` siblings with 10,000 instances of one module-scoped
78
96
  `tasty({})` component. Both receive the same props, and the benchmark fails if
79
97
  they do not produce equivalent DOM.
@@ -85,19 +103,19 @@ excludes layout, paint, and stylesheet matching. Every commit is wrapped in
85
103
  `flushSync`, keeping its synchronous reconciliation and commit inside the
86
104
  sample. This does not estimate React's concurrent scheduling latency.
87
105
 
88
- On an Apple M3 Pro with React 19.2.4 and Chromium 151, three consecutive runs
106
+ On an Apple M3 Pro with React 19.2.8 and Chromium 151, three consecutive runs
89
107
  produced these ranges:
90
108
 
91
- | Work on 10,000 siblings | Raw elements | `tasty({})` | Extra per wrapped element |
92
- | ----------------------------------- | -----------: | -----------: | ------------------------: |
93
- | Mount + remove | 4.5–4.9 ms | 14.0–14.9 ms | 0.95–1.00 us |
94
- | Rerender, same host props | 1.3–1.4 ms | 10.9–11.4 ms | 0.96–1.00 us |
95
- | Rerender, change one host attribute | 2.8–3.4 ms | 15.0–15.7 ms | 1.21–1.27 us |
109
+ | Work on 10,000 siblings | Raw elements | `tasty({})` | Extra per wrapped element |
110
+ | ----------------------------------- | -----------: | ----------: | ------------------------: |
111
+ | Mount + remove | 4.2–4.3 ms | 9.2–9.7 ms | 0.50–0.54 us |
112
+ | Rerender, same host props | 1.2–1.3 ms | 6.3–6.5 ms | 0.51–0.52 us |
113
+ | Rerender, change one host attribute | 2.5–2.7 ms | 11.2–11.6 ms | 0.86–0.91 us |
96
114
 
97
115
  The useful result is the raw/Tasty time difference divided by 10,000, not the
98
116
  ratio between the two times. The ratio becomes large because the raw baseline
99
- is tiny. In this synthetic workload, an empty wrapper adds roughly 1 us per
100
- participating element, or 1.2–1.3 us when React also changes a DOM attribute.
117
+ is tiny. In this synthetic workload, an empty wrapper adds roughly 0.5 us per
118
+ participating element, or ~0.9 us when React also changes a DOM attribute.
101
119
 
102
120
  This is the floor Tasty consumes when it has no styling job. It is not a
103
121
  page-level score. Real trees include application components, effects, layout,
@@ -107,7 +125,7 @@ snapshot experiment with controlled garbage collection.
107
125
 
108
126
  ## Cold Generation and Injection
109
127
 
110
- [`tasty-injection.bench.ts`](../src/tasty-injection.bench.ts) measures the extra
128
+ [`tasty-injection.bench.ts`](https://github.com/tenphi/tasty/blob/main/src/tasty-injection.bench.ts) measures the extra
111
129
  work when Tasty must generate and inject CSS that an otherwise equivalent page
112
130
  already has. It does not compare different stylesheet insertion techniques.
113
131
 
@@ -142,17 +160,23 @@ ranges:
142
160
 
143
161
  | Workload | CSS already present | Tasty runtime | Incremental Tasty cost |
144
162
  | ---------------------------------------------------- | ------------------: | -------------: | ---------------------: |
145
- | One new rule + immediate resolution, per transaction | 2.8–3.3 us | 110.3–113.8 us | 107.3–111.0 us |
146
- | 1,000 new rules + one resolution | 1.86–2.06 ms | 9.01–9.98 ms | 7.13–7.92 ms |
147
- | 1,000-rule workload, incremental cost per rule | — | — | 7.1–7.9 us |
163
+ | One new rule + immediate resolution, per transaction | 2.6–3.0 us | 102.8–107.0 us | 100.3–104.3 us |
164
+ | 1,000 new rules + one resolution | 1.69–1.79 ms | 7.42–7.67 ms | 5.73–5.94 ms |
165
+ | 1,000-rule workload, incremental cost per rule | — | — | 5.7–5.9 us |
148
166
 
149
167
  Directly compared, injecting 1,000 rules before one resolution boundary cost
150
- about 66–71 times as much in total as injecting one rule and resolving it—not
151
- 1,000 times as much. Its average incremental cost per rule was about 14–16
168
+ about 55–59 times as much in total as injecting one rule and resolving it—not
169
+ 1,000 times as much. Its average incremental cost per rule was about 17–18
152
170
  times lower. This is the same Tasty generation and injection path in both cases;
153
171
  the group amortizes fixed transaction work and lets the browser resolve all the
154
172
  stylesheet writes together.
155
173
 
174
+ The per-transaction single-rule figure is the one number here that engine work
175
+ does not move: it is dominated by the browser's injection-to-resolution
176
+ boundary, which is crossed once per rule regardless of how fast generation is.
177
+ The 1,000-rule column, where Tasty's own generation dominates, is where engine
178
+ changes show up.
179
+
156
180
  The subtraction is the meaningful result. It includes Tasty's cold style
157
181
  generation, cache and injector bookkeeping, rule insertion, and any additional
158
182
  style invalidation exposed by that workload's resolution boundary. It does not
@@ -173,49 +197,65 @@ The benchmarks above measure mounting and whole-tree updates. A running
173
197
  application spends most of its time on neither. It flips mods — hovered,
174
198
  pressed, selected, expanded — on elements whose styles never change, one
175
199
  element at a time, and it mounts and unmounts small styled subtrees as menus
176
- and dialogs open. Both paths go through the state-map and ref-counting
177
- machinery rather than the parser, so a regression in them is invisible to every
200
+ and dialogs open. Both paths go through mod handling and the chunk cache
201
+ rather than the parser, so a regression in them is invisible to every
178
202
  other benchmark here.
179
203
 
180
- [`tasty-interaction.bench.tsx`](../src/tasty-interaction.bench.tsx) pairs each
204
+ [`tasty-interaction.bench.tsx`](https://github.com/tenphi/tasty/blob/main/src/tasty-interaction.bench.tsx) pairs each
181
205
  case with a raw-DOM equivalent driven by a hand-written stylesheet that
182
206
  produces the same computed color and background in both states. The benchmark
183
207
  fails if either arm resolves to anything else, so an arm that quietly rendered
184
208
  unstyled elements cannot report a flattering number.
185
209
 
186
210
  Each leaf owns its own `useState`, which is what keeps a single-element
187
- interaction single: re-rendering the root to flip one row would time 1,000
188
- elements. One toggle is far below Chromium's 0.1 ms timer resolution, so a
189
- sample performs 100 independent interactions — each its own `flushSync` commit
190
- and its own computed-style read — and the churn case performs 10 open/close
191
- cycles. Divide the raw/Tasty difference by those counts.
192
-
193
- On an Apple M1 Max with React 19.2.8 and Chromium 151, three consecutive runs
194
- produced these ranges:
195
-
196
- | Workload | Raw elements | Tasty mods | Extra per unit |
197
- | ----------------------------------------------------- | -----------: | -----------: | ---------------------------: |
198
- | 100 single-element mod toggles in a 1,000-element tree | 9.6–9.8 ms | 9.9–10.1 ms | 1.5–4.7 us per interaction |
199
- | 10 mount + unmount cycles of a 200-element subtree | 3.5–3.7 ms | 5.7–5.8 ms | 1.05–1.14 us per element |
211
+ interaction single: re-rendering the root to flip one row would time the whole
212
+ tree. One toggle is far below Chromium's 0.1 ms timer resolution, so a sample
213
+ flips a 100-element tree three times over — 300 commits — and the churn case
214
+ performs 20 open/close cycles. Divide the raw/Tasty difference by those counts.
215
+
216
+ Two things had to be sized deliberately, and both are the difference between a
217
+ readable number and noise:
218
+
219
+ - **The tree is small (100 elements), not large.** React locates a leaf's
220
+ pending update by walking the sibling list, so in a 1,000-element tree a
221
+ single-element update costs ~68 us of traversal — identical in both arms and
222
+ an order of magnitude above anything the styling layer contributes.
223
+ - **The sample resolves style once, not once per flip.** Forcing a recalc
224
+ between flips costs ~70 us in both arms, which buries the delta the same way.
225
+ The browser's side of an interaction is real, but it is the browser's;
226
+ resolution boundaries are what the injection benchmark above measures.
227
+
228
+ The contract check also reads the injected CSS **before** any toggle and fails
229
+ if the hovered rule is not already there. That a style map's states all ship in
230
+ one chunk on first render is the premise of this case; if the hovered rule
231
+ arrived lazily, the first sample would be timing injection.
232
+
233
+ On an Apple M3 Pro with React 19.2.8 and Chromium 151, three consecutive runs:
234
+
235
+ | Workload | Raw elements | Tasty mods | Extra per unit |
236
+ | ---------------------------------------------------- | -----------: | ---------: | -----------------------: |
237
+ | 300 single-element mod toggles in a 100-element tree | 1.7–1.8 ms | 2.0–2.1 ms | 1.2–1.3 us / interaction |
238
+ | 20 mount + unmount cycles of a 200-element subtree | 5.2–5.4 ms | 8.3–8.6 ms | 0.77–0.81 us / element |
239
+
240
+ The absolute columns move several percent with machine load; the delta between
241
+ the arms is the stable quantity, so read that rather than either column.
200
242
 
201
243
  Two things are worth reading out of this.
202
244
 
203
- A mod flip on an already-mounted element is close to free. The delta is a few
204
- microseconds and is the same order as the run-to-run spread of the raw
205
- baseline, so treat "under 5 us" as the claim rather than any single figure
206
- inside that range. The CSS for both states already exists, both arms perform
207
- the same commit and the same style resolution, and Tasty's remaining work is
208
- picking a class name.
245
+ A mod flip on an already-mounted element costs about 1.2 us. The CSS for both
246
+ states already exists — Tasty emits every state of a style map in one chunk on
247
+ first render — so both arms perform the same commit, and what is left is
248
+ Tasty's props and mod handling. That is the same order as the ~0.5 us empty
249
+ wrapper measured above, which is most of where it comes from.
209
250
 
210
- Subtree churn, by contrast, is not about styling at all. Its per-element cost
211
- lands on top of the ~1 us empty-wrapper mount cost measured above, which is
212
- where essentially all of it comes from — the styles are already cached, so
251
+ Subtree churn is not about styling at all. Its ~0.8 us per element sits right
252
+ on the empty-wrapper mount cost, because the styles are already cached:
213
253
  reopening a menu re-pays the React wrapper, not the style pipeline.
214
254
 
215
255
  ## Page-Load Cold Start
216
256
 
217
257
  Every benchmark above deliberately excludes the network, module compilation and
218
- the first render. [`scripts/cold-start`](../scripts/cold-start) measures exactly
258
+ the first render. [`scripts/cold-start`](https://github.com/tenphi/tasty/tree/main/scripts/cold-start) measures exactly
219
259
  those: what a visitor waits for between requesting a page and seeing styled
220
260
  content, in a real Chromium under CDP network and CPU throttling.
221
261
 
@@ -236,53 +276,89 @@ rather than counted in animation frames — `requestAnimationFrame` fires before
236
276
  paint, so a page that commits fast can reach its second frame with nothing
237
277
  painted yet.
238
278
 
239
- On an Apple M1 Max with React 19.2.8 and Chromium 151, first contentful paint:
240
-
241
- | Link / CPU | baseline | runtime | prewarm | Tasty's cost |
242
- | --------------------- | -------: | ------: | ------: | -----------: |
243
- | No throttling, 1x | 40 ms | 48 ms | 52 ms | +8 ms |
244
- | Fast 4G, 1x | 744 ms | 936 ms | 936 ms | +192 ms |
245
- | Slow 4G, 1x | 2776 ms | 3792 ms | 3788 ms | +1016 ms |
246
- | No throttling, 4x CPU | 140 ms | 192 ms | 188 ms | +52 ms |
247
- | Fast 4G, 4x CPU | 812 ms | 1052 ms | 1056 ms | +240 ms |
248
- | Slow 4G, 4x CPU | 2824 ms | 3908 ms | 3908 ms | +1084 ms |
249
-
250
- **The cost is the bundle, not the work.** Minified and brotli-compressed, the
251
- library is 56.1 KB (201 KB raw) on top of React's 50.7 KB. On Slow 4G that
252
- extra transfer alone accounts for 1,027 ms of the 1,016 ms FCP delta — the
253
- whole of it, within noise. Everything Tasty then *does* is small by comparison:
254
-
255
- | Phase (Slow 4G, 1x) | baseline | runtime | prewarm |
256
- | ------------------------ | -------: | ------: | ------: |
257
- | js+css transfer | 1567 ms | 2594 ms | 2588 ms |
258
- | module compile (shared) | 3.2 ms | 3.8 ms | 3.6 ms |
259
- | tasty top-level execute | — | 0.9 ms | 0.9 ms |
260
- | `configure()` | — | 0.5 ms | 0.5 ms |
261
- | prewarm | — | — | 4.4 ms |
262
- | render 1st component | 1.9 ms | 7.5 ms | 2.3 ms |
263
- | render 49 more | 1.0 ms | 5.5 ms | 5.1 ms |
279
+ Two things about the payload decide whether this measures a deployment or a
280
+ straw man, so both are enforced rather than assumed:
281
+
282
+ - **Assets are served brotli-compressed**, the way a static host serves them.
283
+ The bundle is 51.5 KB on the wire and 180 KB decoded; putting the decoded
284
+ bytes on a 1.6 Mbps link would add ~700 ms and charge it to Tasty. The run
285
+ reads `encodedBodySize` back out of resource timing and fails if what
286
+ crossed the wire is not the compressed size the table reports.
287
+ - **The bundle is built from what the page imports** (`tasty`, `configure`,
288
+ `computeStyles`, `tastyDebug`), so it is tree-shaken as an application's
289
+ would be. Re-exporting the whole library adds ~4 KB brotli of code no page
290
+ here calls.
291
+
292
+ On an Apple M3 Pro with React 19.2.8 and Chromium 151, first contentful paint,
293
+ median of three full runs of the matrix:
294
+
295
+ | Link / CPU | baseline | runtime | prewarm | Tasty's cost | noise |
296
+ | --------------------- | -------: | ------: | ------: | -----------: | ----: |
297
+ | No throttling, 1x | 36 ms | 40 ms | 40 ms | +4 ms | 0 ms |
298
+ | Fast 4G, 1x | 628 ms | 672 ms | 688 ms | +44 ms | 20 ms |
299
+ | Slow 4G, 1x | 2044 ms | 2308 ms | 2308 ms | +264 ms | 24 ms |
300
+ | No throttling, 4x CPU | 112 ms | 144 ms | 144 ms | +32 ms | 16 ms |
301
+ | Fast 4G, 4x CPU | 656 ms | 728 ms | 736 ms | +72 ms | 4 ms |
302
+ | Slow 4G, 4x CPU | 2064 ms | 2360 ms | 2360 ms | +296 ms | 8 ms |
303
+
304
+ The `noise` column is not an estimate. The `baseline` page contains no Tasty at
305
+ all, so its three samples should be identical; the spread they actually show is
306
+ this cell's measurement error, and it applies to the other columns too.
307
+
308
+ Read that column before any other. Only the Slow 4G rows carry a cost an order
309
+ of magnitude above their own noise. The unthrottled 1x row (+4 ms) means "too
310
+ small to measure this way", not "4 ms". And a single run is genuinely not
311
+ enough here: taken alone, the first of these three runs put Fast 4G 1x at
312
+ +72 ms, which the median over three corrects to +44 ms.
313
+
314
+ For the same reason, `prewarm` landing above `runtime` in the Fast 4G 1x row is
315
+ noise, not a cost — the two modes differ only in when the engine compiles, and
316
+ that difference is measured in the phase table below, not in FCP.
317
+
318
+ **The cost is the bundle, not the work.** On Slow 4G the extra transfer alone
319
+ accounts for 263 ms of the 264 ms FCP delta — effectively all of it. Everything
320
+ Tasty then *does* is small by comparison (median of three runs):
321
+
322
+ | Phase (Slow 4G, 1x) | baseline | runtime | prewarm |
323
+ | ----------------------- | -------: | ------: | ------: |
324
+ | js+css transfer | 1423 ms | 1686 ms | 1690 ms |
325
+ | module compile (shared) | 3.5 ms | 3.3 ms | 3.0 ms |
326
+ | tasty top-level execute | — | 1.2 ms | 0.8 ms |
327
+ | `configure()` | — | 0.6 ms | 0.4 ms |
328
+ | prewarm | — | — | 3.3 ms |
329
+ | render 1st component | 3.0 ms | 7.3 ms | 1.9 ms |
330
+ | render 49 more | 1.3 ms | 5.2 ms | 3.8 ms |
264
331
 
265
332
  Importing Tasty costs about 1 ms of top-level execution; `configure()` costs
266
- half of one. The rest of the CPU delta — roughly 10 ms for 50 components — is
333
+ half of one. The rest of the CPU delta — about 10 ms for 50 components — is
267
334
  generation and injection, which is the cost the injection benchmark isolates.
268
335
 
336
+ One asymmetry is worth naming: the control links a render-blocking stylesheet
337
+ and the runtime modes have none, so the control's first paint waits for CSS the
338
+ runtime modes never request. That is the real difference between the two
339
+ delivery models, not a thumb on the scale, but it means the FCP delta is not
340
+ purely "what Tasty costs to execute".
341
+
269
342
  **Prewarming moves the wake-up, it does not remove it.** The first styled render
270
- is ~4.5 ms more expensive than the ones after it, because that is when the
343
+ is ~5.4 ms more expensive than the ones after it, because that is when the
271
344
  engine's deferred payload is actually compiled. A throwaway `computeStyles()`
272
- against a detached root pays it early: `render 1st` drops from 7.5 ms to
273
- 2.3 ms. The prewarm itself costs 4.4 ms, so FCP does not move. It is worth
274
- doing only when something else can overlap it, or when the first render is on a
275
- latency-critical path and the page has idle time before it.
345
+ against a detached root pays it early: `render 1st` drops from 7.3 ms to
346
+ 1.9 ms. The prewarm itself costs 3.3 ms, so the work is moved rather than
347
+ removed and FCP does not move. It is worth doing only when something else can
348
+ overlap it, or when the first render is on a latency-critical path and the page
349
+ has idle time before it.
276
350
 
277
351
  **Retained heap.** After a forced collection, the runtime page holds about
278
- 1,050 KB more than the control (2,659 KB vs 1,613 KB) for 50 components — the
352
+ 985 KB more than the control (2,605 KB vs 1,619 KB) for 50 components — the
279
353
  parser caches, the chunk cache, the injector's registry and the generated CSS.
280
354
  The control is not zero either; most of its 1.6 MB is React and the DOM.
281
355
 
282
356
  CPU throttling changes which line moves. At 4x, module compilation of the
283
- larger graph becomes visible (6.3 ms → 25 ms) where at 1x it is free: V8
357
+ larger graph becomes visible (2.6 ms → 19 ms) where at 1x it is free: V8
284
358
  pre-parses at import and compiles lazily, so a slower CPU pays for code the
285
- faster one never fully compiled.
359
+ faster one never fully compiled. Transfer numbers from the unthrottled cells
360
+ are not worth reading — with no emulated link, resource timings are scheduling
361
+ jitter.
286
362
 
287
363
  ## Reading the Results Together
288
364
 
@@ -295,16 +371,17 @@ blindly. They describe different paths:
295
371
  rule.
296
372
  - A genuinely new style pays generation and injection once, then becomes
297
373
  reusable.
298
- - A mod flip on an already-styled element pays neither; it is a class-name
299
- change.
374
+ - A mod flip on an already-styled element pays neither; it toggles a `data-*`
375
+ attribute and the class stays the same.
300
376
  - Browser style resolution, layout, and paint depend on the actual document and
301
377
  need application-level profiling.
302
378
 
303
379
  The cold-start measurement is the one that puts the rest in proportion. On a
304
- slow connection, essentially all of Tasty's page-load cost is transferring the
305
- library; the generation and injection the microbenchmarks obsess over is ~10 ms
306
- for 50 components. Bundle size is therefore the lever with the largest effect
307
- on first paint, and the runtime levers matter for what happens after it.
380
+ slow connection, nearly all of Tasty's page-load cost is transferring the
381
+ library — 263 ms of a 264 ms delta — while the generation and injection the
382
+ microbenchmarks obsess over is ~10 ms for 50 components. Bundle size is
383
+ therefore the lever with the largest effect on first paint, and the runtime
384
+ levers matter for what happens after it.
308
385
 
309
386
  The practical optimization target is therefore repeated work: keep style input
310
387
  stable when possible, reuse generated chunks, and generate CSS at build or