From f64067e8f3c539789db3587e7e40c4fe6733082e Mon Sep 17 00:00:00 2001 From: Chris Lorenzo Date: Fri, 20 Nov 2026 12:11:10 -0500 Subject: [PATCH 1/3] docs: renderer 2.0 setup, Building for TVs, text measured before the frame From the 1.8 branch (46ba87e, 1ff8d59, a0808a0, 1e344f0, 7d2d71c and the stream T layout.md entries): - render.md and basics.md: no render or font engine to set; load an SDF font per family and register shader types; renderEngine, fontEngines and stage.shManager listed as removed in renderer 2.0. - deploy/build.md (new, in the sidebar): terser `reduce_funcs: false`. - layout.md: flex text is measured with `measure()` before the frame; points at MIGRATION-1.8.md. - virtual.md: factorScale has no effect since 1.7. - useHold.md: the release handler is `onEnterRelease`. - effects.md: a `shader` tuple's type must be registered. 1.8 said Solid registers `rounded`, which it does not: it names registerShaderType and registerDefaultShaders instead. Co-Authored-By: Claude Opus 5.5 --- docs/_sidebar.md | 1 + docs/articles/basics.md | 4 +--- docs/deploy/build.md | 38 ++++++++++++++++++++++++++++++++++ docs/essentials/effects.md | 2 +- docs/essentials/render.md | 42 +++++++++++++++++++++++++++----------- docs/flow/layout.md | 6 +++--- docs/primitives/useHold.md | 2 +- docs/primitives/virtual.md | 2 +- 8 files changed, 76 insertions(+), 21 deletions(-) create mode 100644 docs/deploy/build.md diff --git a/docs/_sidebar.md b/docs/_sidebar.md index 81d3980d..0c0a8efa 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -55,6 +55,7 @@ - [DOM Renderer](/articles/domrenderer.md) - [SolidTV Renderer](/articles/solidtv_renderer.md) - Build & Deploy + - [Building for TVs](/deploy/build.md) - [RDK Firebolt Integration](/deploy/firebolt.md) - [Tizen/Samsung](/deploy/tizen.md) - [WebOS/LG](/deploy/lg.md) diff --git a/docs/articles/basics.md b/docs/articles/basics.md index f0f7f25a..50f544b8 100644 --- a/docs/articles/basics.md +++ b/docs/articles/basics.md @@ -40,8 +40,6 @@ Config.fontSettings.color = 0xffffffff; // Settings for SolidTV Renderer passed in for starting application Config.rendererOptions = { numImageWorkers: 1, - fontEngines: [SdfTextRenderer], - renderEngine: WebGlCoreRenderer, inspector: Inspector, // Set the resolution based on window height deviceLogicalPixelRatio: window.innerHeight / 1080, @@ -53,7 +51,7 @@ Config.rendererOptions = { Here, we’re setting up a few important things: - We’re defaulting font settings for all `` nodes. -- The `rendererOptions` allow us to pass options to the SolidTV renderer, including the number of image workers, font engines, and pixel ratios. +- The `rendererOptions` allow us to pass options to the SolidTV renderer, including the number of image workers and the pixel ratios. (Renderer 2.0 draws with WebGL and SDF text only, so there is no render engine or font engine to set.) - `boundsMargin` is the preload margin around the viewport, in logical pixels. It defaults to `200`, which is usually what you want — it loads textures ahead of a node scrolling into view. ## Routing with SolidJS Router diff --git a/docs/deploy/build.md b/docs/deploy/build.md new file mode 100644 index 00000000..cf598514 --- /dev/null +++ b/docs/deploy/build.md @@ -0,0 +1,38 @@ +# Building for TVs + +## Minifying with terser + +Build with terser, and turn off its `reduce_funcs` option. Vite does not bundle terser, so install it first (`npm i -D terser`): + +```js +// vite.config.js +export default defineConfig({ + build: { + minify: 'terser', + terserOptions: { + compress: { + // Keeps terser from inlining the renderer's single-use helper + // functions into its scene walk. + reduce_funcs: false, + }, + }, + }, +}); +``` + +`compress` stays on (the other options keep their defaults), so build-time defines such as `__DEV__` and `SOLIDTV_DOM_RENDERING` still fold away. The same option goes to other bundlers' terser plugins, for example `new TerserPlugin({ terserOptions: { compress: { reduce_funcs: false } } })` in webpack, or `--compress reduce_funcs=false` on the terser command line. + +### Why + +With terser's defaults, `@solidtv/renderer` 2.0's scene walk allocates for every node it visits. Terser inlines a single-use helper of the walk, the one that computes a node's world transform, into `ScenePass.visit` as an immediately-invoked function (`!function (s, id, parent) {…}(s, id, parent)`). The function is created again for each node the walk visits, on every frame that walks the scene. + +Set `reduce_funcs: false` and the walk keeps calling the helper. The renderer's allocations for one key press, measured in the SolidTV benchmark (`docs/perf`, allocation mode, every allocation sampled), fall: + +| Scenario | Renderer allocations per press, terser defaults | With `reduce_funcs: false` | +| ---------------------------------------- | ----------------------------------------------- | -------------------------- | +| `rows-ud-auto` (move focus between rows) | 56.7 KiB | 3.4 KiB | +| `virtual-grid` | 67.7 KiB | 8.6 KiB | + +SolidTV's own allocations per press change little (2.4 → 2.1 KiB and 12.5 → 11.0 KiB), since terser inlines fewer of Solid's helpers too. Each figure is one run, and the bundle-size difference was not measured. + +The measurements are in [`docs/perf/results/2026-10-03/profiles.md`](../perf/results/2026-10-03/profiles.md), section "Terser inlining in the renderer's walk". diff --git a/docs/essentials/effects.md b/docs/essentials/effects.md index d91262d5..c68a3910 100644 --- a/docs/essentials/effects.md +++ b/docs/essentials/effects.md @@ -1,6 +1,6 @@ # Shaders and Effects -The shader prop allows you to specify a custom shader. Most of the common use ones have shortcuts like `borderRadius`, `border`, `linearGradient`. These shortcuts get combined to create one dynamic shader from the Renderer. The order that they are listed in the props / style object affect how it gets created and could change the UI. Typically you want borderRadius to be the last one. If you have a custom shader, you'll need to use the `shader` prop and create the directly. Check out this [example](https://github.com/lightning-js/renderer/blob/main/examples/tests/dynamic-shader.ts) from the renderer for more information. +The shader prop allows you to specify a custom shader. Most of the common use ones have shortcuts like `borderRadius`, `border`, `linearGradient`. These shortcuts get combined to create one dynamic shader from the Renderer. The order that they are listed in the props / style object affect how it gets created and could change the UI. Typically you want borderRadius to be the last one. If you have a custom shader, you'll need to use the `shader` prop and create it directly. A shader type named in a `shader` tuple must be registered with the renderer first, with `renderer.registerShaderType(name, type)`; renderer 2.0 draws nothing for an unregistered name and warns. `registerDefaultShaders(renderer)` registers the types Solid's style shortcuts create (`rounded`, `roundedWithBorder`, `roundedWithShadow`, `roundedWithBorderWithShadow`, `shadow`, `holePunch`, `linearGradient`, `radialGradient`). Check out this [example](https://github.com/lightning-js/renderer/blob/main/examples/tests/dynamic-shader.ts) from the renderer for more information. ```jsx const RoundedRectangle = ['RoundedRectangle', { radius: 6 }]; diff --git a/docs/essentials/render.md b/docs/essentials/render.md index c11b2469..123d1ed4 100644 --- a/docs/essentials/render.md +++ b/docs/essentials/render.md @@ -29,13 +29,10 @@ Before calling the Render function, you can set rendererOptions. ```jsx import { render, Config } from '@solidtv/solid'; -import { WebGlCoreRenderer, SdfTextRenderer } from '@solidtv/renderer/webgl'; import { Inspector } from '@solidtv/renderer/inspector'; Config.rendererOptions = { fpsUpdateInterval: logFps ? 1000 : 0, - fontEngines: [SdfTextRenderer], - renderEngine: WebGlCoreRenderer, inspector: Inspector, // textureMemory: { // criticalThreshold: 80e6, @@ -48,6 +45,33 @@ Config.rendererOptions = { render(() => Hello World); ``` +`@solidtv/renderer` 2.0 draws with WebGL and SDF text only, so there is no render engine or font engine to pick and no `@solidtv/renderer/webgl` entry to import. The renderer needs two things from the app before it draws: an SDF font for every font family it names, and each shader type registered under the name it is used by. + +```jsx +import { createRenderer, loadFonts } from '@solidtv/solid'; +import { Rounded, RoundedWithBorder } from '@solidtv/renderer/shaders'; + +const { renderer, render } = createRenderer(); + +// A web font (.ttf, fontUrl) does not draw on the WebGL renderer: convert it +// to an MSDF or SSDF atlas and load that, for every family the app uses. +loadFonts([ + { + type: 'msdf', + fontFamily: 'Roboto', + atlasDataUrl: '/fonts/Roboto-Regular.msdf.json', + atlasUrl: '/fonts/Roboto-Regular.msdf.png', + }, +]); + +renderer.registerShaderType('rounded', Rounded); +renderer.registerShaderType('roundedWithBorder', RoundedWithBorder); + +render(() => Hello World); +``` + +See [Text](/essentials/text.md) for more on fonts, and the renderer's `docs/upgrade-1.x-to-2.0.md` for everything renderer 2.0 changed. When you build for production, read [Building for TVs](/deploy/build.md): a terser setting there removes most of the renderer's per-frame allocations. + For the latest renderer options read the official [renderer documentation](https://www.solid-tv.github.io/solid//api/renderer/interfaces/Renderer.RendererMainSettings.html) ### Config.rendererOptions @@ -98,21 +122,15 @@ For the latest renderer options read the official [renderer documentation](https Optional. Allows inspection of the state of Nodes in the renderer, replicating the node state. Type: `typeof Inspector | false`. -- **renderEngine** - Defines the rendering engine (WebGL or Canvas). WebGL is more performant, while Canvas is more broadly supported. - Type: `typeof CanvasCoreRenderer | typeof WebGlCoreRenderer`. - - **quadBufferSize** Specifies the quad buffer size in bytes. Default: `1048576` (16384 quads x 64 bytes — the most a Uint16 index buffer can address). Was `1310720` before renderer 1.8. -- **fontEngines** - Defines font engines for text rendering (CanvasTextRenderer for Canvas, SdfTextRenderer for WebGL). Enables tree shaking for unused engines. - Default: `[]`. Type: `(typeof SdfTextRenderer | typeof CanvasTextRenderer)[]`. - #### Removed renderer settings - **renderOnlyInViewport**: removed in renderer 1.8. Its `true` behavior is now unconditional — the renderer always draws only what is in view. +- **renderEngine** and **fontEngines**: removed in renderer 2.0. WebGL and SDF text are the only engines. Solid drops them from the options before it creates the renderer and logs one `console.warn` for each in every build (not only in development), so an app that still sets them keeps working; delete them. +- **`renderer.stage.shManager`**: removed in renderer 2.0 (`renderer.registerShaderType(name, type)` replaces `renderer.stage.shManager.registerShaderType(name, type)`). Solid keeps `stage.shManager` working on the WebGL renderer and logs one `console.warn` the first time it is read; change the call. ### Additional Solid-Specific Configurations @@ -141,7 +159,7 @@ Besides `rendererOptions`, the `Config` object exposes several properties specif The property key used to identify the focused state styling. - _Default_: `'$focus'` - **domRendererEnabled**: `boolean` (Default: `false`) - Whether the DOM renderer should be used instead of the SolidTV Canvas renderer. + Whether the DOM renderer should be used instead of the SolidTV WebGL renderer. - **simpleAnimationsEnabled**: `boolean` Allows simple CSS-like transition properties without full engine overhead. - **throttleInput**: `number` diff --git a/docs/flow/layout.md b/docs/flow/layout.md index b6906e78..2f11db48 100644 --- a/docs/flow/layout.md +++ b/docs/flow/layout.md @@ -21,7 +21,7 @@ The engine allocates nothing during a layout pass and writes only the values tha ### One flex engine -Before 1.8 there were two engines, a legacy one and a CSS-aligned one chosen at build time with the `VITE_USE_NEW_FLEX` environment variable. Since 1.8 there is only the CSS-aligned one, with everything below. The variable is ignored; delete it from your `.env`. If your app ran on the legacy engine, see the 1.8 release notes for the layouts that change. +Before 1.8 there were two engines, a legacy one and a CSS-aligned one chosen at build time with the `VITE_USE_NEW_FLEX` environment variable. Since 1.8 there is only the CSS-aligned one, with everything below. The variable is ignored; delete it from your `.env`. If your app ran on the legacy engine, see `MIGRATION-1.8.md` in the repository for the layouts that change. ### Example @@ -43,7 +43,7 @@ const RowStyles = { ; ``` -When a `` with `display: flex` contains text nodes as children, it automatically sets up a listener for the text to load, sets the width and height of the text elements, and then calls `updateLayout` on the container to recalculate the flex layout. +When a `` with `display: flex` contains text nodes as children, Solid measures each text with the renderer's `measure()` right after the change, before the next frame, and calls `updateLayout` on the container to recalculate the flex layout from the measured sizes. It does not wait for the text's `loaded` event. A text whose font is not loaded yet waits for the font, then lays out once. Change a text's props on the element (`fontSize`, `text`, a `transition`), not on its renderer node (`el.lng`): Solid is not told about writes made there, and the container keeps the old size. ### Flex Properties @@ -114,7 +114,7 @@ Note: `alignItems` supports `flexStart`, `flexEnd`, and `center`, but requires t ## Layout Callbacks -When a container with `display: flex` undergoes layout during initial rendering, `updateLayout` is called to calculate the flex layout. You can use `onLayout` hooks to update the element with after flex has performed it's calculations and all text nodes have been loaded. +When a container with `display: flex` undergoes layout during initial rendering, `updateLayout` is called to calculate the flex layout. You can use `onLayout` hooks to update the element with after flex has performed it's calculations and its text has been measured. - **`onLayout`**: Use this callback to update the element after flex calculation. diff --git a/docs/primitives/useHold.md b/docs/primitives/useHold.md index a8f35147..76f79924 100644 --- a/docs/primitives/useHold.md +++ b/docs/primitives/useHold.md @@ -96,7 +96,7 @@ const [onHoldEnter, onHoldRelease] = useHold({ performOnEnterImmediately: false, }); -; +; ``` --- diff --git a/docs/primitives/virtual.md b/docs/primitives/virtual.md index 52886ca2..066b2e0c 100644 --- a/docs/primitives/virtual.md +++ b/docs/primitives/virtual.md @@ -42,7 +42,7 @@ import { VirtualRow, VirtualColumn } from './primitives/Virtual'; - **onEndReached** (`() => void`): Callback triggered when selection moves near the end of the list Requires `onEndReachedThreshold` to be set. - **onEndReachedThreshold** (`number`): Number from end of items when `onEndReached` will be called (default: `undefined`). - **debugInfo** (`boolean`): Logs internal slice recalculations and bounds shifts to console. -- **factorScale** (`boolean`): If `true`, scrolling calculations will take item focus scale into account. +- **factorScale** (`boolean`): **Deprecated; it has no effect since 1.7.** A window shift always moves the row or column by the unscaled slot (item size plus gap), the distance flex moves the items, so a focused item with a `$focus` scale keeps its screen position without it. Remove the prop. - **uniformSize** (`boolean`): If `true` (default), assumes all items are uniform size to calculate scrolling, improving performance. - **children** (`(item: Accessor, index: Accessor) => JSX.Element`): Function that renders each item. - **selected** (`number`): Initial selected index. From 7b596e68fbfc5142f53dcede5b929ed2bb391a11 Mon Sep 17 00:00:00 2001 From: Chris Lorenzo Date: Fri, 20 Nov 2026 12:11:14 -0500 Subject: [PATCH 2/3] docs: MIGRATION-1.8.md, from 1.7.x to 1.8 What #89-#92 changed for apps, adapted from the 1.8 branch's MIGRATION-1.7.md: one flex engine and the flex fixes B5-B12, text sized before the frame and laid out eagerly, one reactive flush per focus change, States changes and B2, diffed state application and per-object style caching, the Row/Column transition cache, B19 draw order, B20, and the terser build setting. Left out, as 1.7.x already shipped them: the renderer 2.0 breaks, the renderEngine/fontEngines/shManager absorption, B1, B3, B4, B13-B17, B21 and the Virtual/VirtualGrid layout changes. Each entry keeps what changes and the upgrade step; the measurements stay in docs/perf/log.md. Co-Authored-By: Claude Opus 5.5 --- MIGRATION-1.8.md | 233 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 233 insertions(+) create mode 100644 MIGRATION-1.8.md diff --git a/MIGRATION-1.8.md b/MIGRATION-1.8.md new file mode 100644 index 00000000..15d4eaaf --- /dev/null +++ b/MIGRATION-1.8.md @@ -0,0 +1,233 @@ +# Migrating to @solidtv/solid 1.8 + +1.8 rewrites Solid's internals to use less CPU and allocate less per key press: +one flex engine, text measured before the frame, draw order that follows the +child order, compiled state styles, and one reactive flush per focus change. +Apps written against ``, `` and the primitives keep their code, +except where this file says otherwise. + +It needs `@solidtv/renderer` 2.0.7 or later (as 1.7.1 did): Solid sizes text +with the renderer's `TextNode.measure()` and orders siblings with +`Node.insertBefore`. The renderer 2.0 breaks themselves came with Solid 1.7; +see the renderer's `docs/upgrade-1.x-to-2.0.md`. + +The measurements behind each change are in `docs/perf/log.md`. + +## Layout and flex + +- **One flex engine.** + - **What changes:** `src/core/flex.ts` and `VITE_USE_NEW_FLEX` are gone; + every build runs the CSS-aligned engine (`flexLayout.ts`). It allocates + nothing during a layout pass and writes only the values that changed. + Apps that did not set the variable now get, where the engines differed: + - a number `padding` also offsets the cross axis (rows start at + `paddingTop` with `alignItems` or wrapping); + - padding arrays and `paddingLeft`/`Top`/`Right`/`Bottom` work (the old + engine produced NaN), and the `margin` array works; + - wrapped lines start at the cross padding, and the height adds the end + padding; + - `flexShrink` shrinks overflowing items and `flexBasis` replaces the + width or height for positioning (the old engine ignored both); + - a container whose items only have `flexShrink` gets + `flexBoundary: 'fixed'`, so it no longer sizes itself to its items; + - no `console.warn` when `flexGrow` has no free space; + - positions are float64 (no float32 rounding such as 109.70999908). + - **Upgrade step:** delete `VITE_USE_NEW_FLEX` from `.env` (it is ignored). + If your app ran on the old engine, check the layouts above. +- **Text in a layout container is sized by Solid, before the frame.** + - **What changes:** a `` whose parent has `display="flex"` or an + `onLayout` is measured with the renderer's `measure()` in Solid's + post-mutation pass. The container's flex and `onLayout` run in that + microtask, before the frame, instead of after the text's `loaded` in a + later frame. Final positions are the same, and they are right in the first + frame that shows the change. A change that leaves a text's size unchanged + lays nothing out. + - **Reads right after mount see the laid-out values.** Code that reads a + flex-derived position or size in the same task as the mount (an + `onFocus` that fires at mount, an effect, a `ref` callback) now gets the + laid-out value. Before, it got the pre-layout value, often 0, so + something positioned from it may move to where it was meant to be. + - **`loaded`.** An `onEvent.loaded` on such a text still fires once per + layout, now after the container's relayout. On the DOM renderer it fires + for every new size, as before. + - **Animations.** A `transition` on a text's `fontSize`, `lineHeight`, + `width` or `height`, and `el.animate()` of its layout props, still lay + the container out on every animated frame, and it ends where the final + size puts it. + - **Writes that bypass Solid.** Layout props written or animated on the + renderer node (`el.lng.text = …`, `el.lng.fontSize = …`, + `el.lng.animate({ fontSize })`) no longer lay out the container: the + renderer lays the text out again, but Solid is not told. Development + builds warn when this happens. + - **Upgrade step:** write or animate text props on the element + (`el.fontSize`, a `transition`, `el.animate()`), not on `el.lng`. +- **Text under hidden or out-of-bounds ancestors is laid out eagerly.** + - **What changes:** text in a layout container is measured at mount and on + every change, even when an ancestor has alpha 0 or is outside the bounds + margin, so such containers have their final size before they are shown. + Before, they stayed unlaid until visible. + - A text whose font is not loaded yet waits, then lays out once. A font + loaded with `loadFonts()` lays out culled text when it arrives; one + loaded with `renderer.loadFont()` directly lays it out when shown, as + before. + - It costs one text layout per such text, and more use of the renderer's + text layout cache (`textLayoutCacheSize`, 250 entries by default). A + page whose texts in layout containers outnumber the cache thrashes it; + raise the size for such pages. + - **Upgrade step:** none. +- **A `loaded` relayout runs between the renderer's walks.** + - **What changes:** an autosize node's `loaded` queues its parent's layout + for the post-mutation pass instead of laying it out inside the event, and + a `loaded` that leaves the size unchanged lays nothing out. An app's + `onEvent.loaded` handler on such a node now runs before the parent's + relayout. On the DOM renderer the relayout is one microtask after the + event. + - **Upgrade step:** read the parent's layout from its `onLayout`, not from a + child's `loaded` handler. +- **Post-mutation scheduling is a microtask only.** + - **What changes:** Solid no longer asks the renderer for an in-frame run, + and a frame, on every mutation. Nodes an app inserts or removes inside a + renderer callback that runs between the walks (its own `onEvent` + handler, `loaded` included) are laid out one frame later. + - **Upgrade step:** none. +- **A `flexGrow` container calls `onLayout` once per layout,** after its grown + children are laid out again. Before, it was called twice, the first time + before the children were laid out. **Upgrade step:** do not count on two + calls. +- **DOM renderer: `measure()`.** `DOMText.measure()` sizes a text + synchronously with `getBoundingClientRect` once `document.fonts.check` + reports its font loaded, so a flex text is laid out in the post-mutation + microtask, not after the DOM renderer's timer. A web font that loads after + its text was measured still lays the container out again. **Upgrade step:** + none. + +### Flex bugs fixed + +- **B5:** an unsized `` no longer blocks its + container's layout. +- **B6:** `justifyContent="center"` with padding centres inside the padding + (it was shifted by the start padding). Drop compensating offsets, if any. +- **B7:** cross-axis `alignItems`/`alignSelf` `center` and `flexEnd` stay + inside the cross padding (center was offset by `paddingTop`, flexEnd + overflowed by it). Drop compensating offsets, if any. +- **B8:** a `flexGrow` item is sized from its own size on every layout: it + shrinks back when a sibling grows, and returns to its own size when no space + is left (it kept its largest grown size). +- **B9:** a wrapping container with no cross size places wrapped items on + their own lines (they overlapped the first line). +- **B10:** `flexWrap="wrap-reverse"` wraps, first line at the end. +- **B11:** a `contain` text with no size subtracts its right and bottom + margins from the computed `maxWidth`/`maxHeight`. +- **B12:** `maxLines={1}` with a `lineHeight` of 3 or less reads it as a + multiplier: `maxHeight = lineHeight * fontSize` (it was the bare multiplier, + a 1.2 px tall text). + +## Keys and focus + +- **One reactive flush per focus change.** + - **What changes:** `onFocus`, `onBlur` and `onFocusChanged` run in the same + order, but the whole focus change (the callbacks, `focusPath`, + `activeElement`) runs in one Solid `batch`. + - An effect or JSX binding triggered by a signal written in one of these + callbacks runs once, after the last callback of the change, instead of + right after each write. Memos read inside the callbacks are still + current. + - Effects on `focusPath` run in the same flush as those on + `activeElement`. + - A callback that writes a signal and then reads a node prop that an + effect sets from that signal sees the old value until the change ends. + - A focus change made from inside a focus callback no longer publishes the + intermediate `activeElement`/`focusPath` to effects: they see only the + final one. + - If a focus callback throws, the effects queued by earlier callbacks of + that change are dropped. The exception still propagates. + - **Upgrade step:** if a focus callback relied on an effect having run after + its own signal write, read the signal instead. + +## States and styles + +- **`states` Array methods return plain arrays.** `states.slice()`, + `filter()`, `map()`, `splice()` and the other `Array` methods return a plain + `Array`, not a `States`. `States` itself is still an `Array` subclass. + **Upgrade step:** call `has`/`add`/`toggle` on `node.states`, not on a copy. +- **B2: `states.remove('focus')` and `toggle('focus')` match `'$focus'`,** as + `has('focus')` already did. Before, they did nothing when only `'$focus'` was + in the list. **Upgrade step:** none. +- **A state change writes only the keys whose value changed.** + - **What changes:** a key still resolves to the active state of highest + precedence that sets it, else `theme[key]`, else `style[key]`, else + `undefined`, but it is written only when that value differs from the one + the last state change wrote. Before, every state change, and every undo, + re-wrote every key of every active state. + - Adding a second state no longer restarts the first state's transition + (a `$focus` `scale` keeps animating when `$active` is added). + - A value the app writes to a key a state sets survives a later state + change that leaves that key's value unchanged. + - The border keys (`border`, `borderTop`, `borderRight`, `borderBottom`, + `borderLeft`) are the exception: when a state change writes one of them, + it writes all of them again in order, as before, so the sides and the + whole border combine as they did. + - The undo is a state change too: when a key's base value (`theme`, else + `style`) is `===` the value the state wrote, the undo skips it. + - **Upgrade step:** code that relied on a state change to overwrite its own + write to a key the state sets must write the key again. +- **Assigning an unchanged `states` list does nothing.** An array or string + with the same states in the same order, or an object that adds and removes + nothing, is a no-op. With `forwardStates`, a child that changed its own + states keeps them until the parent's list changes. And + `node.states = node.states` no longer empties the list. **Upgrade step:** + none. +- **A `$state` block, and a `border` or `shadow` object, are read once per + object.** + - **What changes:** their keys and values are compiled the first time they + are used and cached by object identity. Changing such an object afterwards + (`style.$focus.color = x`, or `myBorder.width = 4` and assigning the same + object again) is not seen. A getter in a `$state` block is still read each + time the block is applied; an object with a getter is not cached. + - **Upgrade step:** assign a new object instead of mutating one, or use a + getter. +- **Setting `linearGradient` or `radialGradient` again updates the node's + gradient shader** in place, instead of making a new one. A gradient shader + shared between nodes is updated for all of them. **Upgrade step:** none. + +## Primitives + +- **Row and Column cache the merged `transition`.** After a press, a Row's or + Column's `transition` is a merged object cached per element and direction. + An in-place edit of the base `transition` object is not seen. **Upgrade + step:** assign a new `transition` object instead of mutating it. + +## Nodes + +- **B19: draw order follows the child order.** + - **What changes:** overlapping siblings with equal `zIndex` draw in their + `children` order after every update, on both renderers: a `` that + appears between siblings, a `` that adds in the middle or reorders, + and a Virtual window shift. Before, such a node was drawn after all its + siblings. An adjacent `` swap also keeps the declared order now, for + flex positions and focus order too (a child inserted before itself stays + in place). When the anchor has a different `zIndex`, the renderer places + the node at the nearest place that keeps siblings sorted by `zIndex`. + - **Upgrade step:** if an app relied on an inserted node drawing last, give + it a higher `zIndex`. +- **B20: text props on a non-text element; `absX`/`absY`/`destroyed` + writes.** Text-only props (`fontSize`, `lineHeight`, `maxWidth`, + `maxHeight`, `text`, `contain`, `textAlign`, …) written to a `` stay on + the ElementNode and no longer reach `view.lng`. Writing `absX`, `absY` or + `destroyed` on an element is ignored; it threw a `TypeError` on renderer 2.0. + **Upgrade step:** none. +- **A removed element does not lay out its old parent.** When a removed, + not yet destroyed element changes size (a text in a hidden + `Preserve`/`KeepAlive` root finishing its load, say), its old parent's flex + and `onLayout` no longer run. A removed element still keeps its `parent`, + and keys and events from a removed subtree still bubble through it. + **Upgrade step:** none. + +## Build + +- **Recommended: terser `reduce_funcs: false`.** With terser's default + `reduce_funcs`, renderer 2.0's scene walk allocates on every node it visits. + Build with `build.minify: 'terser'` and + `build.terserOptions.compress.reduce_funcs = false`; + [Building for TVs](docs/deploy/build.md) has the Vite, webpack and CLI + forms. **Upgrade step:** set the option in your build. From 65b30712cf1a56dcba819c9a54f5055f2432d6b5 Mon Sep 17 00:00:00 2001 From: Chris Lorenzo Date: Fri, 20 Nov 2026 12:11:14 -0500 Subject: [PATCH 3/3] docs(perf), bench: the 1.8 rewrite's design, measurements and harness From the 1.8 branch: - docs/perf: the methodology (README), the log, the Phase 0 profiles and summaries, the Checkpoint 2 series summary, the route timings, the survey verification and the text-flex alternatives study. The raw per-run JSON records are left out, as .gitignore already says; their summaries are committed. - docs/superpowers: the design, the Phase 2 plan, the Checkpoint 2 report and the renderer proposals (the rewrite brief is already on main). - bench: the demo-app route timing and bundle scripts (bench/demo), the renderer v2 arm, and the harness fixes. - .gitignore: bench/.results-tmp and .superpowers. The log notes that this work was named 1.7 on the branch and shipped as 1.8. Co-Authored-By: Claude Opus 5.5 --- .gitignore | 2 + bench/demo/bundle-copies.mjs | 93 ++ bench/demo/check-routes.mjs | 87 + bench/demo/lib.mjs | 551 +++++++ bench/demo/route-times.mjs | 527 +++++++ bench/demo/run-demo.mjs | 407 +++++ bench/harness/analyze.mjs | 8 +- bench/harness/probe.mjs | 4 +- bench/prepare-arms.mjs | 31 +- bench/run.mjs | 17 +- bench/src/arm-v1.ts | 2 +- bench/src/arm-v2.ts | 37 + bench/src/scenario.ts | 4 +- bench/vite.config.ts | 7 +- docs/perf/README.md | 183 ++- docs/perf/log.md | 707 +++++++++ docs/perf/results/2026-10-03/profiles.md | 397 +++++ docs/perf/results/2026-10-03/summary.md | 1178 ++++++++++++++ docs/perf/results/2026-10-04/summary.md | 324 ++++ docs/perf/results/routes-2026-10-03.md | 136 ++ docs/perf/results/routes-2026-10-04.md | 136 ++ docs/perf/survey-verification.md | 1402 +++++++++++++++++ docs/perf/text-flex-alternatives.md | 763 +++++++++ .../plans/2026-10-03-solid-1.7-phase-2.md | 209 +++ .../specs/2026-10-03-solid-1.7-design.md | 655 ++++++++ .../specs/2026-10-04-checkpoint-2-report.md | 369 +++++ docs/superpowers/specs/renderer-proposals.md | 112 ++ 27 files changed, 8243 insertions(+), 105 deletions(-) create mode 100644 bench/demo/bundle-copies.mjs create mode 100644 bench/demo/check-routes.mjs create mode 100644 bench/demo/lib.mjs create mode 100644 bench/demo/route-times.mjs create mode 100644 bench/demo/run-demo.mjs create mode 100644 bench/src/arm-v2.ts create mode 100644 docs/perf/log.md create mode 100644 docs/perf/results/2026-10-03/profiles.md create mode 100644 docs/perf/results/2026-10-03/summary.md create mode 100644 docs/perf/results/2026-10-04/summary.md create mode 100644 docs/perf/results/routes-2026-10-03.md create mode 100644 docs/perf/results/routes-2026-10-04.md create mode 100644 docs/perf/survey-verification.md create mode 100644 docs/perf/text-flex-alternatives.md create mode 100644 docs/superpowers/plans/2026-10-03-solid-1.7-phase-2.md create mode 100644 docs/superpowers/specs/2026-10-03-solid-1.7-design.md create mode 100644 docs/superpowers/specs/2026-10-04-checkpoint-2-report.md create mode 100644 docs/superpowers/specs/renderer-proposals.md diff --git a/.gitignore b/.gitignore index 3bc988cd..2707d31c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,8 @@ package-lock.json # benchmark arms and outputs bench/.arms bench/dist +bench/.results-tmp docs/perf/results/**/*.cpuprofile # Raw per-run benchmark records (regenerated by npm run bench; summaries are committed) docs/perf/results/**/*.json +.superpowers diff --git a/bench/demo/bundle-copies.mjs b/bench/demo/bundle-copies.mjs new file mode 100644 index 00000000..1b077206 --- /dev/null +++ b/bench/demo/bundle-copies.mjs @@ -0,0 +1,93 @@ +// Proves a demo build bundles exactly one copy of solid-js and of +// @solidtv/renderer, and shows which @solidtv/solid and renderer it bundled, +// from the sourcemaps' `sources` (build with --sourcemap=true). +// +// node bench/demo/bundle-copies.mjs [--legacy] +// +// Every bundled module's real path is grouped by package root, so two copies of +// one package (two node_modules/.pnpm entries, or a link and an arm dir) show +// as two roots. Exits 1 if solid-js or @solidtv/renderer has more than one. +import { readdirSync, readFileSync } from 'node:fs'; +import { join, resolve, dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +// Package root of a bundled source path: the package under the last +// node_modules, or for linked checkouts and bench arms, the checkout. +function pkgRoot(p) { + const nm = p.lastIndexOf('/node_modules/'); + if (nm !== -1) { + const rest = p.slice(nm + '/node_modules/'.length).split('/'); + const name = rest[0].startsWith('@') ? `${rest[0]}/${rest[1]}` : rest[0]; + return { name, root: p.slice(0, nm) + '/node_modules/' + name }; + } + const m = p.match( + /^(.*?\/(?:solid-1\.7\/bench\/\.arms\/[^/]+|renderer-v2-solid|solid-1\.7|solid-demo-app-1\.7))\//, + ); + if (m) { + const root = m[1]; + const name = /renderer/.test(root) + ? '@solidtv/renderer' + : /demo-app/.test(root) + ? '(app)' + : '@solidtv/solid'; + return { name, root }; + } + return { name: '(other)', root: dirname(p) }; +} + +/** Map of package name -> Map(root -> module count) for one build. */ +export function bundleCopies(dist, { legacy = false } = {}) { + const assets = join(resolve(dist), 'assets'); + const maps = readdirSync(assets).filter( + (f) => f.endsWith('.js.map') && f.includes('-legacy') === legacy, + ); + if (maps.length === 0) { + throw new Error( + `no ${legacy ? 'legacy ' : ''}sourcemaps in ${assets} (build with --sourcemap=true)`, + ); + } + const sources = new Set(); + for (const f of maps) { + const map = JSON.parse(readFileSync(join(assets, f), 'utf8')); + for (const s of map.sources || []) + sources.add(resolve(assets, map.sourceRoot || '', s)); + } + const byPkg = new Map(); + for (const s of sources) { + const { name, root } = pkgRoot(s); + if (!byPkg.has(name)) byPkg.set(name, new Map()); + const roots = byPkg.get(name); + roots.set(root, (roots.get(root) || 0) + 1); + } + return byPkg; +} + +if (process.argv[1] === fileURLToPath(import.meta.url)) { + const dist = process.argv[2] || 'dist'; + const byPkg = bundleCopies(dist, { + legacy: process.argv.includes('--legacy'), + }); + const watch = [ + 'solid-js', + '@solidtv/renderer', + '@solidtv/solid', + '@solidjs/router', + ]; + const rest = [...byPkg.keys()].filter((n) => !watch.includes(n)).sort(); + let bad = false; + for (const name of [...watch, ...rest]) { + const roots = byPkg.get(name); + if (!roots) { + if (watch.includes(name)) console.log(`${name}: (not bundled)`); + continue; + } + if (roots.size > 1 && (name === 'solid-js' || name === '@solidtv/renderer')) + bad = true; + const flag = roots.size > 1 ? ' <-- MORE THAN ONE COPY' : ''; + console.log( + `${name}: ${roots.size} cop${roots.size === 1 ? 'y' : 'ies'}${flag}`, + ); + for (const [root, n] of roots) console.log(` ${root} (${n} modules)`); + } + process.exit(bad ? 1 : 0); +} diff --git a/bench/demo/check-routes.mjs b/bench/demo/check-routes.mjs new file mode 100644 index 00000000..7cd950fb --- /dev/null +++ b/bench/demo/check-routes.mjs @@ -0,0 +1,87 @@ +// Opens every demo-app route in headless Chromium (real WebGL) and reports +// console errors, page errors and failed requests per route. +// +// node bench/demo/check-routes.mjs [--tmdb fixtures|live] [--shots ] [--only a,b] +// +// is a built demo (e.g. ../solid-demo-app-1.7/dist or dist-bench/A). +// Each route gets a fresh page, ~4s to render, then Right/Down/Left/Up presses. +// Exits 1 if any route logged an error. +import { mkdirSync } from 'node:fs'; +import { join, resolve } from 'node:path'; +import { ROUTES, launchChromium, routeTmdbFixtures, serveDir } from './lib.mjs'; + +const args = process.argv.slice(2); +const opt = (name, dflt) => { + const i = args.indexOf(`--${name}`); + return i === -1 ? dflt : args[i + 1]; +}; +const dist = resolve( + args.find((a, i) => !a.startsWith('--') && !args[i - 1]?.startsWith('--')) || + 'dist', +); +const tmdb = opt('tmdb', 'fixtures'); +const shots = opt('shots', null); +const only = opt('only', null)?.split(','); + +const routes = ROUTES.filter((r) => !only || only.includes(r)); + +const server = await serveDir(dist); +const browser = await launchChromium(); +if (shots) mkdirSync(shots, { recursive: true }); +const unknownTmdb = new Set(); +const report = []; + +for (const route of routes) { + const context = await browser.newContext({ + viewport: { width: 1920, height: 1080 }, + }); + if (tmdb === 'fixtures') + await routeTmdbFixtures(context, server.origin, (p) => unknownTmdb.add(p)); + const page = await context.newPage(); + const errors = []; + const warnings = []; + page.on('console', (m) => { + if (m.type() === 'error') + errors.push(`console: ${m.text().split('\n')[0]}`); + else if (m.type() === 'warning') warnings.push(m.text().split('\n')[0]); + }); + page.on('pageerror', (e) => + errors.push(`pageerror: ${e.message.split('\n')[0]}`), + ); + page.on('requestfailed', (r) => + errors.push(`requestfailed: ${r.url()} ${r.failure()?.errorText}`), + ); + page.on('response', (r) => { + if (r.status() >= 400) errors.push(`http ${r.status()}: ${r.url()}`); + }); + await page.goto(`${server.origin}/#/${route}`); + await page.waitForTimeout(4000); + for (const key of ['ArrowRight', 'ArrowDown', 'ArrowLeft', 'ArrowUp']) { + await page.keyboard.press(key); + await page.waitForTimeout(250); + } + await page.waitForTimeout(500); + if (shots) + await page.screenshot({ + path: join(shots, `${route.replace(/\//g, '_') || 'root'}.png`), + }); + report.push({ route, errors, warnings }); + console.log( + `${errors.length ? 'ERR ' : 'ok '} #/${route}${errors.length ? '' : warnings.length ? ` (${warnings.length} warnings)` : ''}`, + ); + for (const e of [...new Set(errors)]) console.log(` ${e}`); + for (const w of [...new Set(warnings)]) console.log(` warn: ${w}`); + await context.close(); +} + +await browser.close(); +await server.close(); +if (unknownTmdb.size) + console.log( + `\nTMDB paths without a fixture (answered with a generic list):\n ${[...unknownTmdb].join('\n ')}`, + ); +const bad = report.filter((r) => r.errors.length); +console.log( + `\n${report.length - bad.length}/${report.length} routes without errors (${dist}, tmdb=${tmdb})`, +); +process.exit(bad.length ? 1 : 0); diff --git a/bench/demo/lib.mjs b/bench/demo/lib.mjs new file mode 100644 index 00000000..cb933039 --- /dev/null +++ b/bench/demo/lib.mjs @@ -0,0 +1,551 @@ +// Shared helpers for the demo-app harness (run-demo.mjs, check-routes.mjs): +// Playwright from this repo's devDependencies, a static server for a demo +// build, and offline TMDB fixtures. +import { createServer } from 'node:http'; +import { createReadStream, existsSync, statSync } from 'node:fs'; +import { createRequire } from 'node:module'; +import { extname, join, normalize, resolve, dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { deflateSync } from 'node:zlib'; + +export const here = dirname(fileURLToPath(import.meta.url)); +export const solidRoot = resolve(here, '../..'); +export const demoRoot = resolve( + process.env.DEMO_ROOT || join(solidRoot, '../solid-demo-app-1.7'), +); + +// playwright is not a direct dependency: reach it through @vitest/browser-playwright. +export function loadPlaywright() { + const req = createRequire(join(solidRoot, 'package.json')); + return createRequire(req.resolve('@vitest/browser-playwright/package.json'))( + 'playwright', + ); +} + +// src/index.tsx's routes (player/:id needs a video stream; left out). +export const ROUTES = [ + '', + 'browse/all', + 'examples', + 'examples/tmdb', + 'loops', + 'infinite', + 'tmdbgrid', + 'virtual', + 'destroy', + 'grid', + 'matrix', + 'text', + 'firebolt', + 'login', + 'nested', + 'textposter', + 'textcentering', + 'countdown', + 'custombuttons', + 'positioning', + 'layout', + 'focusbasics', + 'transitions', + 'components', + 'focushandling', + 'keyhandling', + 'gradients', + 'flex', + 'create', + 'viewport', + 'flexsize', + 'flexmenu', + 'flexcolumnsize', + 'flexcolumn', + 'flexgrow', + 'flexjustifywidth', + 'keepalive', + 'suspense', + 'superflex', + 'tags', + 'buttonsmaterial', + 'entity/movie/1013', + 'entity/tv/1013', + 'entity/people/1013', + 'image-performance', + 'large-image-performance', + 'mixed-image-performance', + 'texture-compression-performance', + 'complexflex', + 'complexflexcaps', + 'benchmark', + 'versions', + 'does-not-exist', +]; + +// New headless on the full Chromium: hardware WebGL through ANGLE/Metal on a +// Mac. The default headless shell falls back to SwiftShader (software GL), +// which puts GPU emulation on the CPU being measured. +export async function launchChromium({ headed = false } = {}) { + const { chromium } = loadPlaywright(); + return chromium.launch({ headless: !headed, channel: 'chromium' }); +} + +const MIME = { + '.html': 'text/html; charset=utf-8', + '.js': 'text/javascript; charset=utf-8', + '.mjs': 'text/javascript; charset=utf-8', + '.css': 'text/css; charset=utf-8', + '.json': 'application/json; charset=utf-8', + '.map': 'application/json; charset=utf-8', + '.png': 'image/png', + '.jpg': 'image/jpeg', + '.jpeg': 'image/jpeg', + '.gif': 'image/gif', + '.svg': 'image/svg+xml', + '.webp': 'image/webp', + '.ktx': 'application/octet-stream', + '.pvr': 'application/octet-stream', + '.ttf': 'font/ttf', + '.woff': 'font/woff', + '.woff2': 'font/woff2', + '.mp4': 'video/mp4', +}; + +// Serves a built app. Same isolation headers as the demo's dev server +// (vite.config.js server.headers), which also gives performance.now() its +// fine-grained resolution. /__blank is an empty same-origin page to set up a +// context on before the app loads. /__tmdb-img/* serves fixture posters. +export function serveDir(dir) { + const root = resolve(dir); + if (!existsSync(join(root, 'index.html'))) + throw new Error(`no index.html in ${root}`); + const server = createServer((req, res) => { + const headers = { + 'Cross-Origin-Opener-Policy': 'same-origin', + 'Cross-Origin-Embedder-Policy': 'require-corp', + 'Cache-Control': 'no-store', + }; + const url = new URL(req.url, 'http://x'); + if (url.pathname === '/__blank') { + res.writeHead(200, { ...headers, 'Content-Type': MIME['.html'] }); + return res.end('blank'); + } + if (url.pathname.startsWith('/__tmdb-img/')) { + const png = fixtureImage(url.pathname.slice('/__tmdb-img/'.length)); + res.writeHead(200, { + ...headers, + 'Content-Type': 'image/png', + 'Content-Length': png.length, + }); + return res.end(png); + } + let file = normalize(join(root, decodeURIComponent(url.pathname))); + if (!file.startsWith(root)) { + res.writeHead(403, headers); + return res.end(); + } + if (existsSync(file) && statSync(file).isDirectory()) + file = join(file, 'index.html'); + if (!existsSync(file)) { + res.writeHead(404, headers); + return res.end('not found'); + } + res.writeHead(200, { + ...headers, + 'Content-Type': + MIME[extname(file).toLowerCase()] || 'application/octet-stream', + 'Content-Length': statSync(file).size, + }); + createReadStream(file).pipe(res); + }); + return new Promise((ok) => + server.listen(0, '127.0.0.1', () => + ok({ + origin: `http://127.0.0.1:${server.address().port}`, + close: () => new Promise((done) => server.close(done)), + }), + ), + ); +} + +// --------------------------------------------------------------------------- +// TMDB fixtures +// +// The app reads TMDB with a v4 token from src/api/key.ts, which is gitignored +// and exists only in the main checkout. Instead of the network, the harness +// answers api.themoviedb.org from deterministic data in TMDB's documented +// response shapes and serves the images itself, so runs are offline and every +// arm sees the same rows, titles and image sizes. The content is synthetic: +// absolute numbers differ from a run against the live API. + +function rng(seed) { + let s = seed >>> 0 || 1; + return () => { + s ^= s << 13; + s ^= s >>> 17; + s ^= s << 5; + return (s >>> 0) / 4294967296; + }; +} +function hash(str) { + let h = 2166136261; + for (let i = 0; i < str.length; i++) + h = Math.imul(h ^ str.charCodeAt(i), 16777619); + return h >>> 0; +} + +const WORDS = ( + 'the night river last city dark light edge storm silent golden broken lost return ' + + 'empire shadow winter summer secret code iron glass heart fire ocean road house ' + + 'kingdom signal frontier echo machine garden dawn midnight runner station orbit' +).split(' '); +const GENRES = [ + [28, 'Action'], + [12, 'Adventure'], + [16, 'Animation'], + [35, 'Comedy'], + [80, 'Crime'], + [99, 'Documentary'], + [18, 'Drama'], + [10751, 'Family'], + [14, 'Fantasy'], + [36, 'History'], + [27, 'Horror'], + [10402, 'Music'], + [9648, 'Mystery'], + [10749, 'Romance'], + [878, 'Science Fiction'], + [10770, 'TV Movie'], + [53, 'Thriller'], + [10752, 'War'], + [37, 'Western'], +].map(([id, name]) => ({ id, name })); + +const cap = (w) => w[0].toUpperCase() + w.slice(1); +function words(r, n) { + const out = []; + for (let i = 0; i < n; i++) out.push(WORDS[Math.floor(r() * WORDS.length)]); + return out; +} +function title(r) { + return words(r, 1 + Math.floor(r() * 4)) + .map(cap) + .join(' '); +} +function overview(r) { + const sentences = []; + const n = 2 + Math.floor(r() * 3); + for (let i = 0; i < n; i++) + sentences.push(cap(words(r, 8 + Math.floor(r() * 10)).join(' ')) + '.'); + return sentences.join(' '); +} +function date(r) { + const y = 1960 + Math.floor(r() * 65); + const m = 1 + Math.floor(r() * 12); + const d = 1 + Math.floor(r() * 28); + return `${y}-${String(m).padStart(2, '0')}-${String(d).padStart(2, '0')}`; +} + +function item(id, type) { + const r = rng(id * 2654435761); + const t = title(r); + const d = date(r); + const base = { + adult: false, + id, + media_type: type, + original_language: 'en', + overview: overview(r), + popularity: Math.round(r() * 5000) / 10, + poster_path: `/p-${id}.png`, + backdrop_path: `/b-${id}.png`, + genre_ids: [ + GENRES[id % GENRES.length].id, + GENRES[(id * 7) % GENRES.length].id, + ], + vote_average: Math.round((4 + r() * 5) * 10) / 10, + vote_count: Math.floor(r() * 20000), + }; + if (type === 'tv') { + return { + ...base, + name: t, + original_name: t, + first_air_date: d, + origin_country: ['US'], + }; + } + if (type === 'person') { + return { + adult: false, + id, + media_type: 'person', + name: title(r), + original_name: title(r), + gender: 1 + (id % 2), + known_for_department: 'Acting', + popularity: base.popularity, + profile_path: `/f-${id}.png`, + character: title(r), + job: 'Director', + department: 'Directing', + known_for: [item(id + 1, 'movie'), item(id + 2, 'movie')], + }; + } + return { + ...base, + title: t, + original_title: t, + release_date: d, + video: false, + }; +} + +function list(seed, type, count = 20) { + const r = rng(seed); + const start = 1000 + Math.floor(r() * 900000); + const results = []; + for (let i = 0; i < count; i++) results.push(item(start + i * 13, type)); + return { page: 1, results, total_pages: 10, total_results: 200 }; +} + +function credits(id) { + return { + id, + cast: list(id + 11, 'person', 12).results.map((p, i) => ({ + ...p, + order: i, + cast_id: i, + credit_id: `c${p.id}`, + })), + crew: list(id + 12, 'person', 4).results.map((p) => ({ + ...p, + credit_id: `w${p.id}`, + })), + }; +} + +function detail(id, type) { + const base = item(id, type); + const r = rng(id); + const lists = { + credits: credits(id), + recommendations: list(id + 1, type), + similar: list(id + 2, type), + videos: { id, results: [] }, + images: { id, backdrops: [], posters: [], logos: [] }, + release_dates: { + id, + results: [ + { + iso_3166_1: 'US', + release_dates: [{ certification: 'PG-13', type: 3 }], + }, + ], + }, + content_ratings: { id, results: [{ iso_3166_1: 'US', rating: 'TV-14' }] }, + external_ids: { id, imdb_id: `tt${id}` }, + keywords: { id, keywords: [], results: [] }, + }; + return { + ...base, + ...lists, + genres: [GENRES[id % GENRES.length], GENRES[(id * 7) % GENRES.length]], + tagline: cap(words(r, 6).join(' ')) + '.', + runtime: 80 + Math.floor(r() * 80), + status: 'Released', + homepage: '', + budget: 0, + revenue: 0, + production_companies: [], + production_countries: [], + spoken_languages: [ + { english_name: 'English', iso_639_1: 'en', name: 'English' }, + ], + belongs_to_collection: null, + number_of_seasons: type === 'tv' ? 1 + (id % 6) : undefined, + number_of_episodes: type === 'tv' ? 10 + (id % 40) : undefined, + seasons: type === 'tv' ? [] : undefined, + created_by: type === 'tv' ? [] : undefined, + networks: type === 'tv' ? [] : undefined, + }; +} + +function person(id) { + const p = item(id, 'person'); + const r = rng(id); + return { + ...p, + also_known_as: [], + biography: overview(r) + ' ' + overview(r), + birthday: date(r), + deathday: null, + place_of_birth: 'Somewhere, USA', + imdb_id: `nm${id}`, + homepage: null, + combined_credits: { cast: list(id + 3, 'movie').results, crew: [] }, + movie_credits: { cast: list(id + 4, 'movie').results, crew: [] }, + tv_credits: { cast: list(id + 5, 'tv').results, crew: [] }, + }; +} + +/** + * The TMDB answer for one API path (without the /3 prefix), or null when the + * path is not one the fixtures know (the caller logs it and answers with a + * generic list). + */ +export function tmdbFixture(pathname, search, imgBase) { + const p = pathname.replace(/^\/3/, ''); + const seed = hash(p + search); + if (p === '/configuration') { + return { + images: { + base_url: imgBase, + secure_base_url: imgBase, + backdrop_sizes: ['w300', 'w780', 'w1280', 'original'], + logo_sizes: ['w45', 'w92', 'w154', 'w185', 'w300', 'w500', 'original'], + poster_sizes: [ + 'w92', + 'w154', + 'w185', + 'w342', + 'w500', + 'w780', + 'original', + ], + profile_sizes: ['w45', 'w185', 'h632', 'original'], + still_sizes: ['w92', 'w185', 'w300', 'original'], + }, + change_keys: [], + }; + } + let m; + if ((m = /^\/genre\/(movie|tv)\/list$/.exec(p))) return { genres: GENRES }; + if ((m = /^\/(movie|tv)\/(\d+)$/.exec(p))) return detail(+m[2], m[1]); + if ((m = /^\/(movie|tv)\/(\d+)\/(credits|aggregate_credits)$/.exec(p))) + return credits(+m[2]); + if ((m = /^\/(movie|tv)\/(\d+)\/(recommendations|similar)$/.exec(p))) + return list(seed, m[1]); + if ( + (m = + /^\/(movie|tv)\/(\d+)\/(videos|images|release_dates|content_ratings|external_ids|keywords)$/.exec( + p, + )) + ) + return detail(+m[2], m[1])[m[3]]; + if ((m = /^\/person\/(\d+)$/.exec(p))) return person(+m[1]); + if ( + (m = /^\/person\/(\d+)\/(combined_credits|movie_credits|tv_credits)$/.exec( + p, + )) + ) + return person(+m[1])[m[2]]; + if ( + (m = /^\/(?:trending\/)?(movie|tv|person|all)(?:\/[a-z_]+)?$/.exec(p)) || + (m = /^\/discover\/(movie|tv)$/.exec(p)) + ) + return list(seed, m[1] === 'all' ? (seed % 2 ? 'movie' : 'tv') : m[1]); + if ((m = /^\/search\/(movie|tv|person|multi)$/.exec(p))) + return list(seed, m[1] === 'multi' ? 'movie' : m[1]); + return null; +} + +/** + * Routes api.themoviedb.org through the fixtures on a Playwright context. + * Unknown paths are answered with a generic movie list and reported through + * `onUnknown`. + */ +export async function routeTmdbFixtures(context, origin, onUnknown = () => {}) { + const imgBase = `${origin}/__tmdb-img/`; + await context.route('https://api.themoviedb.org/**', (route) => { + const url = new URL(route.request().url()); + let body = tmdbFixture(url.pathname, url.search, imgBase); + if (body === null) { + onUnknown(url.pathname + url.search); + body = list(hash(url.pathname + url.search), 'movie'); + } + route.fulfill({ + status: 200, + contentType: 'application/json', + headers: { 'Access-Control-Allow-Origin': '*' }, + body: JSON.stringify(body), + }); + }); +} + +// Fixture images: /-.png, kind p(oster) b(ackdrop) f(ace). +// Eight variants per kind and size; distinct ids share bytes but stay +// distinct URLs, so the renderer still loads one texture per tile. +const ASPECT = { p: 1.5, b: 9 / 16, f: 1.5 }; +const ORIGINAL = { p: 780, b: 1920, f: 632 }; +const imageCache = new Map(); +function fixtureImage(rest) { + const [size = 'w185', file = 'p-0.png'] = rest.split('/'); + const kind = /^[pbf]-/.test(file) ? file[0] : 'p'; + const id = parseInt(file.slice(2), 10) || 0; + let w; + let h; + if (/^w\d+$/.test(size)) { + w = +size.slice(1); + h = Math.round(w * ASPECT[kind]); + } else if (/^h\d+$/.test(size)) { + h = +size.slice(1); + w = Math.round(h / ASPECT[kind]); + } else { + w = ORIGINAL[kind]; + h = Math.round(w * ASPECT[kind]); + } + const variant = id % 8; + const key = `${w}x${h}:${variant}`; + if (!imageCache.has(key)) imageCache.set(key, encodePng(w, h, variant)); + return imageCache.get(key); +} + +const CRC_TABLE = (() => { + const t = new Uint32Array(256); + for (let n = 0; n < 256; n++) { + let c = n; + for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1; + t[n] = c >>> 0; + } + return t; +})(); +function crc32(buf) { + let c = 0xffffffff; + for (let i = 0; i < buf.length; i++) + c = CRC_TABLE[(c ^ buf[i]) & 0xff] ^ (c >>> 8); + return (c ^ 0xffffffff) >>> 0; +} +function chunk(type, data) { + const len = Buffer.alloc(4); + len.writeUInt32BE(data.length); + const td = Buffer.concat([Buffer.from(type, 'ascii'), data]); + const crc = Buffer.alloc(4); + crc.writeUInt32BE(crc32(td)); + return Buffer.concat([len, td, crc]); +} +// An opaque RGB gradient with a little deterministic texture, so it is not a +// trivially compressible flat fill. +function encodePng(w, h, variant) { + const r = rng(variant + 1); + const hue = [r() * 255, r() * 255, r() * 255]; + const raw = Buffer.alloc((w * 3 + 1) * h); + let o = 0; + for (let y = 0; y < h; y++) { + raw[o++] = 0; + for (let x = 0; x < w; x++) { + const n = (r() * 24) | 0; + raw[o++] = (hue[0] * (x / w) + n) & 255; + raw[o++] = (hue[1] * (y / h) + n) & 255; + raw[o++] = (hue[2] * (1 - x / w) + n) & 255; + } + } + const ihdr = Buffer.alloc(13); + ihdr.writeUInt32BE(w, 0); + ihdr.writeUInt32BE(h, 4); + ihdr[8] = 8; // bit depth + ihdr[9] = 2; // RGB + return Buffer.concat([ + Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), + chunk('IHDR', ihdr), + chunk('IDAT', deflateSync(raw)), + chunk('IEND', Buffer.alloc(0)), + ]); +} diff --git a/bench/demo/route-times.mjs b/bench/demo/route-times.mjs new file mode 100644 index 00000000..359560d3 --- /dev/null +++ b/bench/demo/route-times.mjs @@ -0,0 +1,527 @@ +// Times how long each demo-app route takes to appear: from the hash change to +// the page settling, per arm, under CDP CPU throttling. The routes are +// check-routes.mjs's (lib.mjs ROUTES). +// +// node bench/demo/route-times.mjs [--arms A,B,C] [--visits 3] [--throttle 6] +// [--only a,b] [--quiet 500] [--timeout 20] [--tmdb fixtures|live] +// [--out docs/perf/results/routes-] [--dist-bench ] [--verbose] +// +// The arms are the demo's `dist-bench/` builds (`node bench/demo/run-demo.mjs` +// builds them; its --skip-build reuses a current build). +// +// One visit is a fresh browser context: load the app on a start route +// (`#/does-not-exist`, an empty page inside the app's nav drawer) unthrottled, +// wait until it has settled, throttle, then set `location.hash` to the route +// and time that to the page settling. Every route is therefore created from +// the same state, in a page that has run no other route (a first visit: its +// lazy chunk is fetched, its code is cold). +// +// Settled: no drawn frame for `--quiet` ms and no request in flight. A drawn +// frame is a requestAnimationFrame callback in which `gl.clear` ran (both +// renderer majors clear once per drawn frame; the same test as the harness's +// probe, bench/harness/probe.mjs). The demo's bundle exposes no handle to the +// renderer, so its `idle` event is not used: the renderer is idle when it +// draws nothing, which is what "no drawn frame" says. The route's time +// (`settleMs`) is from the hash change to the end of its last drawn frame. +// Wall time to settle includes timers and animations, so each visit also +// records `busyMs`: the main thread's task time (CDP `TaskDuration`) over the +// same window, sampled at the last drawn frame. Both are throttled times. +// +// The renderer's fps heartbeat is switched off: the demo's nav wrapper shows an +// fps counter that renderer 1.x updates every 300 ms for ever, even when the +// scene is idle, so arm A would never go quiet. The visit's server response +// for the app's entry chunk has `fpsUpdateInterval: 300` replaced by 0 (the +// demo already hides the counter on #/benchmark for the same reason). The +// counter's text updates are not route work in any arm. +// +// A route still drawing after `--timeout` s (an animation, a ticking page) has +// no settle time and is left out of the sums. Timers that fire later than +// `--quiet` after the last frame (a page that fills in after a second) are not +// seen. +// +// Per route and arm: `--visits` visits, interleaved (route by route, visit by +// visit, A B C in turn) so that load on the machine falls on every arm alike; +// the median is reported, with min and max. Writes .json and .md. +import { execFileSync } from 'node:child_process'; +import { existsSync, readFileSync, statSync, writeFileSync } from 'node:fs'; +import os from 'node:os'; +import { join, relative, resolve } from 'node:path'; +import { parseArgs } from 'node:util'; +import { PINS } from '../prepare-arms.mjs'; +import { + ROUTES, + demoRoot, + launchChromium, + routeTmdbFixtures, + serveDir, + solidRoot, +} from './lib.mjs'; + +const { values: opt } = parseArgs({ + options: { + arms: { type: 'string', default: 'A,B,C' }, + visits: { type: 'string', default: '3' }, + throttle: { type: 'string', default: '6' }, + only: { type: 'string' }, + quiet: { type: 'string', default: '500' }, + timeout: { type: 'string', default: '20' }, + tmdb: { type: 'string', default: 'fixtures' }, + out: { type: 'string' }, + 'dist-bench': { type: 'string', default: join(demoRoot, 'dist-bench') }, + verbose: { type: 'boolean', default: false }, + help: { type: 'boolean', short: 'h', default: false }, + }, +}); +if (opt.help) { + console.log( + readFileSync(new URL(import.meta.url), 'utf8').split('\nimport ')[0], + ); + process.exit(0); +} + +const arms = opt.arms.split(',').map((a) => a.trim().toUpperCase()); +const visits = Math.max(1, parseInt(opt.visits, 10)); +const throttle = parseFloat(opt.throttle); +const quietMs = parseFloat(opt.quiet); +const timeoutMs = parseFloat(opt.timeout) * 1000; +const date = new Date().toISOString().slice(0, 10); +const outBase = resolve( + opt.out ?? join(solidRoot, 'docs/perf/results', `routes-${date}`), +); +if (!['fixtures', 'live'].includes(opt.tmdb)) + throw new Error('--tmdb is fixtures or live'); +const only = opt.only?.split(','); +const routes = ROUTES.filter((r) => !only || only.includes(r)); +// Every route starts from this one; it starts from START_FOR_NEUTRAL. +const START = 'does-not-exist'; +const START_FOR_NEUTRAL = 'versions'; +const POLL_MS = 40; +const FPS_HEARTBEAT = 'fpsUpdateInterval: 300,'; +let fpsPatched = true; + +// ── page side ──────────────────────────────────────────────────────────── +// Injected before the app's first script. Must not close over anything. +function frameTracker() { + const perf = window.performance; + const raf = window.requestAnimationFrame.bind(window); + let clears = 0; + const glTypes = [window.WebGLRenderingContext, window.WebGL2RenderingContext]; + for (let g = 0; g < glTypes.length; g++) { + const type = glTypes[g]; + if (type === undefined) continue; + const clear = type.prototype.clear; + type.prototype.clear = function (mask) { + clears++; + clear.call(this, mask); + }; + } + const T = { + drawn: 0, + lastDrawEnd: 0, + t0: 0, + firstEnd: 0, + frames0: 0, + maxGap: 0, + }; + const wrappers = new WeakMap(); + window.requestAnimationFrame = function (callback) { + let wrapped = wrappers.get(callback); + if (wrapped === undefined) { + wrapped = function (time) { + const c0 = clears; + callback(time); + if (clears !== c0) { + const end = perf.now(); + T.drawn++; + if (T.t0 !== 0) { + const gap = end - (T.lastDrawEnd > T.t0 ? T.lastDrawEnd : T.t0); + if (T.firstEnd !== 0 && gap > T.maxGap) T.maxGap = gap; + if (T.firstEnd === 0) T.firstEnd = end; + } + T.lastDrawEnd = end; + } + }; + wrappers.set(callback, wrapped); + } + return raf(wrapped); + }; + window.__routeTimes = { + /** Starts the clock and changes the route. */ + go(hash) { + T.t0 = perf.now(); + T.firstEnd = 0; + T.frames0 = T.drawn; + T.maxGap = 0; + window.location.hash = hash; + return T.t0; + }, + snapshot() { + return { + now: perf.now(), + t0: T.t0, + drawn: T.drawn, + lastDrawEnd: T.lastDrawEnd, + firstEnd: T.firstEnd, + frames: T.drawn - T.frames0, + maxGap: T.maxGap, + }; + }, + }; +} + +// ── builds ─────────────────────────────────────────────────────────────── +const distOf = (arm) => join(resolve(opt['dist-bench']), arm); +const git = (dir, ...args) => { + try { + return execFileSync('git', ['-C', dir, ...args], { + stdio: ['ignore', 'pipe', 'ignore'], + }) + .toString() + .trim(); + } catch { + return null; + } +}; +const rev = (dir) => { + const head = git(dir, 'rev-parse', '--short', 'HEAD'); + return ( + head && + `${head}${git(dir, 'status', '--porcelain', '--', 'src') ? '+dirty' : ''}` + ); +}; +const sourceOf = (arm) => + arm === 'A' + ? { solid: PINS.solidA, renderer: `npm ${PINS.rendererA}` } + : arm === 'B' + ? { solid: PINS.solidB, renderer: PINS.rendererB } + : { + solid: rev(solidRoot), + renderer: rev(resolve(solidRoot, '../renderer-v2-solid')), + }; +const builds = {}; +for (const arm of arms) { + const index = join(distOf(arm), 'index.html'); + if (!existsSync(index)) + throw new Error( + `no build for arm ${arm} in ${distOf(arm)}: node bench/demo/run-demo.mjs builds it`, + ); + builds[arm] = { + dist: distOf(arm), + builtAt: statSync(index).mtime.toISOString(), + source: sourceOf(arm), + demo: rev(demoRoot), + }; +} + +// ── run ────────────────────────────────────────────────────────────────── +const servers = {}; +for (const arm of arms) servers[arm] = await serveDir(distOf(arm)); +const browser = await launchChromium(); +const gl = await (async () => { + const page = await browser.newPage(); + try { + return await page.evaluate(() => { + const c = document.createElement('canvas').getContext('webgl'); + const e = c && c.getExtension('WEBGL_debug_renderer_info'); + return c + ? c.getParameter(e ? e.UNMASKED_RENDERER_WEBGL : c.RENDERER) + : null; + }); + } finally { + await page.close(); + } +})(); +const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); + +/** Main-thread task time so far, in seconds (CDP Performance.getMetrics). */ +async function taskDuration(cdp) { + const { metrics } = await cdp.send('Performance.getMetrics'); + for (const m of metrics) if (m.name === 'TaskDuration') return m.value; + throw new Error('Performance.getMetrics has no TaskDuration'); +} + +/** + * Polls until the page has drawn at least one frame since `drawnBefore`, then + * nothing for quietMs, with nothing in flight; or until `limitMs` of page time + * have passed since `from`. With a `cdp` session it also samples the task time + * whenever a poll sees a new last drawn frame, so that `task` is the task time + * at about the last drawn frame, not at the end of the quiet wait. + */ +async function settle(page, cdp, pending, from, limitMs, drawnBefore) { + let seen = -1; + let task = 0; + for (;;) { + const s = await page.evaluate(() => window.__routeTimes.snapshot()); + if (cdp !== null && s.lastDrawEnd !== seen) { + seen = s.lastDrawEnd; + task = await taskDuration(cdp); + } + const quiet = s.now - Math.max(s.lastDrawEnd, from) >= quietMs; + if (quiet && pending.size === 0 && s.drawn > drawnBefore) + return { ...s, task, timedOut: false }; + if (s.now - from > limitMs) return { ...s, task, timedOut: true }; + await sleep(POLL_MS); + } +} + +async function visit(arm, route) { + const server = servers[arm]; + const context = await browser.newContext({ + viewport: { width: 1920, height: 1080 }, + deviceScaleFactor: 1, + }); + try { + const unknown = new Set(); + if (opt.tmdb === 'fixtures') + await routeTmdbFixtures(context, server.origin, (p) => unknown.add(p)); + const pending = new Set(); + context.on('request', (r) => pending.add(r)); + context.on('requestfinished', (r) => pending.delete(r)); + context.on('requestfailed', (r) => pending.delete(r)); + await context.addInitScript({ + content: `(${frameTracker.toString()})();`, + }); + await context.route(/\/assets\/index-[^/]+\.js$/, async (route) => { + const res = await route.fetch(); + const code = await res.text(); + if (!code.includes(FPS_HEARTBEAT)) fpsPatched = false; + await route.fulfill({ + response: res, + body: code.replace(FPS_HEARTBEAT, 'fpsUpdateInterval: 0,'), + }); + }); + const page = await context.newPage(); + const errors = new Set(); + page.on('console', (m) => { + if (m.type() === 'error') + errors.add(`console: ${m.text().split('\n')[0]}`); + }); + page.on('pageerror', (e) => + errors.add(`pageerror: ${e.message.split('\n')[0]}`), + ); + page.on('requestfailed', (r) => + errors.add(`requestfailed: ${r.url()} ${r.failure()?.errorText}`), + ); + page.on('response', (r) => { + if (r.status() >= 400) errors.add(`http ${r.status()}: ${r.url()}`); + }); + + const cdp = await context.newCDPSession(page); + await cdp.send('Performance.enable'); + const start = route === START ? START_FOR_NEUTRAL : START; + await page.goto(`${server.origin}/#/${start}`); + const boot = await settle(page, null, pending, 0, 30000, 0); + if (boot.timedOut) throw new Error(`arm ${arm}: #/${start} did not settle`); + await cdp.send('Emulation.setCPUThrottlingRate', { rate: throttle }); + const task0 = await taskDuration(cdp); + const t0 = await page.evaluate( + (hash) => window.__routeTimes.go(hash), + `#/${route}`, + ); + const s = await settle(page, cdp, pending, t0, timeoutMs, boot.drawn); + return { + settleMs: s.timedOut ? null : s.lastDrawEnd - t0, + busyMs: s.timedOut ? null : (s.task - task0) * 1000, + firstDrawMs: s.firstEnd > 0 ? s.firstEnd - s.t0 : null, + frames: s.frames, + maxGapMs: s.maxGap, + timedOut: s.timedOut, + errors: [...errors], + unknownTmdb: [...unknown], + }; + } finally { + await context.close(); + } +} + +const results = routes.map((route) => ({ + route, + start: route === START ? START_FOR_NEUTRAL : START, + arms: Object.fromEntries(arms.map((a) => [a, { visits: [] }])), +})); +const loadavgStart = os.loadavg(); +const t0 = Date.now(); +try { + for (const [ri, r] of results.entries()) { + for (let v = 0; v < visits; v++) { + for (const arm of arms) { + const rec = await visit(arm, r.route); + if (opt.verbose) console.log(` ${arm} ${JSON.stringify(rec)}`); + r.arms[arm].visits.push(rec); + } + } + console.log( + `${String(ri + 1).padStart(2)}/${results.length} #/${r.route} ` + + arms + .map((a) => `${a} ${cellOf(r.arms[a].visits, 'settleMs')}`) + .join(' '), + ); + } +} finally { + await browser.close(); + for (const s of Object.values(servers)) await s.close(); +} +const loadavgEnd = os.loadavg(); + +// ── report ─────────────────────────────────────────────────────────────── +function median(xs) { + const s = [...xs].sort((a, b) => a - b); + return s.length % 2 + ? s[(s.length - 1) / 2] + : (s[s.length / 2 - 1] + s[s.length / 2]) / 2; +} +function stat(vs, key) { + const xs = vs + .filter((v) => !v.timedOut) + .map((v) => v[key]) + .filter((x) => typeof x === 'number'); + // A route with fewer than two settled visits has no median worth printing. + if (xs.length < Math.min(2, vs.length)) return null; + return { + median: median(xs), + min: Math.min(...xs), + max: Math.max(...xs), + n: xs.length, + }; +} +function cellOf(vs, key) { + const s = stat(vs, key); + return s === null ? 'no idle' : String(Math.round(s.median)); +} +for (const r of results) + for (const arm of arms) { + r.arms[arm].settle = stat(r.arms[arm].visits, 'settleMs'); + r.arms[arm].busy = stat(r.arms[arm].visits, 'busyMs'); + r.arms[arm].firstDraw = stat(r.arms[arm].visits, 'firstDrawMs'); + } +// A route counts in the sums when every arm has a settle time for it. +const counted = results.filter((r) => + arms.every((a) => r.arms[a].settle !== null), +); +const sums = {}; +for (const arm of arms) { + sums[arm] = { + settleMs: counted.reduce((t, r) => t + r.arms[arm].settle.median, 0), + busyMs: counted.reduce((t, r) => t + r.arms[arm].busy.median, 0), + }; +} +const record = { + schema: 'solid-route-times/1', + date: new Date(t0).toISOString(), + wallMs: Date.now() - t0, + arms, + visits, + throttle, + quietMs, + timeoutMs, + tmdb: opt.tmdb, + fpsHeartbeat: fpsPatched + ? 'off' + : 'on (the entry chunk has no fpsUpdateInterval: 300)', + start: START, + startForNeutral: START_FOR_NEUTRAL, + builds, + env: { + chromium: browser.version(), + gl, + host: `${os.cpus()[0]?.model} x${os.cpus().length}, ${os.platform()} ${os.release()}`, + loadavgStart, + loadavgEnd, + }, + counted: counted.map((r) => r.route), + sums, + routes: results, +}; +writeFileSync(`${outBase}.json`, JSON.stringify(record, null, 2) + '\n'); + +const f0 = (x) => String(Math.round(x)); +const cellMd = (s) => + s === null ? 'no idle' : `${f0(s.median)} (${f0(s.min)}-${f0(s.max)})`; +const ratio = (a, b) => + a === null || b === null ? '-' : (a.median / b.median).toFixed(2); +function table(key, label) { + const L = []; + const head = ['route', ...arms]; + if (arms.includes('B') && arms.includes('C')) head.push('C/B'); + if (arms.includes('A') && arms.includes('B')) head.push('B/A'); + L.push(`| ${head.join(' | ')} |`); + L.push(`| ${head.map(() => '---').join(' | ')} |`); + for (const r of results) { + const row = [`#/${r.route}`, ...arms.map((a) => cellMd(r.arms[a][key]))]; + if (arms.includes('B') && arms.includes('C')) + row.push(ratio(r.arms.C[key], r.arms.B[key])); + if (arms.includes('A') && arms.includes('B')) + row.push(ratio(r.arms.B[key], r.arms.A[key])); + L.push(`| ${row.join(' | ')} |`); + } + const sumRow = [ + `**sum of ${counted.length} routes**`, + ...arms.map((a) => `**${f0(sums[a][label])}**`), + ]; + if (arms.includes('B') && arms.includes('C')) + sumRow.push((sums.C[label] / sums.B[label]).toFixed(2)); + if (arms.includes('A') && arms.includes('B')) + sumRow.push((sums.B[label] / sums.A[label]).toFixed(2)); + L.push(`| ${sumRow.join(' | ')} |`); + return L; +} +const excluded = results.filter((r) => !counted.includes(r)); +const L = []; +L.push('# Route creation times'); +L.push(''); +L.push( + `Generated by \`node bench/demo/route-times.mjs\` (${record.date.slice(0, 10)}). Method: the header of [bench/demo/route-times.mjs](../../../bench/demo/route-times.mjs).`, +); +L.push(''); +L.push( + `- Arms: ${arms.map((a) => `${a} (solid ${builds[a].source.solid}, renderer ${builds[a].source.renderer})`).join('; ')}; demo ${builds[arms[0]].demo}`, +); +L.push( + `- ${visits} visits per route and arm, each in a fresh page started on \`#/${START}\`; CPU throttling ${throttle}x; TMDB ${opt.tmdb}; fps heartbeat ${fpsPatched ? 'off' : 'ON (not patched)'}; settled = no drawn frame for ${quietMs} ms and no request in flight, at most ${timeoutMs / 1000} s`, +); +L.push( + `- ${record.env.chromium}, ${gl}; 1-minute load average ${loadavgStart[0].toFixed(1)} at the start, ${loadavgEnd[0].toFixed(1)} at the end`, +); +L.push(''); +L.push( + '## Time from the hash change to the page settling (ms, median of the visits, min-max in parentheses)', +); +L.push(''); +L.push(...table('settle', 'settleMs')); +L.push(''); +L.push( + excluded.length === 0 + ? 'Every route settled in every arm.' + : `Left out of the sums (no settle time in at least one arm): ${excluded.map((r) => `#/${r.route}`).join(', ')}.`, +); +L.push(''); +L.push( + '## Main-thread busy time over the same window (ms of task time, throttled; median, min-max)', +); +L.push(''); +L.push( + 'The settle time includes timers and animations (a debounce, a 250 ms transition): it is what a person waits. The busy time is what the page spends on the main thread (CDP `TaskDuration`, sampled at the last drawn frame): script, renderer frames, GC. It is the figure to compare between arms.', +); +L.push(''); +L.push(...table('busy', 'busyMs')); +L.push(''); +const errs = results.flatMap((r) => + arms.flatMap((a) => + [...new Set(r.arms[a].visits.flatMap((v) => v.errors))].map( + (e) => `#/${r.route} ${a}: ${e}`, + ), + ), +); +if (errs.length) { + L.push('## Errors logged while timing'); + L.push(''); + for (const e of errs) L.push(`- ${e}`); + L.push(''); +} +writeFileSync(`${outBase}.md`, L.join('\n')); +console.log( + `\nsum of ${counted.length} routes, settle: ${arms.map((a) => `${a} ${f0(sums[a].settleMs)} ms`).join(', ')}; busy: ${arms.map((a) => `${a} ${f0(sums[a].busyMs)} ms`).join(', ')}`, +); +console.log( + `wrote ${relative(process.cwd(), outBase)}.json and ${relative(process.cwd(), outBase)}.md`, +); diff --git a/bench/demo/run-demo.mjs b/bench/demo/run-demo.mjs new file mode 100644 index 00000000..db59f34c --- /dev/null +++ b/bench/demo/run-demo.mjs @@ -0,0 +1,407 @@ +// Runs the demo app's #/benchmark for the solid 1.7 benchmark arms in +// Playwright Chromium (new headless, hardware WebGL) under CDP CPU throttling. +// +// node bench/demo/run-demo.mjs [--arms A,B,C] [--runs N] [--throttle 6] [--interleave] +// [--skip-build] [--query displaySize=20&posterScale=0.5] +// [--tmdb fixtures|live] [--out docs/perf/results] +// [--timeout 300] [--cooldown 2] [--headed] +// +// Arms (see bench/prepare-arms.mjs and the demo's scripts/benchArms.js): +// A solid 1.6.4 on renderer 1.9.3 B 1.6.4 + lockstep patch on renderer v2 +// C this working tree on ../renderer-v2-solid +// +// Unless --skip-build: prepares the arms, then builds each into +// ../solid-demo-app-1.7/dist-bench/ with `BENCH_ARM= vite build`, and +// checks from the sourcemaps that it bundled the arm's solid and renderer and +// one copy each of solid-js and @solidtv/renderer. +// +// Each run is a fresh browser context with empty storage: throttle on a blank +// same-origin page, load `/?&arm=#/benchmark`, wait for the page's +// result log, read `localStorage.benchmarkRuns` (exactly one entry), and write +// /demo---.json. The page drives the presses itself +// (synthetic ArrowDown/ArrowUp, 500ms apart) and times the handler and its +// microtask tail; see the demo's BENCHMARKING.md for every field. +// +// --tmdb fixtures (default) answers api.themoviedb.org with deterministic +// synthetic data (lib.mjs), offline and identical for every arm. --tmdb live +// uses the network and needs the TMDB token in the demo's gitignored +// src/api/key.ts before the build. +import { execFileSync } from 'node:child_process'; +import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; +import os from 'node:os'; +import { join, relative, resolve } from 'node:path'; +import { parseArgs } from 'node:util'; +import { bundleCopies } from './bundle-copies.mjs'; +import { + demoRoot, + launchChromium, + routeTmdbFixtures, + serveDir, + solidRoot, +} from './lib.mjs'; + +const { values: opt } = parseArgs({ + options: { + arms: { type: 'string', default: 'A,B,C' }, + runs: { type: 'string', default: '1' }, + throttle: { type: 'string', default: '6' }, + interleave: { type: 'boolean', default: false }, + 'skip-build': { type: 'boolean', default: false }, + query: { type: 'string', default: 'displaySize=20&posterScale=0.5' }, + tmdb: { type: 'string', default: 'fixtures' }, + out: { type: 'string', default: join(solidRoot, 'docs/perf/results') }, + timeout: { type: 'string', default: '300' }, + cooldown: { type: 'string', default: '2' }, + headed: { type: 'boolean', default: false }, + help: { type: 'boolean', short: 'h', default: false }, + }, +}); +if (opt.help) { + console.log( + readFileSync(new URL(import.meta.url), 'utf8').split('\nimport ')[0], + ); + process.exit(0); +} + +const arms = opt.arms.split(',').map((a) => a.trim().toUpperCase()); +const runs = Math.max(1, parseInt(opt.runs, 10)); +const throttle = parseFloat(opt.throttle); +const timeoutMs = parseFloat(opt.timeout) * 1000; +const outDir = resolve(opt.out); +const rendererC = resolve(solidRoot, '../renderer-v2-solid'); +const EXPECT = { + A: { + solid: join(solidRoot, 'bench/.arms/solid-a'), + renderer: join(solidRoot, 'bench/.arms/renderer-a'), + }, + B: { + solid: join(solidRoot, 'bench/.arms/solid-b'), + renderer: join(solidRoot, 'bench/.arms/renderer-b'), + }, + C: { solid: solidRoot, renderer: rendererC }, +}; +for (const a of arms) if (!EXPECT[a]) throw new Error(`unknown arm ${a}`); +if (!['fixtures', 'live'].includes(opt.tmdb)) + throw new Error('--tmdb is fixtures or live'); + +const distOf = (arm) => join(demoRoot, 'dist-bench', arm); +const git = (dir, ...args) => { + try { + return execFileSync('git', ['-C', dir, ...args], { + stdio: ['ignore', 'pipe', 'ignore'], + }) + .toString() + .trim(); + } catch { + return null; + } +}; +const rev = (dir) => { + const head = git(dir, 'rev-parse', '--short', 'HEAD'); + return ( + head && + `${head}${git(dir, 'status', '--porcelain', '--', 'src') ? '+dirty' : ''}` + ); +}; + +// ── build ──────────────────────────────────────────────────────────────── +if (!opt['skip-build']) { + const { prepareArms } = await import('../prepare-arms.mjs'); + prepareArms({ skipC: !arms.includes('C') }); + for (const arm of arms) { + console.log( + `\n── building arm ${arm} → ${relative(process.cwd(), distOf(arm))}`, + ); + execFileSync( + join(demoRoot, 'node_modules/.bin/vite'), + ['build', '--sourcemap=true', '--logLevel', 'warn'], + { + cwd: demoRoot, + env: { ...process.env, BENCH_ARM: arm }, + stdio: 'inherit', + }, + ); + } +} + +function verifyBuild(arm) { + const copies = bundleCopies(distOf(arm)); + const only = (name) => { + const roots = copies.get(name); + if (!roots || roots.size !== 1) { + throw new Error( + `arm ${arm}: ${name} bundled from ${roots ? [...roots.keys()].join(', ') : 'nowhere'}`, + ); + } + return [...roots.keys()][0]; + }; + const build = { + solidJs: only('solid-js'), + solid: only('@solidtv/solid'), + renderer: only('@solidtv/renderer'), + }; + for (const k of ['solid', 'renderer']) { + if (build[k] !== EXPECT[arm][k]) + throw new Error( + `arm ${arm}: bundled ${k} ${build[k]}, expected ${EXPECT[arm][k]}`, + ); + } + const html = readFileSync(join(distOf(arm), 'index.html'), 'utf8'); + return { + ...build, + entryChunk: /src="\/assets\/(index-[^"]+\.js)"/.exec(html)?.[1] ?? null, + solidVersion: JSON.parse( + readFileSync(join(build.solid, 'package.json'), 'utf8'), + ).version, + rendererVersion: JSON.parse( + readFileSync(join(build.renderer, 'package.json'), 'utf8'), + ).version, + solidRev: arm === 'C' ? rev(solidRoot) : readPin(build.solid), + rendererRev: arm === 'C' ? rev(rendererC) : readPin(build.renderer), + demoRev: rev(demoRoot), + }; +} +function readPin(dir) { + const f = join(dir, '.bench-pin'); + return existsSync(f) ? readFileSync(f, 'utf8').trim() : null; +} + +const builds = {}; +for (const arm of arms) { + if (!existsSync(join(distOf(arm), 'index.html'))) + throw new Error(`no build for arm ${arm}: drop --skip-build`); + builds[arm] = verifyBuild(arm); + console.log( + `arm ${arm}: solid ${builds[arm].solidVersion} (${builds[arm].solidRev}) on renderer ` + + `${builds[arm].rendererVersion} (${builds[arm].rendererRev}); one solid-js, one renderer`, + ); +} + +// ── run ────────────────────────────────────────────────────────────────── +const order = []; +if (opt.interleave) + for (let r = 0; r < runs; r++) for (const arm of arms) order.push(arm); +else for (const arm of arms) for (let r = 0; r < runs; r++) order.push(arm); + +const servers = {}; +for (const arm of arms) servers[arm] = await serveDir(distOf(arm)); +const browser = await launchChromium({ headed: opt.headed }); +mkdirSync(outDir, { recursive: true }); +const date = new Date().toISOString().slice(0, 10); +const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); + +// A fixed busy loop (~15ms unthrottled on an M4 Pro, long enough to span the +// throttler's time slices), timed in the page: its ratio with and without +// throttling shows the throttle took. Best of three. +const calibrate = (page) => + page.evaluate(() => { + let best = Infinity; + for (let k = 0; k < 3; k++) { + const t = performance.now(); + let x = 0; + for (let i = 0; i < 3e7; i++) x += Math.sqrt(i); + best = Math.min(best, performance.now() - t + (x < 0 ? 1 : 0)); + } + return best; + }); + +function nextFile(arm) { + for (let n = 1; ; n++) { + const f = join(outDir, `demo-${date}-${arm}-${n}.json`); + if (!existsSync(f)) return f; + } +} + +async function runOnce(arm, seq) { + const server = servers[arm]; + const context = await browser.newContext({ + viewport: { width: 1920, height: 1080 }, + deviceScaleFactor: 1, + }); + const unknownTmdb = new Set(); + if (opt.tmdb === 'fixtures') + await routeTmdbFixtures(context, server.origin, (p) => unknownTmdb.add(p)); + const page = await context.newPage(); + const errors = []; + let finished; + const done = new Promise((r) => (finished = r)); + page.on('console', (m) => { + if (m.type() === 'error') errors.push(m.text().split('\n')[0]); + if (m.text().includes('BENCHMARK PERFORMANCE RESULTS')) finished(); + }); + page.on('pageerror', (e) => + errors.push(`pageerror: ${e.message.split('\n')[0]}`), + ); + + await page.goto(`${server.origin}/__blank`); + await page.evaluate(() => { + localStorage.clear(); + sessionStorage.clear(); + }); + const gl = await page.evaluate(() => { + const ctx = document.createElement('canvas').getContext('webgl'); + const ext = ctx && ctx.getExtension('WEBGL_debug_renderer_info'); + return ctx + ? ctx.getParameter(ext ? ext.UNMASKED_RENDERER_WEBGL : ctx.RENDERER) + : null; + }); + const cdp = await context.newCDPSession(page); + const unthrottledMs = await calibrate(page); + await cdp.send('Emulation.setCPUThrottlingRate', { rate: throttle }); + const throttledMs = await calibrate(page); + + const url = `${server.origin}/?${opt.query ? `${opt.query}&` : ''}arm=${arm}#/benchmark`; + const loadavgStart = os.loadavg(); + const t0 = Date.now(); + await page.goto(url); + let timer; + const finishedInTime = await Promise.race([ + done.then(() => true), + new Promise((r) => (timer = setTimeout(() => r(false), timeoutMs))), + ]); + clearTimeout(timer); + const wallMs = Date.now() - t0; + const loadavgEnd = os.loadavg(); + if (!finishedInTime) { + await context.close(); + throw new Error( + `arm ${arm}: no benchmark result after ${opt.timeout}s` + + (errors.length + ? `; console errors:\n ${[...new Set(errors)].slice(0, 10).join('\n ')}` + : '') + + (opt.tmdb === 'live' + ? '\n(--tmdb live needs the TMDB token in the demo src/api/key.ts before the build)' + : ''), + ); + } + // The page logs the result, then stores it: let the store land. + await page.waitForFunction( + () => (localStorage.getItem('benchmarkRuns') || '[]').length > 2, + null, + { + timeout: 10000, + }, + ); + const stored = await page.evaluate(() => + JSON.parse(localStorage.getItem('benchmarkRuns') || '[]'), + ); + if (stored.length !== 1) + throw new Error( + `arm ${arm}: expected 1 stored run, found ${stored.length}`, + ); + const postRunThrottledMs = await calibrate(page); + const page2 = await page.evaluate(() => ({ + userAgent: navigator.userAgent, + crossOriginIsolated: self.crossOriginIsolated, + innerWidth, + innerHeight, + devicePixelRatio, + })); + await context.close(); + + const record = { + schema: 'solid-demo-benchmark/1', + arm, + seq, + date: new Date(t0).toISOString(), + url, + storedUrl: stored[0].url, + throttle, + tmdb: opt.tmdb, + build: builds[arm], + env: { + chromium: browser.version(), + gl, + ...page2, + host: `${os.cpus()[0]?.model} x${os.cpus().length}, ${os.platform()} ${os.release()}`, + loadavgStart, + loadavgEnd, + throttleCheck: { + unthrottledMs: +unthrottledMs.toFixed(2), + throttledMs: +throttledMs.toFixed(2), + postRunThrottledMs: +postRunThrottledMs.toFixed(2), + ratio: +(throttledMs / unthrottledMs).toFixed(2), + }, + }, + wallMs, + consoleErrors: [...new Set(errors)], + tmdbUnknownPaths: [...unknownTmdb], + results: stored[0].results, + }; + const file = nextFile(arm); + writeFileSync(file, JSON.stringify(record, null, 2) + '\n'); + return { record, file }; +} + +const records = []; +try { + for (let i = 0; i < order.length; i++) { + const arm = order[i]; + process.stdout.write( + `\nrun ${i + 1}/${order.length}: arm ${arm} (throttle ${throttle}x) ... `, + ); + const { record, file } = await runOnce(arm, i + 1); + records.push(record); + const d = record.results.inputDispatch; + console.log( + `press mean ${d.meanMs}ms, total ${d.totalMs}ms over ${d.keyPresses} presses ` + + `(throttle ×${record.env.throttleCheck.ratio}, load ${record.env.loadavgStart[0].toFixed(1)}) → ${relative(process.cwd(), file)}`, + ); + if (record.consoleErrors.length) + console.log(` console errors: ${record.consoleErrors.join(' | ')}`); + if (i < order.length - 1) await sleep(parseFloat(opt.cooldown) * 1000); + } +} finally { + await browser.close(); + for (const s of Object.values(servers)) await s.close(); +} + +// ── summary ────────────────────────────────────────────────────────────── +const METRICS = [ + ['press mean ms', (r) => r.inputDispatch.meanMs], + ['press total ms', (r) => r.inputDispatch.totalMs], + ['handler total ms', (r) => r.inputDispatch.handlerTotalMs], + ['press max ms', (r) => r.inputDispatch.maxMs], + ['presses', (r) => r.inputDispatch.keyPresses], + ['update total ms', (r) => r.frameWorkSplit.totalUpdateMs], + ['render total ms', (r) => r.frameWorkSplit.totalRenderMs], + ['upload total ms', (r) => r.frameWorkSplit.totalUploadMs], + ['anim fps', (r) => r.frameRateAndSmoothness.avgAnimatedFps], + ['anim p95 ms', (r) => r.frameRateAndSmoothness.animP95Ms], + ['initial render ms', (r) => r.benchmark.initialRenderTimeMs], + ['textures uploaded', (r) => r.assetsAnimationsGeometry.uploadedTextures], +]; +const median = (xs) => { + const s = [...xs].sort((a, b) => a - b); + return s.length % 2 + ? s[(s.length - 1) / 2] + : (s[s.length / 2 - 1] + s[s.length / 2]) / 2; +}; +const fmt = (x) => (Number.isInteger(x) ? String(x) : x.toFixed(2)); +const cell = (xs) => { + const v = xs.filter((x) => typeof x === 'number'); + if (!v.length) return '-'; + if (v.length === 1) return fmt(v[0]); + return `${fmt(median(v))} [${fmt(Math.min(...v))}–${fmt(Math.max(...v))}]`; +}; +const cols = arms.map((arm) => records.filter((r) => r.arm === arm)); +const rows = [ + ['metric', ...arms.map((a, i) => `${a} (n=${cols[i].length})`)], + ...METRICS.map(([name, get]) => [ + name, + ...cols.map((rs) => cell(rs.map((r) => get(r.results)))), + ]), +]; +const widths = rows[0].map((_, c) => Math.max(...rows.map((r) => r[c].length))); +console.log( + `\n${opt.query || 'default scene'}, throttle ${throttle}x, tmdb ${opt.tmdb}` + + (runs > 1 ? '; median [min–max]' : ''), +); +for (const [i, r] of rows.entries()) { + console.log( + r + .map((c, j) => (j ? c.padStart(widths[j]) : c.padEnd(widths[j]))) + .join(' '), + ); + if (i === 0) console.log(widths.map((w) => '-'.repeat(w)).join(' ')); +} diff --git a/bench/harness/analyze.mjs b/bench/harness/analyze.mjs index 18eab85b..8eede0c5 100644 --- a/bench/harness/analyze.mjs +++ b/bench/harness/analyze.mjs @@ -477,13 +477,13 @@ export function writeSummary(dir) { L.push('## Ratios (medians over runs)'); L.push(''); L.push( - "A/C: arm A's value over arm C's (above 1: C is faster or allocates less). The arms' Solid and renderer are listed above: when they are the same code, A/C is the in-session noise floor.", + "A/B: shipping 1.6.4 on renderer 1.9.3 over the lockstep port on renderer v2. B/C: the lockstep port over the working tree, both on renderer v2 (above 1: C is faster or allocates less). The arms' Solid and renderer are listed above: when B and C are the same code, B/C is the in-session noise floor.", ); L.push(''); L.push( - '| scenario | A/C total | A/C handler | A/C frame | A/C bytes/op | A/C writes/op |', + '| scenario | A/B total | B/C total | A/B handler | B/C handler | A/B frame | B/C frame | A/B bytes/op | B/C bytes/op | A/B writes/op | B/C writes/op |', ); - L.push('| --- | --- | --- | --- | --- | --- |'); + L.push('| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |'); for (const s of scenarios) { const arms = by.get(s); const tm = (a, f) => @@ -497,7 +497,7 @@ export function writeSummary(dir) { const wr = (a) => arms.has(a) ? median(arms.get(a).count.map((r) => r.stats.writes)) : null; L.push( - `| ${s} | ${ratio(tm('A', 'total'), tm('C', 'total'))} | ${ratio(tm('A', 'handler'), tm('C', 'handler'))} | ${ratio(tm('A', 'frame'), tm('C', 'frame'))} | ${ratio(al('A'), al('C'))} | ${ratio(wr('A'), wr('C'))} |`, + `| ${s} | ${ratio(tm('A', 'total'), tm('B', 'total'))} | ${ratio(tm('B', 'total'), tm('C', 'total'))} | ${ratio(tm('A', 'handler'), tm('B', 'handler'))} | ${ratio(tm('B', 'handler'), tm('C', 'handler'))} | ${ratio(tm('A', 'frame'), tm('B', 'frame'))} | ${ratio(tm('B', 'frame'), tm('C', 'frame'))} | ${ratio(al('A'), al('B'))} | ${ratio(al('B'), al('C'))} | ${ratio(wr('A'), wr('B'))} | ${ratio(wr('B'), wr('C'))} |`, ); } L.push(''); diff --git a/bench/harness/probe.mjs b/bench/harness/probe.mjs index eeccbb24..bc66b0b6 100644 --- a/bench/harness/probe.mjs +++ b/bench/harness/probe.mjs @@ -29,8 +29,8 @@ // never lands in the op's frames; its handler is timed as `keyup`, and the // probe waits for idle again before the next op. // -// v1 and v2 below are @solidtv/renderer 1.x and 2.x. The arms here run 1.x; -// the 2.x hooks are kept for that renderer and never install on 1.x. +// v1 and v2 below are @solidtv/renderer 1.x and 2.x. Arm A runs 1.x, arms B +// and C 2.x; a hook for one major never installs on the other. export function pageProbe(opts) { const counting = opts.mode === 'count'; const perf = window.performance; diff --git a/bench/prepare-arms.mjs b/bench/prepare-arms.mjs index 270236be..be84aba0 100644 --- a/bench/prepare-arms.mjs +++ b/bench/prepare-arms.mjs @@ -1,8 +1,9 @@ // Prepares the benchmark arms under bench/.arms (gitignored). // // A: solid 1.6.4 on renderer 1.9.3 (what ships today) +// B: solid 1.6.4 + the renderer v2 lockstep patch, on renderer v2 (faf4b9f) // C: this working tree (src/) on its installed @solidtv/renderer -// (node_modules/@solidtv/renderer, whatever version that is) +// (node_modules/@solidtv/renderer: the ../renderer-v2-solid link, built here) // // Re-running is cheap: an arm already prepared at the pinned ref is kept. import { execSync } from 'node:child_process'; @@ -29,7 +30,9 @@ const rendererCVersion = JSON.parse( export const PINS = { solidA: '71c170f', // v1.6.4 + solidB: 'f1c8ab0', // 1.6.4 + solid-lockstep-2.0.patch rendererA: '1.9.3', // npm + rendererB: 'faf4b9f', // renderer v2 (2.0.0-alpha.0) the lockstep patch targets }; export const ARMS = { @@ -39,6 +42,11 @@ export const ARMS = { rendererMajor: 1, rendererVersion: PINS.rendererA, }, + B: { + solid: join(armsDir, 'solid-b'), + renderer: join(armsDir, 'renderer-b'), + rendererMajor: 2, + }, C: { solid: solidRoot, renderer: rendererC, @@ -64,13 +72,17 @@ function gitArchive(repo, ref, dir) { sh(`git -C "${repo}" archive ${ref} | tar -x -C "${dir}"`); } -export function prepareArms() { +export function prepareArms({ skipC = false } = {}) { mkdirSync(armsDir, { recursive: true }); if (!stamped(ARMS.A.solid, PINS.solidA)) { gitArchive(solidRoot, PINS.solidA, ARMS.A.solid); stamp(ARMS.A.solid, PINS.solidA); } + if (!stamped(ARMS.B.solid, PINS.solidB)) { + gitArchive(solidRoot, PINS.solidB, ARMS.B.solid); + stamp(ARMS.B.solid, PINS.solidB); + } if (!stamped(ARMS.A.renderer, PINS.rendererA)) { rmSync(ARMS.A.renderer, { recursive: true, force: true }); mkdirSync(ARMS.A.renderer, { recursive: true }); @@ -90,12 +102,21 @@ export function prepareArms() { ); stamp(ARMS.A.renderer, PINS.rendererA); } - // C builds from the working tree and the installed renderer's dist as - // they are: nothing to prepare. + if (!stamped(ARMS.B.renderer, PINS.rendererB)) { + gitArchive(rendererC, PINS.rendererB, ARMS.B.renderer); + sh( + 'pnpm install --frozen-lockfile --ignore-scripts && pnpm build', + ARMS.B.renderer, + ); + stamp(ARMS.B.renderer, PINS.rendererB); + } + if (!skipC) { + sh('pnpm build', ARMS.C.renderer); + } return ARMS; } if (process.argv[1] === fileURLToPath(import.meta.url)) { - prepareArms(); + prepareArms({ skipC: process.argv.includes('--skip-c') }); console.log(JSON.stringify(ARMS, null, 2)); } diff --git a/bench/run.mjs b/bench/run.mjs index 079ade5a..6ff93739 100644 --- a/bench/run.mjs +++ b/bench/run.mjs @@ -3,7 +3,7 @@ // drives one fresh Chromium per run with CDP CPU throttling. Methodology and // the meaning of every number: docs/perf/README.md. // -// node bench/run.mjs [--arms A,C] [--scenarios id,...] [--runs 3] +// node bench/run.mjs [--arms A,B,C] [--scenarios id,...] [--runs 3] // [--modes time,alloc,profile,count] [--throttle 6] [--skip-build] // [--quick] [--out dir] [--gpu metal|swiftshader|default] [--no-chunks] // [--flex new|old] [--alloc-interval 1] [--profile-interval 50] @@ -35,7 +35,7 @@ const require = createRequire(import.meta.url); const { values: args } = parseArgs({ options: { - arms: { type: 'string', default: 'A,C' }, + arms: { type: 'string', default: 'A,B,C' }, scenarios: { type: 'string' }, runs: { type: 'string', default: '3' }, modes: { type: 'string', default: 'time,alloc,profile,count' }, @@ -249,11 +249,14 @@ function armSource(arm) { if (arm === 'A') { return { solid: PINS.solidA, renderer: `npm ${PINS.rendererA}` }; } - const dirty = - (git(solidRoot, 'status', '--porcelain', '--', 'src') ?? '') !== ''; + if (arm === 'B') { + return { solid: PINS.solidB, renderer: PINS.rendererB }; + } + const dirty = (dir, paths) => + (git(dir, 'status', '--porcelain', '--', ...paths) ?? '') !== ''; return { - solid: `${git(solidRoot, 'rev-parse', '--short', 'HEAD')}${dirty ? '+dirty' : ''}`, - renderer: `installed ${ARMS.C.rendererVersion}`, + solid: `${git(solidRoot, 'rev-parse', '--short', 'HEAD')}${dirty(solidRoot, ['src']) ? '+dirty' : ''}`, + renderer: `${git(ARMS.C.renderer, 'rev-parse', '--short', 'HEAD')}${dirty(ARMS.C.renderer, ['src']) ? '+dirty' : ''}`, }; } @@ -500,7 +503,7 @@ let failures = 0; for (const mode of modes) { for (const scenario of scenarios) { for (let run = 1; run <= runs; run++) { - // Arms interleaved within a run set: A, C, A, C, ... + // Arms interleaved within a run set: A, B, C, A, B, C, ... for (const arm of arms) { const r = await runOnce({ origin, arm, scenario, mode, run }); const file = join( diff --git a/bench/src/arm-v1.ts b/bench/src/arm-v1.ts index 7eed423e..0167a1ec 100644 --- a/bench/src/arm-v1.ts +++ b/bench/src/arm-v1.ts @@ -1,4 +1,4 @@ -// Renderer 1.x bootstrap (both arms): the engines are passed in, and shader +// Renderer 1.x bootstrap (arm A): the engines are passed in, and shader // types register on the stage's shader manager, as solid-demo-app does on 1.9. import { SdfTextRenderer, WebGlCoreRenderer } from '@solidtv/renderer/webgl'; import { diff --git a/bench/src/arm-v2.ts b/bench/src/arm-v2.ts new file mode 100644 index 00000000..6a9941d9 --- /dev/null +++ b/bench/src/arm-v2.ts @@ -0,0 +1,37 @@ +// Renderer 2.x bootstrap (arms B and C): WebGL and SDF text only, and shader +// types register on the renderer, as solid-demo-app-2.0.patch does. +import { + HolePunch, + LinearGradient, + RadialGradient, + Rounded, + RoundedWithBorder, + RoundedWithBorderAndShadow, + RoundedWithShadow, +} from '@solidtv/renderer/webgl/shaders'; + +export const rendererMajor = 2; + +export function rendererOptions(base: T): T { + return base; +} + +const shaderTypes = { + rounded: Rounded, + roundedWithBorder: RoundedWithBorder, + roundedWithShadow: RoundedWithShadow, + roundedWithBorderWithShadow: RoundedWithBorderAndShadow, + radialGradient: RadialGradient, + linearGradient: LinearGradient, + holePunch: HolePunch, +}; + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function registerShaders(renderer: any): void { + for (const name in shaderTypes) { + renderer.registerShaderType( + name, + shaderTypes[name as keyof typeof shaderTypes], + ); + } +} diff --git a/bench/src/scenario.ts b/bench/src/scenario.ts index 971bcfcc..aee16a72 100644 --- a/bench/src/scenario.ts +++ b/bench/src/scenario.ts @@ -6,8 +6,8 @@ import type { JSX } from 'solid-js'; * `warmup` operations and then for `measured` operations, timing each one. * * Scenarios must be arm-agnostic: they use only the public `@solidtv/solid` - * API that solid 1.6.4 (arm A) and the working tree (arm C) share, never the - * renderer directly. + * API that solid 1.6.4 (arms A, B) and the working tree (arm C) share, never + * the renderer directly. */ export interface Scenario { /** Stable kebab-case id, used in URLs (`?scenario=`) and result files. */ diff --git a/bench/vite.config.ts b/bench/vite.config.ts index 143359b1..5dbc840c 100644 --- a/bench/vite.config.ts +++ b/bench/vite.config.ts @@ -1,4 +1,4 @@ -// Builds the benchmark app for one arm: BENCH_ARM=A|C (default C). +// Builds the benchmark app for one arm: BENCH_ARM=A|B|C (default C). // // Every arm compiles its Solid from source (the `src/` of the arm's tree) and // consumes its renderer through the renderer's built `dist`, as apps do. The @@ -42,8 +42,7 @@ if (!(arm in ARMS)) { } const { rendererMajor } = ARMS[arm]; // The renderer bootstrap (engines, shader registration) for the arm's -// renderer major: src/arm-v1.ts. Renderer 1.x is the only one this branch's -// Solid runs on. +// renderer major: src/arm-v1.ts (arm A) or src/arm-v2.ts (arms B and C). const armInit = resolve(here, `src/arm-v${rendererMajor}.ts`); if (!existsSync(armInit)) { throw new Error( @@ -97,7 +96,7 @@ const solidAliases: Alias[] = [ * Count mode only: wraps the default export of the arm's flex layout modules * so that each call (one flex pass over one container) counts. It matches * `export default function (` in src/core/flex.ts and flexLayout.ts, as in - * both arms. A module without it is left alone with a warning, as is a + * every arm. A module without it is left alone with a warning, as is a * build in which neither module was transformed (a path that matches no * module id), and the runner reports flex passes as n/a (`flexHooks` stays 0). */ diff --git a/docs/perf/README.md b/docs/perf/README.md index 1fb49391..b769828c 100644 --- a/docs/perf/README.md +++ b/docs/perf/README.md @@ -1,12 +1,12 @@ # Performance measurement: methodology -How `npm run bench` measures the CPU cost of SolidTV on its two benchmark +How `npm run bench` measures the CPU cost of SolidTV on its three benchmark arms, and what each number means. ## Running it ```sh -npm run bench # every scenario, arms A,C, 3 runs, all modes +npm run bench # every scenario, arms A,B,C, 3 runs, all modes npm run bench -- --scenarios thumbnail-focus --runs 5 --modes time npm run bench -- --scenarios smoke --runs 1 --quick # harness smoke test node bench/run.mjs --summarize docs/perf/results/ # rebuild summary.md only @@ -15,7 +15,7 @@ node bench/harness/inclusive.mjs docs/perf/results/ # inclusive time (need | Option | Default | Meaning | | -------------------- | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `--arms` | `A,C` | Arms to run, interleaved within each run set (A, C, A, C, …) | +| `--arms` | `A,B,C` | Arms to run, interleaved within each run set (A, B, C, A, B, C, …) | | `--scenarios` | every scenario but `smoke` | Scenario ids (`bench/src/scenarios`) | | `--runs` | 3 | Page loads per scenario, arm and mode | | `--modes` | `time,alloc,profile,count` | Measurement modes; each is its own page load | @@ -49,30 +49,34 @@ Run the measured series on a quiet machine: the summary records the ## Arms and builds -| Arm | Solid | Renderer | -| --- | -------------------------- | -------------------------------------------------------------- | -| A | 1.6.4 (`71c170f`) | npm 1.9.3 | -| C | this working tree (`src/`) | the installed `@solidtv/renderer` (`node_modules`), its `dist` | - -`bench/prepare-arms.mjs` prepares arm A under `bench/.arms` (a `git archive` -of the pinned commit, and `npm pack` of the pinned renderer); arm C is the -working tree and whatever `node_modules/@solidtv/renderer` resolves to (its -version is read from its `package.json` and recorded in each result). -`bench/vite.config.ts` builds one arm (`BENCH_ARM=A|C`): Solid compiled from -the arm's source, the renderer from its `dist`, terser without mangling, -`chrome64` target, as the demo app's modern bundle. The renderer bootstrap -(engines, shader registration) is `bench/src/arm-v1.ts`, picked by the -renderer's major version. The build uses the arms' real paths: the bundler's -module ids are real paths, so through a symlinked `bench/.arms` nothing would -match a chunk or the flex hook. The runner rebuilds every arm it runs unless +| Arm | Solid | Renderer | +| --- | ---------------------------------------- | ----------------------------------------------------------------------------------------------- | +| A | 1.6.4 (`71c170f`) | npm 1.9.3 | +| B | 1.6.4 + renderer v2 lockstep (`f1c8ab0`) | v2 `faf4b9f` | +| C | this working tree (`src/`) | the installed `@solidtv/renderer` (`node_modules`: the `../renderer-v2-solid` link), its `dist` | + +`bench/prepare-arms.mjs` prepares arms A and B under `bench/.arms` (a `git +archive` of each pinned commit; `npm pack` of A's renderer, and B's renderer +archived from `../renderer-v2-solid` and built); arm C is the working tree and +whatever `node_modules/@solidtv/renderer` resolves to (on this branch the +`../renderer-v2-solid` link, whose `dist` it rebuilds; its major is read from +its `package.json`). `bench/vite.config.ts` builds one arm (`BENCH_ARM=A|B|C`): +Solid compiled from the arm's source, the renderer from its `dist`, terser +without mangling, `chrome64` target, as the demo app's modern bundle. The +renderer bootstrap (engines, shader registration) is `bench/src/arm-v1.ts` +(arm A) or `bench/src/arm-v2.ts` (arms B and C), picked by the renderer's +major version. The build uses the arms' real paths: the bundler's module ids +are real paths, so through a symlinked `bench/.arms` nothing would match a +chunk or the flex hook. The runner rebuilds every arm it runs unless `--skip-build`, and records each arm's source (`source` in each JSON; C is marked `+dirty` when `src/` has uncommitted changes). -While `src/` is unchanged from 1.6.4, **A and C run the same Solid code**, so -A/C (the ratios in the summary) is the in-session noise floor, plus whatever -differs between the two renderer versions (the summary lists each arm's -Solid and renderer; today's lockfile installs 1.9.0). After a change to `src/`, -A/C is the change's effect (above 1: C is faster or allocates less). +The summary's ratios are A/B (shipping 1.6.4 on renderer 1.9.3 over the +lockstep port on renderer v2) and B/C (the lockstep port over the working +tree, both on renderer v2; above 1: C is faster or allocates less). The +summary lists each arm's Solid and renderer: B/C is the in-session noise +floor only when they match (C at `f1c8ab0` on renderer `faf4b9f`: **B and C +are then the same code**). **Flex.** solid-demo-app sets `VITE_USE_NEW_FLEX=true`, so apps run `src/core/flexLayout.ts`. Every arm is built that way by default (the define @@ -119,6 +123,9 @@ below). warns when it is coarser than 20 µs. - `--disable-background-timer-throttling`, `--disable-renderer-backgrounding` and `--disable-backgrounding-occluded-windows` keep headless timers honest. +- Headless Chromium can run `requestAnimationFrame` at 120 Hz (it does on an + M4 Pro). Renderer v2 caps at its target frame rate, so every other callback + is then an undrawn tick (counted as `undrawnCpu`, a few µs). ### CPU throttling is a duty cycle @@ -164,7 +171,7 @@ warmup and after the measured ops; the summary flags a run whose last two snapshots differ, and a scenario whose final state differs between arms) and `opKind(i)` (a label per op; the summary adds one row per kind, so an alternating create/destroy workload is not reported as one bimodal number). -Scenarios use only the public `@solidtv/solid` API both arms share, never the +Scenarios use only the public `@solidtv/solid` API every arm shares, never the renderer directly. The scenarios (`bench/src/scenarios`): `nav` (Row/Column presses with every @@ -178,9 +185,9 @@ checks the harness. `bench/harness/probe.mjs` is injected before the app's first script. It wraps `requestAnimationFrame` (each callback timed with `performance.now()` into -preallocated typed arrays; a callback that ran `gl.clear` drew a frame: the -renderer clears once per drawn frame) and listens for the renderer's `idle` -event. For each op: +preallocated typed arrays; a callback that ran `gl.clear` drew a frame, and +both renderer majors clear once per drawn frame) and listens for the +renderer's `idle` event (both majors emit it). For each op: 1. **Alignment.** The op starts in a task right after a rendering step (a rAF, then a `MessageChannel` message), so the next frame is a full vsync away. @@ -195,14 +202,18 @@ event. For each op: record). 4. **`frame`.** The CPU time (callback duration) of the first drawn renderer frame after the op: the frame that shows the result. It includes what the - framework does inside the frame (Solid's flex on a text's `loaded` event). - `total` = handler + tail + frame: keydown dispatch to the end of the - renderer frame that shows the result. + framework does inside the frame (Solid's flex on a text's `loaded` event + in arms A and B; in arm C a text in a flex container is measured in the + tail, so only an autosize node's or an animated text's `loaded` relays out + here; and on renderer v2 the `idle` listeners, which v2 emits inside the + last drawn frame). `total` = handler + tail + frame: keydown dispatch to the + end of the renderer frame that shows the result. 5. **Frames until idle.** Every later callback until the renderer's `idle` event: `frames` (drawn), `animCpu` (drawn frames after the first: - transitions), `undrawnCpu` (renderer callbacks that drew nothing: the - renderer's idle polls), `otherRaf` (callbacks that are not the - renderer's). `cpu` = handler + tail + all of those. `settle` = wall time + transitions), `undrawnCpu` (renderer callbacks that drew nothing: v1's + idle polls, v2's capped ticks and upload-only frames), `otherRaf` + (callbacks that are not the renderer's). `cpu` = handler + tail + all of + those. `settle` = wall time from the op's start to the end of its last drawn frame. `frameDelay` = from the tail's end to the first frame's start. 6. **Idle.** The op is over at the renderer's `idle` event followed by 50 ms @@ -266,41 +277,38 @@ out-of-memory probe), which shows up as `getError [native] (renderer)`. Built separately (`BENCH_INSTRUMENT=1` into `dist/-count`). Per op: -| Count | Hook | -| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| flex passes | Build time: the default export of the arm's `src/core/flex.ts` and `flexLayout.ts` is wrapped (`bench/vite.config.ts`, `countFlexPasses`); one call is one container laid out. `n/a` if the hook did not install (the build warns). | -| node writes | Runtime: every configurable setter on the renderer node prototypes (from `renderer.root`, and every node `createNode`/`createTextNode` returns) is wrapped. Only **app writes** count: a setter call made while renderer code is on the stack is skipped (a renderer frame's callback, `createNode`/`createTextNode`/`createShader`/`animate`, another setter, a non-node emitter's dispatch such as a texture's), while the app's listeners the renderer calls (`loaded` and other node events, the renderer's `idle`) run as app code. Per-prop counts in `topWrites.node`. | -| shader writes | Runtime: each shader node's `props` (the node's own `definedProps`: one non-enumerable accessor per prop) is swapped for a counting forwarder, at `createShader` and for existing nodes. App writes only, as above. | -| in frames | The app writes (both kinds) made during a renderer frame: Solid's work in listeners the frame calls, such as flex on a text's `loaded`. The renderer steps animations through its setters; that does not count. | -| created, creation props | Nodes created through `createNode`/`createTextNode`, and the keys with a defined value in the props bag passed to them (the renderer applies the bag in its constructor; never counted as writes). | -| animations | App calls of `animate`/`animateProp` on node prototypes. | -| walks per drawn frame | Iterations of `Stage.drawFrame`'s update loop (counted through reads of `stage.reprocessFrame`). | -| loaded (emitted / heard) | `emit('loaded', …)` on nodes, text when the payload's `type` is `'text'`: every emit, and the ones a listener hears (listeners are in `eventListeners`). Renderer 1.x emits on every text layout and texture load whether or not anything listens. | -| text layout calls and ms | `stage.textRenderers.sdf.renderText` (cache lookup and layout), timed in the instrumented build. | -| layout cache hit rate | `renderText` returning a layout object it returned before (a hit) or a new one (a miss); layouts made before the counters were installed count as a miss on first sight, which the warmup absorbs. | -| frames to final layout | The index (1 = the first drawn frame, 0 = during the handler or tail) of the last renderer frame in which a flex pass, a text layout or a text `loaded` happened; `ms to final layout` is from the op's start to that frame's end (instrumented timing). | +| Count | Hook | +| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| flex passes | Build time: the default export of the arm's `src/core/flex.ts` and `flexLayout.ts` is wrapped (`bench/vite.config.ts`, `countFlexPasses`); one call is one container laid out. `n/a` if the hook did not install (the build warns). | +| node writes | Runtime: every configurable setter on the renderer node prototypes (from `renderer.root`, and every node `createNode`/`createTextNode` returns) is wrapped. Only **app writes** count: a setter call made while renderer code is on the stack is skipped (a renderer frame's callback, `createNode`/`createTextNode`/`createShader`/`animate`, another setter, a non-node emitter's dispatch such as a texture's), while the app's listeners the renderer calls (`loaded` and other node events, the renderer's `idle`) run as app code. v2's `Node.insertBefore` (since `dc09e5e`; the second way, beside the `parent` setter, to attach a child) counts as a write too. Per-prop counts in `topWrites.node`. | +| shader writes | Runtime: each shader node's `props` (v1: the node's own `definedProps`, one non-enumerable accessor per prop; v2: a facade with non-configurable prototype accessors) is swapped for a counting forwarder, at `createShader` and for existing nodes. App writes only, as above. | +| in frames | The app writes (both kinds) made during a renderer frame: Solid's work in listeners the frame calls, such as flex on text `loaded` (arms A and B; arm C measures a text in a flex container in the tail). Renderer v1 steps animations through its setters, v2 writes its arrays; neither counts. | +| created, creation props | Nodes created through `createNode`/`createTextNode`, and the keys with a defined value in the props bag passed to them. Renderer v2 applies the bag through its public setters, v1 in its constructor; both are counted here, the same way, and never as writes. | +| animations | App calls of `animate`/`animateProp` on node prototypes. | +| walks per drawn frame | v2: `renderer.scene.run` (one `ScenePass.run` per walk; `RendererCore.update` walks up to 3 times). v1: iterations of `Stage.drawFrame`'s update loop (counted through reads of `stage.reprocessFrame`). | +| loaded (emitted / heard) | `emit('loaded', …)` on nodes, text when the payload's `type` is `'text'`: every emit, and the ones a listener hears (both majors keep listeners in `eventListeners`). v1 emits on every text layout and texture load whether or not anything listens; v2 queues the event only for a node with a listener, so its two numbers are equal. | +| text layout calls and ms | v2: `renderer.textNodes.lay` (every layout, from a walk's visit or from `TextNode.measure()`: a cache lookup, and the layout on a miss; the renderer's `407b973` and later), else `renderer.textNodes.layoutText` (every walk visit of a text node with `DIRTY_LAYOUT`, which in `faf4b9f` lays out inline: arm B). v1: `stage.textRenderers.sdf.renderText` (cache lookup and layout). Timed in the instrumented build; `layoutText`'s time includes the visit's block placement, `lay`'s does not. | +| layout cache hit rate | v2: `renderer.textNodes.cache.get` hits over lookups (the hook forwards its arguments whatever the signature: a key string in `faf4b9f`, a font record id and the text props since `87633b8`). v1: `renderText` returning a layout object it returned before (a hit) or a new one (a miss); layouts made before the counters were installed count as a miss on first sight, which the warmup absorbs. | +| frames to final layout | The index (1 = the first drawn frame, 0 = during the handler or tail) of the last renderer frame in which a flex pass, a text layout or a text `loaded` happened; `ms to final layout` is from the op's start to that frame's end (instrumented timing). | Hooks. Every one is looked up by name at runtime (the flex wrap at build -time) and the page reports what it found (`hooks` in the count JSON): - -| Hook (`hooks.`) | Feeds | Renderer 1.x | -| --------------------------------------- | ------------------------------------------------ | -------------------------------------------- | -| `flexHooks` (build time) | flex passes, frames to final layout | default export of `flex.ts`, `flexLayout.ts` | -| `nodeAccessors` | node writes, in frames | node prototype setters | -| shader `props` swap (`shaderUnwrapped`) | shader writes | `definedProps` accessors | -| `createHook` | created, creation props | `createNode`, `createTextNode` | -| `animateHooks` | animations | `animate`, `animateProp` | -| `walkHook` | walks, walks/drawn frame | `Stage.drawFrame` loop iterations | -| `drawHook` | drawn frames, walks/drawn frame | `gl.clear` | -| `loadedHook` | loaded (emitted / heard), frames to final layout | `emit` on the node prototype chain | -| `textHook` | text layout calls and ms, frames to final layout | `SdfTextRenderer.renderText` | -| `cacheHook` | layout cache hit rate | `renderText` layout identity | -| `loopHook` | (errors only, below) | `stage.options.handleLoopError` | - -The probe also carries the hooks for `@solidtv/renderer` 2.x (`ScenePass.run`, -`TextNodes.lay`, `LayoutCache.get`, `insertBefore`, `settings.handleLoopError`), -each labelled "v2" in `probe.mjs`: they install only when the renderer has -those names, so on 1.x they never run. +time) and the page reports what it found (`hooks` in the count JSON). A +renderer is not a fixed target: arm C follows `../renderer-v2-solid`, which +renamed and restructured the text path between `faf4b9f` and `6392ce4`. + +| Hook (`hooks.`) | Feeds | A: v1 1.9.3 | B: v2 `faf4b9f` | C: v2 `6392ce4` and later | +| --------------------------------------- | ------------------------------------------------ | -------------------------------------------- | -------------------------- | ------------------------- | +| `flexHooks` (build time) | flex passes, frames to final layout | default export of `flex.ts`, `flexLayout.ts` | same | same | +| `nodeAccessors` | node writes, in frames | node prototype setters | same | same, and `insertBefore` | +| shader `props` swap (`shaderUnwrapped`) | shader writes | `definedProps` accessors | prototype facade | same | +| `createHook` | created, creation props | `createNode`, `createTextNode` | same | same | +| `animateHooks` | animations | `animate`, `animateProp` | same | same | +| `walkHook` | walks, walks/drawn frame | `Stage.drawFrame` loop iterations | `ScenePass.run` | same | +| `drawHook` | drawn frames, walks/drawn frame | `gl.clear` | same | same | +| `loadedHook` | loaded (emitted / heard), frames to final layout | `emit` on the node prototype chain | same | same | +| `textHook` | text layout calls and ms, frames to final layout | `SdfTextRenderer.renderText` | `TextNodes.layoutText` | `TextNodes.lay` | +| `cacheHook` | layout cache hit rate | `renderText` layout identity | `LayoutCache.get` | `LayoutCache.get` | +| `loopHook` | (errors only, below) | `stage.options.handleLoopError` | `settings.handleLoopError` | same | A count whose hook found nothing is **`n/a`, never 0**: the hook stays `null` in the page (for node writes, animations and shader writes: no setter or @@ -308,28 +316,29 @@ method wrapped, or a shader whose `props` could not be swapped), and `countStats` (`bench/harness/analyze.mjs`) reports what it feeds as `n/a`. A `n/a` in a cell means the hook needs updating for that renderer: look for its renamed function and add it next to the others in `installCounters` -(`bench/harness/probe.mjs`). Frames to final layout is `n/a` unless the flex, -text and `loaded` hooks are all there, since it reads their sum. +(`bench/harness/probe.mjs`); prefer a small opt-in probe hook in the +renderer's source over guessing. Frames to final layout is `n/a` unless the +flex, text and `loaded` hooks are all there, since it reads their sum. A hook that **throws** is an error, not a zero. Each hook forwards every argument it is called with, and an exception that passes through one is counted per hook (`hooks.errors`: name, times, first stack), logged once with `console.error` and added to the run's `errors`; so is a hook whose install threw (` (install)`). The run is kept as JSON, left out of the summary -and the runner exits 1. The renderer's frame loop swallows what a frame or a -listener it calls throws and hands it to `handleLoopError`, a no-op by -default (`stage.options.handleLoopError`, a copy of the setting made when the -Stage is built, so the setting itself is not read again): the frame is not -drawn and is tried again, which reads as zero drawn frames and zero counts. -So the probe also counts what reaches it (`renderer frame loop`). An -exception is charged once, to the innermost hook that saw it. +and the runner exits 1. Both renderers' frame loops swallow what a frame or a +listener it calls throws and hand it to `handleLoopError`, a no-op by default +(v2: `settings.handleLoopError`; v1 1.9.3: `stage.options.handleLoopError`, a +copy of the setting made when the Stage is built, so the setting itself is not +read again): the frame is not drawn and is tried again, which reads as zero +drawn frames and zero counts. So the probe also counts what reaches it +(`renderer frame loop`). An exception is charged once, to the innermost hook +that saw it. ## Noise -- **In-session control:** while `src/` is unchanged, A and C are the same - Solid code; their ratio in the summary is the noise floor of that series - (with the renderer-version caveat above). An effect smaller than that - spread is not a result. +- **In-session control:** when B and C are the same code (above), their + ratio in the summary is the noise floor of that series. An effect smaller + than that spread is not a result. - **Runs:** a "faster" claim needs n ≥ 3 runs that beat the noise floor. Use more runs (`--runs 5`) for effects near it. - **Throttling** adds up to ±0.43 ms per op (above); means over 60 ops reduce @@ -362,3 +371,17 @@ exception is charged once, to the innermost hook that saw it. This harness is the in-browser, per-scenario measurement on a desktop CPU under throttling; it is not a substitute for measuring on a device. + +## The demo app and micro-benchmarks + +`bench/demo` runs solid-demo-app (its 1.7 port, `../solid-demo-app-1.7`) per +arm; the demo's own `#/benchmark` and the on-device method are in its +`BENCHMARKING.md`. + +| Script | What it does | +| -------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | +| `bench/demo/run-demo.mjs` | Builds the demo per arm into `dist-bench/` and runs its `#/benchmark` under CDP throttling | +| `bench/demo/route-times.mjs` | Times each demo route from the hash change to the page settling, per arm | +| `bench/demo/check-routes.mjs` | Opens every route of a demo build and reports console errors, page errors and failed requests | +| `bench/demo/bundle-copies.mjs` | Checks from a build's sourcemaps that it bundles one copy each of `solid-js` and `@solidtv/renderer` | +| `bench/micro/accessors.test.tsx` | ElementNode's forwarded-prop accessors on real renderer v2 handles (`npx vitest run --config=bench/micro/vitest.config.ts`) | diff --git a/docs/perf/log.md b/docs/perf/log.md new file mode 100644 index 00000000..493d026f --- /dev/null +++ b/docs/perf/log.md @@ -0,0 +1,707 @@ +# Performance log + +This work was done on the `1.8` branch under the working name "1.7" and +shipped in 1.8 (#89–#92). The `MIGRATION-1.7.md` it mentions became +`MIGRATION-1.8.md`. + +Every Phase 2 change is measured before and after with `npm run bench` and +logged here: the scenario, arms, runs, the numbers, and whether it was kept +(it must beat the noise floor or remove allocations). + +## 2026-10-03: Phase 0 baseline + +- Arms A (1.6.4 on renderer 1.9.3), B (lockstep port on renderer v2 `faf4b9f`) + and C (= B today), 16 scenarios, 6x throttle. +- Time: 3 runs per arm; alloc and count: 1 run; profile: 1-2 runs per arm. +- Results: `results/2026-10-03/summary.md` and `profiles.md`; the demo app's + `#/benchmark`: `results/demo-2026-10-03-*.json`. +- Analysis: `docs/superpowers/specs/2026-10-03-solid-1.7-design.md`, + sections 1 and 2. + +## 2026-10-03: terser `reduce_funcs` (build setting, not a code change) + +- Arm B rebuilt with `BENCH_TERSER_COMPRESS='{"reduce_funcs":false}'`, alloc + mode, 1 run, 4 scenarios: renderer KiB per press 56.7 → 3.4 + (rows-ud-auto), 67.7 → 8.6 (virtual-grid), 8.6 → 4.0 (thumbnail-focus), + 49.6 → 21.0 (text-flex-mount-same). Framework unchanged. +- Not adopted in the bench (it mirrors the demo app's build); proposed for the + demo app in Phase 3 and as renderer proposal P3. + +## Phase 2: per-stream entries + +These are single 6x runs, arms B (frozen lockstep port) and C (each stream's +worktree), taken while other agents ran benchmarks on the same machine (load +average 4-26). Time is rough guidance; allocation (bytes per op) and counts +(flex passes, node writes, walks) are the evidence. Entries read "before arm B +→ after arm C" unless they say "C before → C after". The Checkpoint 2 series +(idle machine, n >= 3, every arm built with terser `reduce_funcs: false`) +replaces them. + +Two harness caveats. Arm B's by-owner allocation split from a worktree run put +everything under `user` (framework and renderer 0.00) until the bench fix +below: totals, counts and times were not affected, so compare totals or sites +by function name. And on renderer `6392ce4` count mode was broken for text +scenarios in arm C (fixed below); stream L's text counts come from a scratch +build of renderer `faf4b9f`. + +### 2026-10-03: Stream M (package exports, renderer-break absorption, terser note) + +- B21 and decision 5.6 run once at startup, and the terser note cites the + 2026-10-03 profile above. No measured change; the bench was not run. + +### 2026-10-03: Stream F (key dispatch, `States`, focus change) + +#### F1, key dispatch without per-event allocation (`8b5a5ad`) + +- What changed: + - Handler prop names cached per key name (no template strings per event). + - One reused listener per event type (no closure per event). + - Key identities as two locals (no `keyIdentities` array, no `for…of` in + `findSuppression`). + - No result object from the bubble walk; `_pendingHistoryKey` updated in + place. + - (The walk skip measured here was removed in fix round 1; see the + fix-round entry below for the numbers without it.) +- Scenarios: rows-lr-noshift, rows-lr-auto, virtual-row; arms B,C; alloc, + count, time; 1 run, 6x. +- Alloc, total KiB/op, B → C: rows-lr-noshift 3.46 → 2.78, rows-lr-auto + 13.27 → 12.58, virtual-row 21.67 → 21.00 (−0.67 to −0.69 each). + - Gone from the top sites: `keyIdentities` 200 B/op, `findSuppression` 168, + per-event closures 176. + - `propagateKeyPress` 220 → 185. The rest is terser `reduce_funcs` IIFE + closures; with `reduce_funcs: false` it is 24 B/op. +- Counts unchanged. Time (rough): rows-lr-noshift total 0.790 → 0.693 ms; + rows-lr-auto and virtual-row within noise. +- Kept. + +#### F2, `States` without species construction (`14e84c7`) + +- What changed: + - `States[Symbol.species]` is `Array`. + - `remove`/`merge` shift in place. + - B2 fix; no class-field emit; no `Object.entries`. +- Measured together with the focus-path change below. +- Gone: `States` 200–216 B/op per navigation op. +- navdrawer-toggle: `States` 3810 + `_super` 1143 B/op removed, `merge` + 3519 → 920 B/op. +- Kept. + +#### F2, O(depth) focus-path diff and one reactive flush per focus change (`560717f`) + +- What changed: + - Generation-stamped path diff (no `indexOf`), a reused build buffer with + one `slice` per change. + - 5.1: the focus phase runs in one `batch`. + - No closures per focus change. +- Scenarios: rows-lr-noshift, thumbnail-focus, portal-focus-text, + navdrawer-toggle; arms B,C; alloc, count, time; 1 run, 6x. C includes F1 + and the `States` change. +- Alloc, total KiB/op, B → C: + + | scenario | B | C | change | + | ----------------- | ----- | ----- | ------ | + | rows-lr-noshift | 3.46 | 2.27 | −34% | + | thumbnail-focus | 12.64 | 11.21 | | + | portal-focus-text | 26.01 | 24.34 | | + | navdrawer-toggle | 22.08 | 14.15 | −36% | + +- Reactivity KiB/op: portal-focus-text 1.80 → 1.08, rows-lr-noshift + 0.83 → 0.71. +- `updateFocusPath` (148 B/op) is gone from the top sites. +- Counts unchanged. Time (rough), total ms B → C: + + | scenario | B | C | + | ----------------- | ----- | ----- | + | rows-lr-noshift | 0.748 | 0.542 | + | thumbnail-focus | 0.717 | 0.613 | + | portal-focus-text | 0.949 | 0.734 | + | navdrawer-toggle | 0.987 | 0.935 | + +- With terser `reduce_funcs: false` (alloc, rows-lr-noshift and + portal-focus-text): + + | scenario | B KiB/op | C KiB/op | + | ----------------- | -------- | -------- | + | rows-lr-noshift | 3.05 | 1.93 | + | portal-focus-text | 10.69 | 9.06 | + + No dispatch or focus-path site remains above 76 B/op. + +- These numbers include F1's walk skip, removed in fix round 1. Without it: + rows-lr-noshift 2.33, portal-focus-text 24.31 KiB/op (next entry). +- Kept. + +#### F1 fix round 1, capture and key-up walks always run again (`7cbdbc7`) + +- What changed: the walk skip (module flags raised from `setProperty`) is + removed. Handlers from `style`, `theme`, `$state` blocks or refs never fired + under it. Everything else in F1 and F2 is unchanged. +- Scenarios: rows-lr-noshift, portal-focus-text; arms B,C; alloc; 1 run, 6x. +- Alloc, total KiB/op, B → C: + + | scenario | B | C | with skip (C) | + | ----------------- | ----- | ----- | ------------- | + | rows-lr-noshift | 3.45 | 2.33 | 2.27 | + | portal-focus-text | 26.06 | 24.31 | 24.34 | + + So the skip was worth at most about 0.06 KiB/op, within noise for + portal-focus-text. + +- `propagateKeyPress` 185 → 247 B/op under the bench's default terser + settings. Both walks now run on every event, and terser `reduce_funcs` + inlines each walk as an IIFE closure. With `reduce_funcs: false` the walks + are plain calls and allocate nothing. +- Kept (correctness). + +### 2026-10-03: Stream P (Row, Column, Grid, Virtual, VirtualGrid, Lazy) + +- **Row/Column transition cache, withScrolling read-once, Grid handlers once + (P1; `4a044c3`, `e3c54c7`, `1f25922`).** Scenarios rows-lr-auto, + rows-ud-auto, rows-lr-always. Framework bytes/op C 1.85 → 1.86, 2.40 → 2.39, + 1.86 → 1.88 (B has no framework bucket; totals B 13.24/59.79/13.18 vs C + 13.22/59.93/13.28): no measurable change at one run (the merged transition + was one small object per press). Flex 0 → 0, node writes 2.0 → 2.0. Time + total C 0.438 → 0.583, 0.770 → 0.455, 0.566 → 0.602 while B moved + 0.472 → 0.511, 0.657 → 0.522, 0.527 → 0.543: noise. **Kept** (removes a + per-press allocation and repeated accessor reads by construction; no + regression in counts or bytes). +- **Virtual: one SliceState, items signal, cursor out of the spread, one flex + pass per shift, no closure per press (`704063c`).** virtual-row: flex passes + 1.9 → 0.9, node writes 26.1 → 15.2, framework 8.35 → 5.82 KiB/op + (`calculateFlex` 4733 → 2341 B; the `onSelectedChanged` 152 B and + `computeSlice` 145 B sites gone), total 21.72 → 19.17 KiB; time C + 1.004 → 0.964 (B 1.058 → 0.880). text-virtual-row: flex 4.2 → 3.2, writes + 29.7 → 20.7, framework 9.93 → 8.80 KiB, total 38.75 → 37.90; time C + 1.185 → 1.001 (B 1.100 → 1.037). **Kept.** +- **VirtualGrid: one flex pass per row change, cursor out of the spread, no + closure per press (`dc7117c`).** virtual-grid: flex 2.0 → 1.0, node writes + 179.0 → 96.5, total 37.85 → 35.25 KiB (renderer 20.74 → 18.24), framework + 11.17 → 11.29 KiB (flat: list reconcile and flex scratch dominate); time C + 1.618 → 1.252 (B 1.403 → 1.590). **Kept.** +- **Virtual reuses the shift animation's props/settings (`c2b0e95`).** + virtual-row (renderer `6392ce4`): framework 5.96 → 5.93 KiB/op, the + `applyShift` site (116 B/op) leaves the top sites; flex 0.9, writes 15.2 + unchanged. **Kept.** +- **Grid `y` in its own effect (`728fcb5`).** No bench scenario has a Grid; the + contract test shows an unrelated prop getter read 4 times over three + vertical moves before, once (mount) after. **Kept.** +- The fix rounds (B14, B15, B13 with wrap, the per-element transition cache) + change no hot-path work and were not re-benchmarked. + +### 2026-10-03: Stream L (one flex engine, layout queue) + +Arm C ran on renderer `faf4b9f` (arm B's renderer) for these entries. + +- **L1, one allocation-free flex engine, write only what changed (`23e9f94`, + `59ab929`).** Scenarios text-details-panel, text-flex-mount-same/-new, + virtual-row, virtual-grid; arm B → arm C. Node writes per op: 54.4 → 15.0, + 91.0 → 50.0, 91.0 → 50.0, 26.1 → 15.2, 179.0 → 51.9. Bytes charged to the + flex function per op: 9,725 → 1,284 (details panel), 28,884 → below the top 5 + (mount), 4,728 → 1,878 (virtual-row), 2,256 → below the top 5 + (virtual-grid). Framework KiB per op (C before → after): 12.05 → 3.62, + 55.04 → 28.04, 64.24 → 28.03, 8.37 → 5.58, 12.55 → 8.62. Flex passes + unchanged (7, 42, 42, 1.9, 2.0). Time within noise. Micro-benchmark: + 2.1 KB → 0-2 B per pass with integral values. **Kept.** +- **L2, depth-ordered layout queue; `loaded` queues the parent; microtask-only + scheduling (`31e6c78`).** text-details-panel flex passes 7.0 → **3.0**; + text-flex-mount-same/-new 42.0 → **32.0**; virtual-row/-grid unchanged (1.9, + 2.0); walks per drawn frame 2.00 and loaded 5/5, 20/20 unchanged (T's); + frames to final layout 1.0 (same frame as before). Time (rough): details + panel C 0.889 → 0.796 ms, mount-new 2.473 → 1.455 ms (noisy). WebGL test: + first render of a 3-text row, flex passes on the row 4 → 2. **Kept.** +- **Transition-aware flex writes, reentrancy guard, one write loop (`57bb69a`, + `89a54f0`).** Correctness fixes; allocation (bytes per op charged to the + flex function, arm C, `faf4b9f`): text-details-panel 1,316 → 1,761, + virtual-row 1,896 → 1,492, virtual-grid below the top 30 sites before and + after (5,344 in between, fixed by `89a54f0`). Flex passes and node writes + unchanged. **Kept.** +- **flexGrow container: one onLayout after its children, its second pass + inline (`8513151`).** No bench scenario has flexGrow; no measured change. + **Kept.** +- **Grown auto-sizing child: no rewrite on relayout (`08d7647`).** + Correctness/write-count fix, no bench scenario has flexGrow. Two relayouts: + 4 width writes and 2 extra child passes → 0 and 0. **Kept.** +- **Per-justify write loops back (`a69c3b6`).** text-details-panel flex-pass + bytes per op 1,771 → 1,496 (L2: 1,490); virtual-row 1,513 → 1,842 + (L2: 1,896); virtual-grid unchanged (below the top 30). **Kept.** The + residual 1.3-1.9 KB/op charged to the flex function is number boxing in the + accessor paths, not engine scratch. + +### 2026-10-03: Stream N (nodes: accessors, handle hygiene, draw order) + +- **N1 / B17 + B20 + 3.6.5 (`e33db56`, `7d40658`, `d342c37`).** fontWeight and + fontFamily resolved in one place; text-only props of non-text elements kept + on the ElementNode; absX/absY/destroyed writes ignored; TextNode fields + assigned in the constructor. Scenarios rows-lr-auto, virtual-row, + portal-focus-text, text-virtual-row. Framework bytes/op 1897 → 1897, + 8536 → 8565, 1952 → 1970, 10181 → 10160 (no change); counts identical; time + B/C 1.13–1.17 → 0.80–1.19 (noise). Bundle +185 B gzip. Kept (bug fixes). +- **N1 / 3.6.6 written-out accessors (`d33c789`).** One getter/setter per + forwarded prop with a constant name; direct store unless `transition`. Same + scenarios. Framework bytes/op virtual-row 8565 → 9307 (+733 B from a + terser-inlined IIFE of the now single-use `getPropertyAlias`), others ±1 %. + Time B/C 0.89–1.30 (noise). Superseded by the next entry. +- **N1 / 3.6.6 + alias inline (`a2666f2`).** Same, `getPropertyAlias` written + inline. Scenarios as above + virtual-grid. Framework bytes/op vs fixes: + 1897 → 1915, 8565 → 8596, 1970 → 1951, 10160 → 10179 (neutral). Time B/C + 0.94–1.33 (noise). Profile, C, shared accessor self time µs/op vs fixes: + virtual-grid 126 → 0, text-virtual-row 81 → 0, virtual-row 19 → 0, + portal-focus-text 18 → 0. Isolated (real v2 handles, unthrottled), + `npx vitest run --config=bench/micro/vitest.config.ts --reporter=verbose` + (`bench/micro/accessors.test.tsx`, best of 15; six runs per version, the + `elementNode.ts` of `d342c37` vs `a2666f2`/`3bbe034`): 1.6 M reads + 15.9–16.3 → 1.00–1.20 ms, 400 k writes 14.7–15.5 → 1.40–1.60 ms. Bundle + 20 967 → 21 731 B gzip (+764). **Kept pending the Checkpoint 2 series:** + allocations are neutral and scenario time could not resolve it from the + noise; revert `a2666f2` and `d33c789` if the series shows no win. +- **N2, B19 draw order and an allocation-free child list (`d5db836`, + `f611469`).** Scenarios virtual-row, virtual-grid, poster-swap (alloc, + count; C before = `71fb38b`, C after = `f611469`; B frozen; renderer + `6392ce4`). + - Framework B/op: virtual-row 8570 → 8511, virtual-grid 11412 → 11116, + poster-swap 13776 → 13555. The `spliceItem` sites (121, 401, 440 B/op) are + gone. + - Node writes/op: 26.15 → 24.8 and 179.0 → 171.1. The removed `parent` + writes became `insertBefore` calls, which the probe does not count. + - Flex passes and drawn frames are unchanged. + - Kept (bug fix plus child-list cost). + +### 2026-10-03: Stream R (renderer: `measure()`, text-keyed cache, `insertBefore`) + +- **R1, `TextNode.measure()`.** + - Unit evidence: layouts in the walk after `measure()` 0, `updateIterations` + 1, `loaded` once for a listener, text under culled parents sized. + - Solid scenarios: not measured here; stream T wires it in. The expected + numbers are text-flex-alternatives §2.2's prototype: details panel walks + 2 → 1, `loaded` 6 → 0, layouts in the walk 6 → 0. + - Kept. +- **R2, text-keyed `LayoutCache`.** + - Renderer micro-benchmark, per hit: + - title 0.386-0.427 µs / 845 B → 0.016-0.017 µs / 0 B; + - description 0.767-0.833 µs / 1121 B → 0.016-0.018 µs / 0 B; + - newly built text string 0.410 → 0.120 µs. + - Miss path unchanged within noise (+96 B per insert). + - Kept. +- **R3, typed-array width tables in the line breaker.** Held back, not + integrated. + - Renderer micro-benchmark, line breaking: title 0.665-0.709 → 0.210-0.224 µs + (3.1×); description 7.34-7.54 → 3.36-4.25 µs (1.8-2.2×). + - `layoutText`: title 1.69-1.77 → 1.30-1.32 µs; description 16.2-17.8 → + 13.6-14.4 µs. + - Parity: 17,100 cases, plus 6,840 whole layouts, bit-identical. + - Bundle +1,076 / +516 B: with R1-R4 the renderer is 171,955 / 54,373 B + against CI's 172,032 / 54,272 B ceiling, 101 B gzip over; without R3 + 170,881 / 53,844 B. + - Kept in the renderer's history as `770c80f`, reverted pending the user's + bundle-budget decision at Checkpoint 2. +- **R4, public `insertBefore`.** + - Draw order follows the insertion order (unit test on emitted quads). + - The Solid draw-order fix and its scenarios are stream N's (N2 above). + - Bundle +540 / +206 B. + - Kept. +- Numbers are desktop Node/V8; TV hardware was not measured. + +### 2026-10-03: Stream B (page-creation baseline) + +- New scenarios page-mount and page-swap: a Browse-like page, a Column of 7 + Rows x 20 Poster tiles (poster.tsx's tile + subtitle + badge), 582 nodes, + 5893 creation props, text: true. Arms A, B, C (C = B, `src` unchanged since + `44e2b76`), 6x, time 3 runs, alloc and count 1 run, in + `results/2026-10-03/summary.md`. +- page-mount create (B → C, same code): total 11.26 → 12.92 ms (noise, B/C + spread 14%); destroy 0.95 → 1.22 ms; alloc (mean over the create and destroy + ops) 332.5 → 332.5 KiB/op (framework 109.2 → 108.8, renderer 94.9 → 95.8). + A: create 14.55 ms, 959.5 KiB/op (renderer 721). The scenario puts 78% of its + texts out of bounds, so it over-weights decision 5.2's eager-layout cost + relative to real routes (Virtual). +- page-swap (B → C): total 12.32 → 12.21 ms; alloc 688.4 → 689.9 KiB/op + (framework 207.8 → 207.8, reactivity 131.4, user 121.4); A: 14.64 ms, + 1893 KiB/op. Counts per swap: 8 flex passes, 156 node writes, 4 shader + writes, 582 created, 12.6 drawn frames, 63 text layouts (all cache hits). +- Per-route timing: `bench/demo/route-times.mjs`, + `results/routes-2026-10-03.md`. Sum over 51 routes, main-thread busy ms: + A 3289, B 3163, C 3162 (settle 17273 / 17664 / 17600, timer-dominated). +- Kept: these are the baselines the Phase 2 changes are measured against. + +### 2026-10-03: Bench fix (count mode on renderer v2's text path) + +- Not a Solid change. Two causes: the cache hook forwarded only its first + argument, so `LayoutCache.get(font, props)` threw inside renderer v2's frame + loop, which swallowed it (arm C text scenarios drew nothing in count mode); + and a worktree's symlinked `bench/.arms` built arm B (and A) without chunks + and without the flex hook. Fixed in `cc75282` and `f348e6c` (`adbbbc8` for the + review round): hooks forward `arguments`, count `TextNodes.lay`, count + `insertBefore` as a node write, report `n/a` for a hook that found nothing, + and fail the run on a hook error. +- Scenarios text-details-panel and text-flex-mount-same, count mode. C before → + after (full op counts): text-details-panel flex passes 0.0 → 7.0, writes / + in frames 10.0 / 0.0 → 54.4 / 44.4, walks per drawn frame n/a → 2.00, drawn + frames 0.0 → 1.0, loaded text emitted / heard 0.0 / 0.0 → 5.0 / 5.0, text + layout calls 0.0 → 7.0 (hit rate n/a → 1.00); text-flex-mount-same flex + passes 21.0 (handler only) → 42.0, writes / in frames 21.0 / 0.0 → 91.0 / + 70.0, loaded 0.0 / 0.0 → 20.0 / 20.0, text layout calls 0.0 → 20.0. +- B before → after: flex passes n/a → 7.0 (text-details-panel), 42.0 + (text-flex-mount-same), 0.0 (rows-lr-noshift). After the fix B and C are + identical on every count that does not depend on time (text-details-panel + 7.0 flex, 54.4 writes, 2.00 walks per drawn frame, 5 / 5 loaded, 7.0 text + layouts; text-virtual-row 4.2 flex, 29.7 writes), and arm A matches the + 2026-10-03 baseline. +- Kept. Earlier by-owner B splits from worktree runs (framework 0.00, + renderer 0.00) are not valid; re-measure them in the Checkpoint 2 series. + +### 2026-10-03: Stream T (flex text measured with `TextNode.measure()`) + +Arm C ran on renderer `renderer-v2-solid` as linked (R1 and R2 merged). "C +before → after" is the worktree at `6552a03` (post-N) and at the T commit. +Runs `bench-T-before` and `bench-T-after`: arms B,C, count, alloc and time, 1 +run at 6x. The after run ran under heavier load than the before run (arm B +itself was 2-4x slower), so only C/B within one run says anything about time. + +- **T1, Solid measures flex text with `TextNode.measure()` before the frame + (`bcf31d2`).** + - What changed: + - A `` whose parent lays out (`display="flex"` or an `onLayout`) + is measured in the post-mutation pass, before the parent's flex and + before the frame. No persistent `loaded` listener; the parent is queued + only when the measured size changed. + - Texts that flex sized (`flexGrow`, `flexShrink`, `minWidth`) are + measured again after each sweep, capped at 16 sweeps. + - A text whose font is missing waits on one shared listener and on + `loadFonts()`'s promise, then lays out once. + - Text under culled or alpha-0 ancestors is laid out at mount (decision + 5.2). + - Per-text state is one `TextMeasure` record, made when a text is first + queued or measured. + - Scenarios: text-details-panel, text-flex-mount-same, text-flex-mount-new, + text-virtual-row, page-mount, page-swap. + - Count mode, per op, C before → after (arm B in brackets): + + | scenario | flex passes | walks / drawn frame | `loaded` text emitted / heard | text layout calls | layout cache hit rate | frames to final layout | node writes\* | + | -------------------- | ------------------ | ------------------- | ----------------------------- | ----------------- | --------------------- | ---------------------- | ------------------ | + | text-details-panel | 3.0 → 3.0 [7.0] | 2.00 → 1.00 [2.00] | 5/5 → 0/0 [5/5] | 7.0 → 7.0 | 1.00 → 1.00 | 1.0 → 1.0 | 10.0 → 15.0 [54.4] | + | text-flex-mount-same | 32.0 → 21.0 [42.0] | 2.00 → 1.00 | 20/20 → 0/0 | 20 → 40 | 1.00 → 1.00 | 1.0 → 0.0 | 21.0 → 82.0 [91.0] | + | text-flex-mount-new | 32.0 → 21.0 [42.0] | 2.00 → 1.00 | 20/20 → 0/0 | 20 → 40 | 0.00 → 0.00 | 1.0 → 0.0 | 21.0 → 82.0 [91.0] | + | text-virtual-row | 2.3 → 1.9 [4.2] | 1.03 → 1.00 [1.03] | 1.9/1.9 → 0/0 | 1.9 → 1.9 | 1.00 → 1.00 | 1.0 → 0.0 | 14.7 → 15.5 [29.7] | + | page-mount | 4.0 → 4.0 | 1.00 → 1.00 | 0/0 → 0/0 | 31.5 → 31.5 | 1.00 → 1.00 | 1.0 → 1.0 | 74.0 → 74.0 | + | page-swap | 8.0 → 8.0 | 1.00 → 1.00 | 0/0 → 0/0 | 63.0 → 63.0 | 1.00 → 1.00 | 1.0 → 1.0 | 149.0 → 149.0 | + - Targets: walks 1, `loaded` heard 0, flex passes 21 for a mount and 3 for + the details panel (target 4): met. + - Text layouts double in the mounts (20 → 40): the 20 culled tiles' texts + are now laid out at mount (5.2), all cache misses in -new. + - Frames to final layout 0.0: the final layout is in place before the + op's first frame, computed in the microtask. + - \*Node writes rose because they are now all counted, not because more + are made. The probe skips writes made with renderer code on the stack, + and before T1 the flex that a `loaded` triggered ran inside the frame + (stream L's footnote). Arm B shows the same from the other side: 91 + writes, 70 of them in frames. Details panel: 15.0 is L1's comparable + figure. + - page-mount and page-swap do not exercise the change: their tile texts + sit in plain views, so Solid measures none of the 287 texts. + + - Allocation, KiB/op, C before → after: + + | scenario | total | framework | renderer | user | + | -------------------- | --------------- | --------------- | --------------- | --------------- | + | text-details-panel | 8.35 → 8.57 | 2.74 → 2.50 | 3.69 → 4.12 | 0 → 0 | + | text-flex-mount-same | 77.97 → 69.21 | 27.30 → 20.39 | 15.44 → 13.26 | 17.33 → 17.64 | + | text-flex-mount-new | 112.05 → 188.07 | 27.02 → 20.56 | 49.78 → 131.95 | 17.33 → 17.64 | + | text-virtual-row | 27.92 → 31.41 | 3.74 → 3.37 | 21.57 → 25.43 | 0 → 0 | + | page-mount | 339.07 → 319.46 | 103.04 → 101.89 | 98.38 → 78.79 | 71.73 → 72.76 | + | page-swap | 670.63 → 672.42 | 197.18 → 197.51 | 201.21 → 200.26 | 141.11 → 143.29 | + - Framework: the per-text `_layoutOnLoad` closures are gone, -6.9 KiB/op + on each mount, and the `_layoutOnLoad` site (7,040 B/op) left the top 5. + - text-flex-mount-new renderer is up because the culled tiles' texts are + laid out at mount, every one a miss (5.2). The figure is noisy: the same + code measured 145.01 KiB at `969b7d8` and 49.78 at `6552a03`. The other + renderer movements are sampling noise at 1 run; in the details panel + the top renderer sites are the walk's `emit` and the visit's transform + IIFE, not text. + + - Time, ms per op, B / C: rough. + + | scenario | C/B before | C/B after | before B / C | after B / C | + | -------------------- | ---------- | --------- | -------------- | --------------- | + | text-details-panel | 1.14 | 0.98 | 0.248 / 0.283 | 1.116 / 1.095 | + | text-flex-mount-new | 0.81 | 0.65 | 1.797 / 1.456 | 3.448 / 2.250 | + | text-flex-mount-same | 0.88 | 0.80 | 0.778 / 0.688 | 1.870 / 1.492 | + | text-virtual-row | 0.90 | 0.74 | 0.432 / 0.387 | 1.172 / 0.870 | + | page-mount | 1.06 | 0.94 | 5.032 / 5.341 | 7.248 / 6.808 | + | page-swap | 0.93 | 0.86 | 10.056 / 9.340 | 12.118 / 10.455 | + - text-details-panel's frame part went from C/B 0.80 to 0.32: the second + walk is gone. The tail grew, because the measure moved into the + microtask. + + - **Kept.** + +- **T1 variant, dropped: measurement state in four `ElementNode` fields.** + - V8 boxes double fields at construction, about 32 B on every node and every + view. page-mount framework + user +9.4 KiB/op, page-swap +23.4 KiB/op + (`bench-T-after-fields-partial`): framework 108.12 and user 76.04, and + 211.74 and 149.97, against 101.89 and 197.51 with the record. + - Replaced by the per-text `TextMeasure` record before the commit. +- **T1 fix round 1 (`f2c8bf8`, `f298320`, `9d8716a`).** + - What changed: + - DOM `loaded` against the last size told. + - A text's layout transition or `animate()` relays out its container + (1.6's result), through one shared listener. + - Queue throw-safety; dropping the remaining texts at the sweep cap (it + had started over in a microtask loop that hung the page). + - `contain` marks a text dirty. + - A DOM late re-measure listener; a sweep of the font-waiting list. + - Scenarios: the six above, arm C, count and alloc (`bench-T-fix1`). + - Counts identical to `bcf31d2`: flex passes 3.0 / 21.0 / 21.0 / 1.9 / 4.0 / + 8.0, walks 1.00 everywhere, `loaded` 0 / 0, text layouts 7 / 40 / 40 / 1.9 + / 31.5 / 63. Framework KiB/op 2.49 / 21.09 / 20.55 / 3.37 / 102.92 / + 196.05 (details panel, mount-same, mount-new, virtual-row, page-mount, + page-swap), within noise of `bcf31d2`. No scenario animates a text's + layout props, so the new path costs nothing here. + - Deferred to the renderer: two `loaded` events for one text, the first + with stale dimensions, when it is measured in two post-mutation runs + before one frame (renderer proposal P5). + - **Kept.** +- **T1 fix round 2 (`f51c63c`, `44a15a3`).** + - What changed: no sweep of the font-waiting list while it is being + measured; a text Solid animated through the element keeps one `loaded` + listener for its lifetime (the module list and the controller tracking + are gone); DOM `destroyed` is true for the descendants of a destroyed + node. + - Scenarios: the six above, arm C, count mode (`bench-T-fix2`). Counts + unchanged from round 1; no scenario animates a text's layout props. + - Accepted allocation: because of that listener, renderer v2's + `TextNodes.lay()` allocates the `loaded` payload (2 objects) on each later + layout of such a text. That is per text change, with no extra walk, and + only for texts animated through the element. Production WebGL builds do + not allocate it for any other text; development builds, which carry a + warning listener on every measured text, and the DOM renderer, which + carries a `loaded` listener on every measured text, queue `loaded` for + each layout. + - **Kept.** +- **T1 fix round 3 (`5a47510`).** Tests only: the font-waiting cases moved to + `tests/fontWaiting.test.ts`, each in a fresh module instance. No measured + change. + +#### Open item: layout cache size (`textLayoutCacheSize`), for the user + +Eager measuring (5.2) is kept. The default (250) is unchanged in code and in +the docs; nothing here sets a new value. + +- **Experiment, not committed.** `PageTile`'s view gets a no-op `onLayout`, so + every tile text (title and meta) is measured: 283 texts per page. Count + mode, 1 run at 6x. Arm B, which has no eager measuring, makes 31.5 + (page-mount) and 63.0 (page-swap) text layouts per op at hit rate 1.00 and + 0.270 / 0.266 ms per op. Arm C makes 141.5 and 283.0 layouts per op, the + approved cost of 5.2, at: + + | `textLayoutCacheSize` | run | page-mount hit rate | page-swap hit rate | page-mount layout ms/op | page-swap layout ms/op | + | --------------------- | -------------------------------------- | ------------------- | ------------------ | ----------------------- | ---------------------- | + | 250 (default) | `bench-T-pagetiles-measured` | 0.00 | 0.01 | 2.350 | 5.043 | + | 512 | `bench-T-pagetiles-measured-cache512` | 1.00 | 0.01 | 0.266 | 5.131 | + | 1024 | `bench-T-pagetiles-measured-cache1024` | 1.00 | 1.00 | 0.134 | 0.217 | + + Layout ms are from the count build, which is instrumented. + +- **Why.** A page measures 283 strings, more than 250. An LRU scanned in a + cycle longer than its size never hits, whatever its size. At 512 one page + fits, so remounting the same page hits, but swapping between two pages + cycles 566 distinct strings and thrashes as at 250. At 1024 both fit. A + cache helps an app that cycles between screens only when it holds every + string of the screens it cycles through. +- **Memory for a full cache**, estimated from + `docs/perf/text-flex-alternatives.md` (about 1.5 kB per title layout and + about 12.6 kB per description layout; not measured in this stream): + + | entries | all title-like (about 1.5 kB) | all description-like (about 12.6 kB) | + | ------- | ----------------------------- | ------------------------------------ | + | 250 | 0.37 MB | 3.1 MB | + | 512 | 0.75 MB | 6.3 MB | + | 1024 | 1.5 MB | 12.6 MB | + + The bench pages' texts are all title-like (titles and one-line meta), so + 283 entries are about 0.42 MB. A details page adds a few descriptions, about + 12.6 kB each. + +- **Options raised, none taken.** + - Raise the size when the app sets none. Solid could do it in + `createRenderer` (`lightningInit.ts`) with no renderer change, or the + renderer's default could change. + - Measure only texts whose layout container is visible or in the margin. + This needs a visibility read from the renderer, gives back part of 5.2 + (including the fix for a container whose visibility depends on its own + text, `docs/perf/text-flex-alternatives.md` section 1.3), and keeps the + second walk on scroll. + - Renderer proposal P6: size the cache in bytes, or make it scan-resistant. +- Numbers are desktop Node/V8, from single runs; TV hardware was not measured. + +### 2026-10-03: Stream S (compiled style plans, diffed state application, B18 shader-prop resets) + +Arm C is the `1.7-styles` worktree from `44e2b76`; arm B is the frozen lockstep +port. Single 6x runs (alloc, count, time), profile 1-3 runs. Arm B's bundle +charges framework and renderer both to `user`, so B's framework share is the sum +of its sampled sites in the framework's line range of `user.js` (`toVec4` +excluded: renderer code bundled there). "S's sites" are the functions this +stream replaced. The framework bytes that remain in C are stream F's (the focus +manager, `States` `merge`/`add`/species construction), not S's. + +- **S1: compiled style plans, diffed state application, shader-prop writes from + cached parses, B18 resets (`c8ed9df`, with `d6d59af`).** Scenarios + thumbnail-focus, navdrawer-toggle, rows-lr-noshift, portal-focus-text, arm B → + arm C at `d6d59af`. + - Allocation, KiB per op: + + | scenario | B total | C total | B framework | C framework | S's sites on B | S's sites on C | + | ----------------- | ------- | ------- | ----------- | ----------- | -------------- | -------------- | + | thumbnail-focus | 12.29 | 10.95 | 2.63 | 1.52 | 1.34 | 0 | + | navdrawer-toggle | 22.29 | 14.50 | 14.91 | 7.29 | 7.95 | 0 | + | rows-lr-noshift | 3.45 | 3.20 | 1.72 | 1.53 | 0.23 | 0 | + | portal-focus-text | 25.93 | 25.77 | 1.58 | 1.67 | 0.21 | 0 | + + S's sites on B: thumbnail-focus `parseAndAssignShaderProps` 0.48, its + `Object.entries`/`forEach` closure 0.63, `_stateChanged` 0.23; + navdrawer-toggle `_stateChanged` 3.91, its closures 1.24, the + `forwardStates` `slice()` (species `States` + `_super`) 2.80; + rows-lr-noshift and portal-focus-text `_stateChanged` only. No S function is + among C's sampled allocation sites in any scenario: state application and + shader-prop writes allocate nothing per press. + + - Counts per op, B → C: node writes thumbnail-focus 0 → 0, navdrawer-toggle + 25.0 → 23.0, rows-lr-noshift 2.0 → 2.0, portal-focus-text 6.0 → 6.0; shader + writes 6.2 → 8.2, 2.0 → 1.0, 0 → 0, 0 → 0; animations unchanged (2, 2, 0, + 3). Thumbnail-focus shader writes go up by the B18 resets on blur + (`border-gap` 4 → 0 is a real change; `border-align` resolves to the value + it holds, so the v2 facade drops it without a repack). Every other + sub-prop there changes on each focus and blur, so the diff saves nothing in + that scenario; it saves writes where focus and base share sub-prop values + (navdrawer 2 → 1). + - Inclusive CPU of `_stateChanged`, µs per op, B → C (each sample weighted by + its run's median interval, because the sampler stalled 0.7-1.5 ms under + load): thumbnail-focus 49.0 → 37.6 (1 run), navdrawer-toggle 98.4 → 73.8 (1 + run), rows-lr-noshift 13.8 → 12.1 (3 runs), portal-focus-text 14.2 → 11.4 (3 + runs). Inside thumbnail-focus: B's `parseAndAssignShaderProps` 14.8, C's + `writeShaderValue` 12.5 (both include the renderer facade writes, which + dominate). + - Time, ms per press total, B → C: 0.648 → 0.653, 1.006 → 0.784, 0.535 → + 0.631, 0.632 → 0.681. Not evidence either way: arm B alone ranged 0.63-0.95 + on portal-focus-text across the day's runs. + - Targets (design 6): framework bytes per press from state application → 0, + met for S's part in all four scenarios. navdrawer-toggle ≤ 1 KiB framework: + 7.29, none of it S's (`States.merge` through `forwardStates` is 3.5 KiB/op, + stream F's). + - **Kept.** + +- **Inline the single-use helpers terser turns into closures (`d6d59af`).** + navdrawer-toggle alloc, 1 run: C framework 7.97 → 7.29 KiB/op (`set states` + 0.69 KiB/op → 0). With terser's default `reduce_funcs` a single-use helper + becomes a closure per call; the demo app builds with it off, other apps may + not. **Kept.** +- **Gradient accessors reuse their shader (`a395219`).** Not measured: no + scenario sets a gradient twice. It removes a `createShader` (a shader, its + facade, its values, a program-slot lookup) per set after the first. Behaviour + checked against a fresh shader on renderer v2 + (`tests/webgl/shader-props.test.tsx`). **Kept.** +- **B18 fix rounds: base record, replay of the effective objects, targeted + fixes (`7044c7f`, `4229c56`, `18e3b93`, `b891864`, `baea932`, `51daf91`, + `9d5fffc`..`9ce36ee`, `f9aee19`..`e4ddeea`).** These change what a state undo + writes, not the hot path's shape. Each round re-ran the alloc check on arm C + (6x, 1 run), KiB per press, total (framework): + + | run | source | thumbnail-focus | navdrawer-toggle | + | ------------------ | --------- | --------------- | ---------------- | + | `bench-S-s1-final` | `d6d59af` | 10.95 (1.52) | 14.50 (7.29) | + | `bench-S-fix1` | `7044c7f` | n/a (1.51) | n/a (7.30) | + | `bench-S-fix2` | `4229c56` | 11.13 (1.52) | 14.53 (7.29) | + | `bench-S-fix3b` | `b891864` | 11.03 (1.51) | 14.65 (7.27) | + | `bench-S-r4` | `baea932` | 11.07 (1.53) | 14.65 (7.30) | + | `bench-S-r5` | `51daf91` | 10.97 (1.53) | 14.66 (7.28) | + | `bench-S-pb` | `9ce36ee` | 10.92 (1.53) | 14.70 (7.28) | + | `bench-S-pb2` | `e4ddeea` | 11.02 (1.52) | 14.67 (7.28) | + + Arm B in the `bench-S-r4` run: 12.41 and 22.19 total. Counts, re-checked in + the first three rounds, stayed at 8.2 and 1.0 shader writes and 0 and 23 node + writes per press. In every run no S + function is among the sampled sites; the framework bytes are stream F's. Three + times the check caught a terser closure in a single-use helper (fixed by + inlining it or making it a method), and the bundle was checked for a `try`: + - `18e3b93`: 64 B per thumbnail-focus press in the border accessor and 64 B + in `writeShaderValue` (three round-3 helpers; framework 1.64), gone in + `b891864` (1.51). + - `baea932`: a single-use `borderOrder` inlined as a function expression in + `writeShaderGroup`, 64 B per press (framework 1.59), fixed by reading the + cache inline. + - `9ce36ee`: the group write after a state change, left with one call site + by the `_applyStates` split (`66630bd`), was a function expression in + `_applyStates`' `finally` (1.59, navdrawer 7.30); as the method + `_writeShaderGroups` it is 1.53 and 7.28. + The grep for `(function(` and `!function(` misses the + `0 !== mask && function(...) {...}(this, mask)` form. + - The bundle's `_stateChanged` has no `try`: `66630bd` moved the + `try`/`finally` that keeps the group write after a throwing setter into + `_applyStates`, because `_stateChanged` runs for every element of every + focus change and Crankshaft (the Chrome 47 floor) does not optimise a + function with `try`/`finally`. + - **Kept** (correctness: the undo equals a never-focused node, each case + checked against the 1.6 export; the differences from 1.6 are listed in + `MIGRATION-1.7.md`, B18). + +## 2026-10-04: Checkpoint 2 series + +Branch `1.7` at `8886583`, renderer `6392ce4`. Time for A, B, C in one +interleaved series (3 runs, 6x); alloc and count for C (count for B re-run +alongside); profiles for C on four scenarios. Results: +`docs/perf/results/2026-10-04/summary.md`, demo `#/benchmark` (A 0.52 / B 0.57 +/ C 0.48 ms press mean) and `docs/perf/results/routes-2026-10-04.md`. The +per-scenario comparison against the design §6 targets, the allocation and +count tables, and the bundle sizes are in +`docs/superpowers/specs/2026-10-04-checkpoint-2-report.md`. + +## 2026-10-04: B18 removed (user decision) + +Branch `1.7-styles` at `837a6d9` (`249e4bc` the removal, `837a6d9` the +review's fix round 1), on `1.7` at `9b53edf`. Checkpoint 2 decided that B18 +(undoing a state's border or shadow should leave the node equal to a +never-focused one) goes back to 1.6.4 behaviour and is a known bug again; the +rest of stream S stays. Removed: the per-node base record and the group replay +(`ShaderBase`, `baseWrite`, `foldBase`, `replayGroup`, `writeShaderGroup`, the +`SHADER_BIT` masks, `_applyStates` with its try/finally, the per-type +`ShaderTypeInfo`). A border or shadow write merges its cached parse into the +shader props, the later write winning, and skips a sub-prop the props already +hold; a state undo writes the fallback object through the same setter, as 1.6 +did. "1.6.4 behaviour" is what 1.6.4 showed on renderer 1.9, so fix round 1 +restored two results the removal had lost: an animated `borderRadius` undo to +none animates to 0 (renderer 1.9 made a track for `undefined`, 2.0 makes +none), and a state change that writes some tracked border-family keys and +skips others as unchanged writes the family again in tracked order +(`_rewriteBorderKeys`, no allocation), so a state's own side survives another +state's `border` write as it did when 1.6 rewrote the whole merged object +(probes M1, ST2, PH). Only that overlap case pays; a single `$focus` border is +written once. + +- Alloc, framework B/op, Checkpoint 2 series → `bench-noB18-fix1` (one 6x + run; `bench-noB18`, before fix round 1, in parentheses): thumbnail-focus + 178 → 172 (171), navdrawer-toggle 1,504 → 1,493 (1,500), rows-lr-noshift + 260 → 260 (260), portal-focus-text 310 → 314 (303). Portal's 314 is sampling + noise on a scenario the change does not touch: three more runs + (`bench-noB18-fix1-alloc3`) gave 306, 304 and 337 (median 306) for portal + and 172, 174 and 172 for thumbnail-focus. The bundle's `_stateChanged`, + `_writeStates`, `_rewriteBorderKeys` and the shader accessor hold no + function expression (checked in `bench/dist/C/assets/framework.js`). +- Counts per press, unchanged but for the shader writes: navdrawer-toggle 23 + node writes and 1 shader write, portal-focus-text 6 and 0, rows-lr-noshift 2 + and 0; thumbnail-focus shader writes 6.0 → 5.2 (B 6.2): the `$focus` + border's `gap` stays 4 after blur (B18) and is not written again on the next + focus; `align` is (`'outside'` against the facade's resolved 1). +- Size: `elementNode.ts` minified+gzip 11,268 → 8,744 B (−2,524 B; both + sides from a copy of the file with `solid-1.7/node_modules/.bin/esbuild` + 0.27.7, as the Checkpoint 2 figure was; in place the same build is 8 B + larger); the bench framework chunk terser+mangled+gzip 22,106 → 19,802 B + (−2,304 B). Stream S's +3.9 kB becomes about +1.4 kB by the same measure. +- Verification: the 83 reviewer probes of the S rounds against the 1.6.4 + export: 78 equal; RS4 differs in floating point mid-animation only; PB2 (a + focus and a blur one frame apart under a transition) flips with timing on + both sides; W1 and W2 make fewer facade writes with the same result; PG + differs by design 3.3.2's diffed writes (a direct write to a key a state + names survives an unrelated state change), described in MIGRATION §2. The + reviewer's RAD probe (animated `borderRadius` undo) ends at `[0, 0, 0, 0]`, + as a never-focused node. `npx vitest run` 722 passed, 2 skipped (the B18 test + is `it.skip('BUG: B18 …')` again), `pnpm test:webgl` 63 passed, `pnpm tsc` + and `pnpm lint` clean. diff --git a/docs/perf/results/2026-10-03/profiles.md b/docs/perf/results/2026-10-03/profiles.md new file mode 100644 index 00000000..798135cc --- /dev/null +++ b/docs/perf/results/2026-10-03/profiles.md @@ -0,0 +1,397 @@ +# Profiles, 2026-10-03 (6x, arms A and B) + +CPU profiles over the measured ops (`node bench/run.mjs --modes profile +--profile-interval 25 --save-profiles`, one run per arm for most scenarios, +two for the Row scenarios), digested with +`node bench/harness/inclusive.mjs `. Rough guidance, not measurements to +compare at the noise floor: µs per op under the 6x throttle (so about 6x the +full-speed CPU), **inclusive** (a function's own time plus its callees'). +Rows nest: the Row/Column handler runs inside the dispatch walk, the state +styles inside the focus path, and `States ops` include the state-change +callback (`_stateChanged`) they trigger. Arm A's renderer frame is not +broken out (renderer 1.9's frame functions have other names). + +The idle maintenance after each press (renderer `gl.getError()`, off the +press path) is not in these rows: B spends 0.6-0.9 ms per op in it, A about +0.18 ms. + +```text + +## navdrawer-toggle A (1 run(s), µs per op) +key event (Solid listener) 151.9 + dispatch walk 66.0 +Row/Column navigation 6.3 +post-mutation pass 659.0 + focus path 566.3 +state styles 461.1 + States ops 557.6 +prop writes to the renderer 122.8 + animateProp 0.9 +shader prop writes 186.8 +reactivity (solid-js) 233.0 + draw 465.3 + +## navdrawer-toggle B (1 run(s), µs per op) +key event (Solid listener) 285.0 + dispatch walk 261.2 +Row/Column navigation 4.7 +post-mutation pass 579.3 + focus path 494.2 +state styles 298.3 + States ops 433.0 +prop writes to the renderer 69.5 + animateProp 46.5 +shader prop writes 133.8 +reactivity (solid-js) 385.1 +renderer frame 1068.8 + scene walk 226.9 + draw 580.2 + +## portal-focus-text A (1 run(s), µs per op) +key event (Solid listener) 150.4 + dispatch walk 121.3 +Row/Column navigation 69.9 +post-mutation pass 286.6 + focus path 256.9 +state styles 46.3 + States ops 181.5 +prop writes to the renderer 64.7 + animateProp 29.5 +shader prop writes 66.2 +reactivity (solid-js) 275.0 + draw 298.3 + +## portal-focus-text B (1 run(s), µs per op) +key event (Solid listener) 321.8 + dispatch walk 254.5 +Row/Column navigation 190.1 +post-mutation pass 380.0 + focus path 323.0 +state styles 117.8 + States ops 261.7 +prop writes to the renderer 118.5 + animateProp 38.4 +shader prop writes 152.3 +reactivity (solid-js) 418.9 +renderer frame 1298.2 + scene walk 451.7 + draw 481.7 + +## poster-swap A (1 run(s), µs per op) +post-mutation pass 177.3 + flex layout 57.2 +prop writes to the renderer 35.1 +shader prop writes 142.0 +Solid setProp/spread 187.9 +node creation 853.0 + renderer createNode 446.0 +reactivity (solid-js) 1276.9 + draw 131.0 + +## poster-swap B (1 run(s), µs per op) +post-mutation pass 143.7 + flex layout 38.0 +prop writes to the renderer 24.8 +shader prop writes 53.9 +Solid setProp/spread 173.5 +node creation 247.6 + renderer createNode 80.2 +reactivity (solid-js) 797.0 +renderer frame 318.6 + scene walk 187.4 + draw 90.8 + +## rows-lr-auto A (2 run(s), µs per op) +key event (Solid listener) 145.1 + dispatch walk 127.7 +Row/Column navigation 62.8 +post-mutation pass 175.3 + focus path 161.4 +state styles 34.4 + States ops 144.4 +prop writes to the renderer 33.5 + animateProp 8.4 +shader prop writes 35.4 +reactivity (solid-js) 189.6 + draw 58.6 + +## rows-lr-auto B (1 run(s), µs per op) +key event (Solid listener) 313.4 + dispatch walk 243.5 +Row/Column navigation 126.2 +post-mutation pass 230.7 + focus path 200.3 +state styles 61.0 + States ops 162.4 +prop writes to the renderer 62.1 + animateProp 35.0 +shader prop writes 79.9 +reactivity (solid-js) 364.1 +renderer frame 1169.6 + scene walk 192.9 + draw 387.7 + +## rows-lr-noshift A (2 run(s), µs per op) +key event (Solid listener) 96.6 + dispatch walk 70.1 +Row/Column navigation 44.9 +post-mutation pass 104.4 + focus path 66.8 +state styles 13.3 + States ops 71.6 +prop writes to the renderer 8.9 +shader prop writes 8.9 +reactivity (solid-js) 128.4 + draw 7.4 + +## rows-lr-noshift B (2 run(s), µs per op) +key event (Solid listener) 67.6 + dispatch walk 51.3 +Row/Column navigation 22.7 +post-mutation pass 86.4 + focus path 66.9 +state styles 9.8 + States ops 65.6 +prop writes to the renderer 1.9 +shader prop writes 2.6 +reactivity (solid-js) 76.8 +renderer frame 66.5 + scene walk 20.9 + draw 19.9 + +## rows-ud-auto A (1 run(s), µs per op) +key event (Solid listener) 276.1 + dispatch walk 250.9 +Row/Column navigation 150.3 +post-mutation pass 228.2 + focus path 169.8 +state styles 16.0 + States ops 175.5 +prop writes to the renderer 48.6 + animateProp 33.8 +shader prop writes 48.9 +reactivity (solid-js) 344.3 + draw 116.2 + +## rows-ud-auto B (1 run(s), µs per op) +key event (Solid listener) 323.3 + dispatch walk 302.9 +Row/Column navigation 188.3 +post-mutation pass 271.9 + focus path 213.8 +state styles 56.1 + States ops 204.0 +prop writes to the renderer 124.3 + animateProp 82.3 +shader prop writes 133.8 +reactivity (solid-js) 379.8 +renderer frame 1476.4 + scene walk 325.1 + draw 616.2 + +## text-details-panel A (1 run(s), µs per op) +key event (Solid listener) 171.8 + dispatch walk 138.0 +Row/Column navigation 65.2 +post-mutation pass 239.0 + flex layout 113.8 + focus path 196.5 +state styles 102.9 + States ops 193.6 +prop writes to the renderer 83.9 +shader prop writes 117.1 +node creation 33.1 +reactivity (solid-js) 258.0 + draw 75.4 + +## text-details-panel B (1 run(s), µs per op) +key event (Solid listener) 145.9 + dispatch walk 128.5 +Row/Column navigation 109.1 +post-mutation pass 261.7 + flex layout 140.6 + focus path 209.7 +state styles 43.9 + States ops 189.3 +prop writes to the renderer 34.7 +shader prop writes 132.7 +node creation 31.6 +reactivity (solid-js) 379.4 +renderer frame 513.7 + scene walk 136.2 + draw 217.3 + +## text-flex-mount-new A (1 run(s), µs per op) +post-mutation pass 320.9 + flex layout 436.4 +prop writes to the renderer 68.3 +shader prop writes 71.4 +Solid setProp/spread 1.2 +node creation 923.9 + renderer createNode 488.4 +reactivity (solid-js) 1647.1 + draw 123.8 + +## text-flex-mount-new B (1 run(s), µs per op) +post-mutation pass 235.9 + flex layout 480.4 +prop writes to the renderer 121.9 +shader prop writes 167.1 +Solid setProp/spread 18.7 +node creation 534.1 + renderer createNode 199.4 +reactivity (solid-js) 1343.0 +renderer frame 1424.1 + scene walk 703.7 + draw 586.0 + +## text-virtual-row A (1 run(s), µs per op) +key event (Solid listener) 195.0 + dispatch walk 134.4 +Row/Column navigation 84.9 +post-mutation pass 405.2 + flex layout 206.1 + focus path 231.0 +state styles 22.6 + States ops 190.3 +prop writes to the renderer 4.3 +shader prop writes 23.1 +node creation 20.6 +reactivity (solid-js) 387.0 + draw 265.7 + +## text-virtual-row B (1 run(s), µs per op) +key event (Solid listener) 371.8 + dispatch walk 347.0 +Row/Column navigation 258.9 +post-mutation pass 323.5 + flex layout 192.2 + focus path 191.9 +state styles 48.4 + States ops 167.1 +prop writes to the renderer 70.8 +shader prop writes 90.5 +node creation 24.2 +reactivity (solid-js) 532.4 +renderer frame 966.7 + scene walk 285.4 + draw 378.2 + +## thumbnail-focus A (1 run(s), µs per op) +key event (Solid listener) 201.5 + dispatch walk 180.8 +Row/Column navigation 28.2 +post-mutation pass 358.7 + focus path 330.3 +state styles 232.5 + States ops 342.5 +prop writes to the renderer 36.8 + animateProp 25.9 +shader prop writes 153.7 +reactivity (solid-js) 248.8 + draw 590.2 + +## thumbnail-focus B (1 run(s), µs per op) +key event (Solid listener) 186.6 + dispatch walk 162.4 +Row/Column navigation 84.5 +post-mutation pass 434.7 + focus path 346.8 +state styles 190.0 + States ops 359.7 +prop writes to the renderer 43.6 + animateProp 11.0 +shader prop writes 139.7 +reactivity (solid-js) 292.1 +renderer frame 1450.6 + scene walk 214.7 + draw 736.8 + +## virtual-grid A (1 run(s), µs per op) +key event (Solid listener) 323.9 + dispatch walk 314.3 +post-mutation pass 600.0 + flex layout 346.0 + focus path 335.8 +state styles 178.4 + States ops 315.7 +prop writes to the renderer 116.0 + animateProp 23.0 +shader prop writes 263.6 +Solid setProp/spread 4.5 +node creation 79.9 + renderer createNode 42.2 +reactivity (solid-js) 749.3 + draw 604.0 + +## virtual-grid B (1 run(s), µs per op) +key event (Solid listener) 386.3 + dispatch walk 355.3 +post-mutation pass 461.4 + flex layout 312.7 + focus path 219.2 +state styles 149.2 + States ops 202.3 +prop writes to the renderer 201.4 + animateProp 37.0 +shader prop writes 318.2 +Solid setProp/spread 1.6 +node creation 102.2 + renderer createNode 12.0 +reactivity (solid-js) 743.5 +renderer frame 1116.2 + scene walk 336.5 + draw 523.5 + +## virtual-row A (1 run(s), µs per op) +key event (Solid listener) 356.3 + dispatch walk 308.9 +Row/Column navigation 218.4 +post-mutation pass 254.8 + flex layout 142.2 + focus path 139.9 +state styles 60.3 + States ops 125.5 +prop writes to the renderer 63.5 + animateProp 2.7 +shader prop writes 64.4 +Solid setProp/spread 51.2 +node creation 22.8 +reactivity (solid-js) 583.2 + draw 204.8 + +## virtual-row B (1 run(s), µs per op) +key event (Solid listener) 451.3 + dispatch walk 417.0 +Row/Column navigation 287.5 +post-mutation pass 344.5 + flex layout 104.8 + focus path 220.9 +state styles 89.8 + States ops 220.6 +prop writes to the renderer 77.7 + animateProp 41.4 +shader prop writes 80.0 +Solid setProp/spread 14.9 +node creation 21.5 +reactivity (solid-js) 568.0 +renderer frame 784.2 + scene walk 128.9 + draw 288.5 +``` + +## Terser inlining in the renderer's walk + +The demo app's production build (terser, `compress` on, `mangle` off) turns +renderer v2's single-use world-transform helper into an IIFE inside +`ScenePass.visit` (`!function(s, id, parent){…}(s, id, parent)`), which +allocates on every dirty node visited, every frame. The bench mirrors that +build. Arm B rebuilt with `BENCH_TERSER_COMPRESS='{"reduce_funcs":false}'` +(the IIFE is gone from `visit`), alloc mode, one run: + +| scenario | renderer KiB/op, demo settings | `reduce_funcs: false` | framework KiB/op (both) | +| -------------------- | ------------------------------ | --------------------- | ----------------------- | +| rows-ud-auto | 56.7 | 3.4 | 2.4 / 2.1 | +| virtual-grid | 67.7 | 8.6 | 12.5 / 11.0 | +| thumbnail-focus | 8.6 | 4.0 | 2.9 / 2.7 | +| text-flex-mount-same | 49.6 | 21.0 | 54.7 / 54.7 | diff --git a/docs/perf/results/2026-10-03/summary.md b/docs/perf/results/2026-10-03/summary.md new file mode 100644 index 00000000..d4eaabf2 --- /dev/null +++ b/docs/perf/results/2026-10-03/summary.md @@ -0,0 +1,1178 @@ +# Benchmark summary + +Generated by `node bench/run.mjs` from the 302 result files in this directory. Methodology: [docs/perf/README.md](../../README.md). + +- CPU throttling: 6x +- GPU: ANGLE (Apple, ANGLE Metal Renderer: Apple M4 Pro, Unspecified Version) +- Flex: new (src/core/flexLayout.ts) +- Chromium: 141.0.7390.37 +- crossOriginIsolated: true; clock resolution 5.0 µs at worst +- 1-minute load average at run start: 0.8–13.8 + +Each cell is the median over runs of the per-run value, with the min–max over runs in parentheses. Times are ms of wall clock under CPU throttling. The per-run value of a time is its **mean over ops**: the throttler is a duty cycle (at 6x about 0.17 ms running, 0.85 ms suspended), so a sub-millisecond interval reads either unthrottled or one suspension longer, and only the mean estimates rate × CPU (see the README). + +## Time per op (ms, per-run mean over ops) + +`total` = handler + tail + frame (keydown to the end of the frame that shows it); `cpu` adds every later frame until idle; `p95 total` is the per-run 95th percentile. + +| scenario | arm | handler | tail | frame | total | p95 total | cpu | drawn frames | settle | runs | +| -------------------- | ----------- | ---------------------- | ------------------- | ------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------- | ------------------- | ---- | +| navdrawer-toggle | A | 0.078 (0.070–0.092) | 0.361 (0.297–0.366) | 0.171 (0.090–0.176) | 0.602 (0.479–0.619) | 1.540 (1.035–1.575) | 1.372 (1.233–1.390) | 16.1 (16.0–16.1) | 261.9 (260.8–262.6) | 3 | +| navdrawer-toggle | B | 0.119 (0.080–0.140) | 0.515 (0.376–0.555) | 0.123 (0.099–0.142) | 0.757 (0.616–0.778) | 1.600 (1.545–1.730) | 1.226 (1.077–1.255) | 15.5 (15.5–15.6) | 248.7 (248.7–249.9) | 3 | +| navdrawer-toggle | C | 0.098 (0.053–0.122) | 0.474 (0.275–0.608) | 0.088 (0.056–0.135) | 0.731 (0.385–0.794) | 1.595 (1.020–1.645) | 1.276 (0.618–1.314) | 15.5 (15.5–15.6) | 248.6 (248.2–250.2) | 3 | +| page-mount | A | 5.668 (5.658–5.799) | 1.020 (0.982–1.309) | 0.908 (0.887–0.968) | 7.688 (7.657–7.854) | 16.240 (15.945–16.655) | 8.969 (8.780–9.627) | 6.8 (6.8–6.8) | 110.6 (108.7–112.9) | 3 | +| page-mount | A [create] | 11.192 (11.114–11.493) | 1.543 (1.384–1.609) | 1.776 (1.746–1.912) | 14.547 (14.410–14.811) | 16.240 (15.945–16.655) | 16.828 (16.827–17.440) | 12.6 (12.6–12.7) | 204.7 (202.4–206.0) | 3 | +| page-mount | A [destroy] | 0.123 (0.105–0.222) | 0.656 (0.421–1.010) | 0.028 (0.025–0.039) | 0.904 (0.565–1.161) | 1.670 (1.135–1.735) | 1.109 (0.734–1.814) | 1.0 (1.0–1.0) | 15.2 (15.0–21.0) | 3 | +| page-mount | B | 4.466 (3.953–4.739) | 0.892 (0.783–1.090) | 0.827 (0.827–0.924) | 6.077 (5.768–6.656) | 12.430 (11.390–14.340) | 7.247 (6.257–7.549) | 6.8 (6.7–6.8) | 102.5 (102.2–102.8) | 3 | +| page-mount | B [create] | 8.549 (7.769–9.044) | 1.098 (0.990–1.459) | 1.631 (1.617–1.827) | 11.264 (10.586–12.133) | 12.430 (11.390–14.340) | 13.604 (11.564–13.920) | 12.5 (12.4–12.5) | 198.3 (198.0–199.8) | 3 | +| page-mount | B [destroy] | 0.384 (0.136–0.434) | 0.722 (0.468–0.794) | 0.024 (0.020–0.038) | 0.951 (0.891–1.179) | 1.755 (1.710–2.120) | 0.951 (0.891–1.179) | 1.0 (1.0–1.0) | 6.3 (5.9–6.6) | 3 | +| page-mount | C | 5.013 (4.339–5.269) | 1.014 (0.769–1.050) | 0.850 (0.609–1.116) | 7.143 (5.717–7.169) | 15.995 (11.560–16.310) | 7.844 (6.944–8.008) | 6.8 (6.8–6.8) | 103.3 (103.1–103.3) | 3 | +| page-mount | C [create] | 9.855 (8.220–10.057) | 1.214 (1.005–1.324) | 1.651 (1.189–2.204) | 12.922 (10.733–13.064) | 15.995 (11.560–16.310) | 14.273 (13.187–14.793) | 12.6 (12.5–12.6) | 199.9 (199.2–200.3) | 3 | +| page-mount | C [destroy] | 0.458 (0.171–0.482) | 0.885 (0.213–1.024) | 0.029 (0.027–0.048) | 1.222 (0.701–1.415) | 1.785 (1.560–2.210) | 1.222 (0.701–1.415) | 1.0 (1.0–1.0) | 6.7 (6.3–6.9) | 3 | +| page-swap | A | 11.319 (10.758–11.509) | 1.835 (1.807–1.976) | 1.400 (1.303–1.518) | 14.644 (13.897–14.885) | 18.495 (15.625–28.140) | 16.343 (15.642–16.624) | 12.6 (12.4–12.8) | 205.6 (204.7–206.8) | 3 | +| page-swap | B | 9.238 (9.218–10.102) | 1.702 (1.610–1.779) | 1.300 (0.985–1.382) | 12.322 (11.813–13.181) | 15.180 (13.545–15.820) | 13.772 (13.127–14.820) | 12.6 (12.4–12.7) | 200.3 (197.9–201.5) | 3 | +| page-swap | C | 9.255 (8.415–9.813) | 1.766 (1.735–1.979) | 1.080 (0.920–1.188) | 12.209 (11.230–12.711) | 14.120 (12.835–15.090) | 13.829 (12.774–13.942) | 12.6 (12.4–12.6) | 199.6 (197.9–200.3) | 3 | +| portal-focus-text | A | 0.053 (0.048–0.069) | 0.097 (0.066–0.099) | 0.042 (0.032–0.062) | 0.186 (0.150–0.231) | 0.595 (0.585–1.020) | 0.772 (0.684–0.948) | 15.0 (15.0–15.0) | 243.8 (243.2–243.9) | 3 | +| portal-focus-text | B | 0.105 (0.089–0.129) | 0.133 (0.103–0.165) | 0.022 (0.019–0.028) | 0.260 (0.211–0.322) | 0.765 (0.725–0.860) | 0.661 (0.650–0.673) | 15.5 (15.3–15.5) | 248.0 (245.8–248.2) | 3 | +| portal-focus-text | C | 0.078 (0.076–0.102) | 0.159 (0.128–0.167) | 0.019 (0.016–0.041) | 0.262 (0.252–0.271) | 0.820 (0.780–1.000) | 0.611 (0.544–0.623) | 15.6 (15.4–15.6) | 249.6 (246.3–250.1) | 3 | +| poster-mount | A | 0.248 (0.221–0.267) | 0.059 (0.024–0.072) | 0.088 (0.069–0.093) | 0.395 (0.315–0.432) | 1.470 (1.095–1.555) | 0.511 (0.463–0.627) | 1.5 (1.5–1.5) | 22.0 (20.7–23.2) | 3 | +| poster-mount | B | 0.151 (0.145–0.181) | 0.062 (0.061–0.064) | 0.070 (0.053–0.072) | 0.286 (0.261–0.314) | 1.160 (1.070–1.195) | 0.286 (0.261–0.314) | 1.0 (1.0–1.0) | 7.5 (7.4–7.6) | 3 | +| poster-mount | C | 0.194 (0.183–0.221) | 0.060 (0.056–0.080) | 0.080 (0.067–0.092) | 0.348 (0.332–0.354) | 1.315 (1.195–1.385) | 0.348 (0.332–0.354) | 1.0 (1.0–1.0) | 7.3 (7.3–7.4) | 3 | +| poster-swap | A | 0.324 (0.306–0.464) | 0.220 (0.058–0.228) | 0.090 (0.070–0.110) | 0.632 (0.597–0.642) | 1.480 (1.375–1.675) | 0.807 (0.751–0.819) | 2.0 (2.0–2.0) | 27.7 (27.6–30.1) | 3 | +| poster-swap | B | 0.353 (0.311–0.364) | 0.076 (0.072–0.100) | 0.077 (0.063–0.102) | 0.503 (0.503–0.512) | 1.080 (0.950–1.260) | 0.503 (0.503–0.512) | 1.0 (1.0–1.0) | 7.6 (7.5–7.6) | 3 | +| poster-swap | C | 0.295 (0.188–0.374) | 0.045 (0.015–0.063) | 0.067 (0.057–0.096) | 0.454 (0.260–0.486) | 1.055 (0.905–1.355) | 0.454 (0.260–0.486) | 1.0 (1.0–1.0) | 7.4 (7.4–7.6) | 3 | +| rows-lr-always | A | 0.037 (0.035–0.041) | 0.055 (0.055–0.065) | 0.011 (0.010–0.042) | 0.110 (0.103–0.137) | 0.440 (0.435–0.455) | 0.374 (0.360–0.462) | 11.1 (11.1–11.2) | 180.4 (180.1–180.4) | 3 | +| rows-lr-always | B | 0.074 (0.060–0.085) | 0.083 (0.075–0.104) | 0.019 (0.011–0.039) | 0.182 (0.171–0.196) | 0.695 (0.620–0.805) | 0.333 (0.284–0.358) | 11.0 (11.0–11.0) | 173.5 (173.5–173.6) | 3 | +| rows-lr-always | C | 0.117 (0.059–0.118) | 0.090 (0.071–0.117) | 0.014 (0.014–0.014) | 0.203 (0.162–0.249) | 0.740 (0.640–0.860) | 0.405 (0.289–0.413) | 11.0 (11.0–11.0) | 173.5 (173.4–173.7) | 3 | +| rows-lr-auto | A | 0.054 (0.050–0.061) | 0.085 (0.055–0.102) | 0.017 (0.014–0.019) | 0.162 (0.118–0.175) | 0.630 (0.450–0.720) | 0.499 (0.445–0.518) | 11.2 (11.2–11.2) | 181.7 (180.1–181.9) | 3 | +| rows-lr-auto | B | 0.087 (0.063–0.147) | 0.084 (0.074–0.117) | 0.023 (0.014–0.033) | 0.203 (0.185–0.254) | 0.730 (0.655–1.030) | 0.338 (0.317–0.435) | 11.0 (11.0–11.0) | 173.5 (173.4–173.5) | 3 | +| rows-lr-auto | C | 0.091 (0.047–0.182) | 0.107 (0.085–0.128) | 0.015 (0.009–0.017) | 0.191 (0.164–0.327) | 0.745 (0.635–1.360) | 0.416 (0.282–0.527) | 11.0 (11.0–11.0) | 173.6 (173.5–173.7) | 3 | +| rows-lr-noshift | A | 0.039 (0.012–0.063) | 0.060 (0.055–0.078) | 0.033 (0.019–0.075) | 0.127 (0.091–0.216) | 0.555 (0.310–0.700) | 0.320 (0.206–0.364) | 1.0 (1.0–1.0) | 14.0 (12.9–15.5) | 3 | +| rows-lr-noshift | B | 0.066 (0.023–0.086) | 0.081 (0.054–0.082) | 0.018 (0.013–0.043) | 0.186 (0.090–0.191) | 0.770 (0.450–0.930) | 0.186 (0.090–0.191) | 1.0 (1.0–1.0) | 6.9 (6.8–7.0) | 3 | +| rows-lr-noshift | C | 0.062 (0.058–0.064) | 0.080 (0.068–0.111) | 0.042 (0.024–0.056) | 0.198 (0.168–0.200) | 0.725 (0.720–0.830) | 0.198 (0.168–0.200) | 1.0 (1.0–1.0) | 6.9 (6.8–6.9) | 3 | +| rows-ud-always | A | 0.046 (0.038–0.048) | 0.075 (0.071–0.079) | 0.031 (0.018–0.035) | 0.144 (0.144–0.154) | 0.580 (0.485–0.605) | 0.626 (0.601–0.659) | 18.6 (18.5–18.7) | 303.9 (302.7–304.7) | 3 | +| rows-ud-always | B | 0.137 (0.086–0.247) | 0.149 (0.065–0.201) | 0.025 (0.015–0.025) | 0.301 (0.175–0.473) | 0.880 (0.620–1.170) | 0.651 (0.428–0.896) | 18.6 (18.4–18.6) | 299.8 (297.4–301.0) | 3 | +| rows-ud-always | C | 0.115 (0.092–0.189) | 0.157 (0.126–0.173) | 0.027 (0.016–0.055) | 0.288 (0.245–0.417) | 0.810 (0.800–1.090) | 0.587 (0.569–0.766) | 18.4 (18.4–18.5) | 297.3 (297.2–298.4) | 3 | +| rows-ud-auto | A | 0.050 (0.037–0.058) | 0.093 (0.076–0.094) | 0.021 (0.018–0.042) | 0.168 (0.147–0.172) | 0.595 (0.490–0.610) | 0.649 (0.579–0.677) | 14.6 (14.6–14.7) | 240.0 (238.8–240.7) | 3 | +| rows-ud-auto | B | 0.093 (0.089–0.128) | 0.112 (0.101–0.134) | 0.015 (0.014–0.015) | 0.241 (0.214–0.243) | 0.795 (0.775–0.800) | 0.476 (0.470–0.560) | 14.7 (14.6–14.7) | 234.9 (234.0–235.4) | 3 | +| rows-ud-auto | C | 0.085 (0.083–0.117) | 0.101 (0.101–0.115) | 0.014 (0.012–0.015) | 0.215 (0.197–0.230) | 0.740 (0.620–0.820) | 0.468 (0.451–0.554) | 14.6 (14.6–14.6) | 233.4 (233.2–234.3) | 3 | +| text-details-panel | A | 0.044 (0.039–0.050) | 0.044 (0.025–0.062) | 0.193 (0.174–0.209) | 0.293 (0.243–0.303) | 0.895 (0.790–0.960) | 0.407 (0.399–0.430) | 1.0 (1.0–1.0) | 14.2 (13.4–16.5) | 3 | +| text-details-panel | B | 0.059 (0.058–0.085) | 0.036 (0.033–0.044) | 0.131 (0.116–0.136) | 0.228 (0.210–0.261) | 0.880 (0.680–0.945) | 0.228 (0.210–0.261) | 1.0 (1.0–1.0) | 6.9 (6.9–6.9) | 3 | +| text-details-panel | C | 0.057 (0.038–0.059) | 0.047 (0.045–0.089) | 0.161 (0.129–0.190) | 0.273 (0.233–0.309) | 0.855 (0.655–1.035) | 0.273 (0.233–0.309) | 1.0 (1.0–1.0) | 6.9 (6.8–7.1) | 3 | +| text-flex-mount-new | A | 0.676 (0.593–0.766) | 0.188 (0.126–0.216) | 0.429 (0.397–0.458) | 1.289 (1.239–1.322) | 2.305 (2.200–2.550) | 1.461 (1.381–1.478) | 1.0 (1.0–1.0) | 15.0 (14.5–16.7) | 3 | +| text-flex-mount-new | B | 0.535 (0.489–0.610) | 0.124 (0.072–0.256) | 0.486 (0.283–0.601) | 1.231 (0.890–1.335) | 2.490 (2.030–2.635) | 1.231 (0.890–1.335) | 1.0 (1.0–1.0) | 7.6 (7.6–7.7) | 3 | +| text-flex-mount-new | C | 0.512 (0.487–0.638) | 0.193 (0.161–0.202) | 0.598 (0.553–0.661) | 1.341 (1.268–1.398) | 2.525 (2.485–2.690) | 1.341 (1.268–1.398) | 1.0 (1.0–1.0) | 7.6 (7.5–7.6) | 3 | +| text-flex-mount-same | A | 0.721 (0.459–0.742) | 0.161 (0.123–0.292) | 0.211 (0.205–0.212) | 1.115 (0.786–1.224) | 2.010 (1.595–2.065) | 1.235 (0.900–1.336) | 1.0 (1.0–1.0) | 14.9 (14.6–15.8) | 3 | +| text-flex-mount-same | B | 0.576 (0.545–0.591) | 0.240 (0.145–0.251) | 0.198 (0.192–0.286) | 1.041 (0.914–1.071) | 1.835 (1.615–2.045) | 1.041 (0.914–1.071) | 1.0 (1.0–1.0) | 7.4 (7.4–7.6) | 3 | +| text-flex-mount-same | C | 0.631 (0.621–0.765) | 0.198 (0.165–0.233) | 0.250 (0.149–0.264) | 1.082 (1.079–1.115) | 1.955 (1.840–2.065) | 1.082 (1.079–1.115) | 1.0 (1.0–1.0) | 7.5 (7.5–7.5) | 3 | +| text-virtual-row | A | 0.190 (0.158–0.206) | 0.277 (0.197–0.318) | 0.147 (0.075–0.178) | 0.655 (0.429–0.662) | 1.355 (1.180–1.500) | 1.529 (0.923–1.531) | 15.6 (15.5–15.6) | 253.0 (249.2–254.8) | 3 | +| text-virtual-row | B | 0.428 (0.152–0.461) | 0.414 (0.262–0.520) | 0.132 (0.088–0.218) | 1.007 (0.502–1.165) | 1.745 (1.195–2.140) | 1.424 (0.771–1.643) | 15.4 (15.3–15.6) | 247.3 (245.5–250.0) | 3 | +| text-virtual-row | C | 0.344 (0.339–0.404) | 0.363 (0.336–0.513) | 0.134 (0.132–0.143) | 0.874 (0.835–0.999) | 2.015 (1.655–2.445) | 1.531 (1.341–1.551) | 15.5 (15.4–15.5) | 248.3 (247.1–248.5) | 3 | +| thumbnail-focus | A | 0.044 (0.030–0.058) | 0.150 (0.116–0.181) | 0.071 (0.067–0.118) | 0.247 (0.231–0.356) | 0.730 (0.725–0.935) | 0.679 (0.617–1.055) | 15.6 (15.6–15.6) | 253.0 (252.4–253.1) | 3 | +| thumbnail-focus | B | 0.088 (0.062–0.104) | 0.263 (0.207–0.303) | 0.057 (0.034–0.070) | 0.399 (0.352–0.437) | 1.100 (1.065–1.305) | 0.669 (0.562–0.705) | 15.6 (15.4–15.6) | 250.4 (247.7–250.4) | 3 | +| thumbnail-focus | C | 0.081 (0.064–0.130) | 0.242 (0.240–0.282) | 0.041 (0.029–0.044) | 0.403 (0.333–0.416) | 1.110 (0.925–1.160) | 0.594 (0.587–0.801) | 15.5 (15.3–15.5) | 248.3 (245.7–249.3) | 3 | +| virtual-grid | A | 0.404 (0.396–0.452) | 0.805 (0.745–0.864) | 0.108 (0.092–0.115) | 1.317 (1.288–1.375) | 1.970 (1.685–2.135) | 2.030 (1.971–2.399) | 15.4 (15.4–15.5) | 250.8 (250.4–252.1) | 3 | +| virtual-grid | B | 0.540 (0.491–0.549) | 0.800 (0.709–0.859) | 0.150 (0.122–0.175) | 1.424 (1.412–1.559) | 2.385 (1.960–2.395) | 1.961 (1.809–2.217) | 15.5 (15.4–15.5) | 247.7 (247.0–248.7) | 3 | +| virtual-grid | C | 0.539 (0.485–0.635) | 0.661 (0.630–0.740) | 0.147 (0.137–0.154) | 1.362 (1.354–1.413) | 2.125 (2.040–2.440) | 1.910 (1.845–1.951) | 15.5 (15.5–15.6) | 249.2 (248.5–250.0) | 3 | +| virtual-row | A | 0.170 (0.159–0.308) | 0.272 (0.243–0.363) | 0.046 (0.039–0.062) | 0.494 (0.452–0.717) | 1.225 (1.025–1.295) | 0.886 (0.797–1.399) | 15.7 (15.5–15.7) | 253.4 (253.4–253.4) | 3 | +| virtual-row | B | 0.445 (0.319–0.483) | 0.471 (0.367–0.477) | 0.061 (0.060–0.064) | 0.910 (0.857–0.979) | 1.610 (1.560–1.710) | 1.305 (1.268–1.504) | 15.4 (15.4–15.5) | 247.4 (246.5–248.5) | 3 | +| virtual-row | C | 0.347 (0.311–0.429) | 0.292 (0.276–0.469) | 0.048 (0.022–0.052) | 0.671 (0.625–0.950) | 1.370 (1.325–1.950) | 0.983 (0.881–1.521) | 15.3 (15.3–15.5) | 245.8 (245.5–247.9) | 3 | + +## Ratios (medians over runs) + +A/B: shipping 1.6.4 on renderer 1.9.3 over the lockstep port on renderer v2. B/C: the same code today, so B/C is the in-session noise floor. + +| scenario | A/B total | B/C total | A/B handler | B/C handler | A/B frame | B/C frame | A/B bytes/op | B/C bytes/op | A/B writes/op | B/C writes/op | +| -------------------- | --------- | --------- | ----------- | ----------- | --------- | --------- | ------------ | ------------ | ------------- | ------------- | +| navdrawer-toggle | 0.79 | 1.04 | 0.65 | 1.21 | 1.39 | 1.40 | 2.20 | 0.77 | 1.00 | 1.00 | +| page-mount | 1.27 | 0.85 | 1.27 | 0.89 | 1.10 | 0.97 | 2.89 | 1.00 | 0.99 | 1.00 | +| page-swap | 1.19 | 1.01 | 1.23 | 1.00 | 1.08 | 1.20 | 2.75 | 1.00 | 0.99 | 1.00 | +| portal-focus-text | 0.72 | 0.99 | 0.50 | 1.35 | 1.90 | 1.17 | 3.07 | 0.93 | 1.00 | 1.00 | +| poster-mount | 1.38 | 0.82 | 1.64 | 0.78 | 1.25 | 0.87 | 2.41 | 1.00 | 1.00 | 1.00 | +| poster-swap | 1.26 | 1.11 | 0.92 | 1.20 | 1.16 | 1.15 | 2.77 | 1.00 | 1.00 | 1.00 | +| rows-lr-always | 0.60 | 0.90 | 0.50 | 0.63 | 0.61 | 1.35 | 1.00 | 1.00 | 1.00 | 1.00 | +| rows-lr-auto | 0.80 | 1.06 | 0.62 | 0.96 | 0.74 | 1.55 | 1.01 | 1.00 | 1.00 | 1.00 | +| rows-lr-noshift | 0.68 | 0.94 | 0.59 | 1.07 | 1.84 | 0.42 | 1.47 | 1.00 | 1.00 | 1.00 | +| rows-ud-always | 0.48 | 1.05 | 0.34 | 1.19 | 1.27 | 0.91 | 0.78 | 1.00 | 1.00 | 1.00 | +| rows-ud-auto | 0.70 | 1.12 | 0.54 | 1.08 | 1.43 | 1.06 | 0.77 | 1.00 | 1.00 | 1.00 | +| text-details-panel | 1.29 | 0.84 | 0.75 | 1.03 | 1.47 | 0.82 | 1.28 | 1.00 | 1.01 | 1.00 | +| text-flex-mount-new | 1.05 | 0.92 | 1.26 | 1.04 | 0.88 | 0.81 | 0.96 | 1.00 | 0.67 | 1.00 | +| text-flex-mount-same | 1.07 | 0.96 | 1.25 | 0.91 | 1.07 | 0.79 | 1.48 | 1.00 | 0.67 | 1.00 | +| text-virtual-row | 0.65 | 1.15 | 0.44 | 1.24 | 1.11 | 0.99 | 1.79 | 1.01 | 1.00 | 1.00 | +| thumbnail-focus | 0.62 | 0.99 | 0.50 | 1.09 | 1.24 | 1.40 | 1.43 | 1.00 | n/a | n/a | +| virtual-grid | 0.92 | 1.05 | 0.75 | 1.00 | 0.72 | 1.02 | 0.56 | 2.27 | 1.00 | 1.00 | +| virtual-row | 0.54 | 1.36 | 0.38 | 1.28 | 0.76 | 1.27 | 1.22 | 1.00 | 1.00 | 1.00 | + +## Allocation per op (KiB, sampling heap profiler, collected objects included) + +`total` is the app: framework + reactivity + renderer + user. `harness` (the op loop) and `no script` (allocations with no script frame on the stack, mostly Blink objects such as the harness's own MessageEvents) are shown beside it, not in it. + +| scenario | arm | total | framework | reactivity | renderer | user | harness | no script | runs | +| -------------------- | --- | ------- | --------- | ---------- | -------- | ------ | ------- | --------- | ---- | +| navdrawer-toggle | A | 48.86 | 15.28 | 0.84 | 32.67 | 0.06 | 0.00 | 14.10 | 1 | +| navdrawer-toggle | B | 22.24 | 15.30 | 0.84 | 6.03 | 0.07 | 0.00 | 12.77 | 1 | +| navdrawer-toggle | C | 28.97 | 15.33 | 0.84 | 12.73 | 0.07 | 0.00 | 12.75 | 1 | +| page-mount | A | 959.51 | 110.37 | 66.19 | 721.10 | 61.85 | 0.00 | 9.68 | 1 | +| page-mount | B | 332.47 | 109.17 | 66.53 | 94.93 | 61.82 | 0.00 | 10.33 | 1 | +| page-mount | C | 332.48 | 108.78 | 66.04 | 95.84 | 61.82 | 0.00 | 10.26 | 1 | +| page-swap | A | 1892.99 | 222.42 | 131.23 | 1417.82 | 121.53 | 0.00 | 9.94 | 1 | +| page-swap | B | 688.38 | 207.82 | 131.41 | 227.70 | 121.44 | 0.00 | 10.17 | 1 | +| page-swap | C | 689.89 | 207.82 | 131.54 | 229.10 | 121.43 | 0.00 | 10.16 | 1 | +| portal-focus-text | A | 74.53 | 1.89 | 1.75 | 70.87 | 0.02 | 0.00 | 14.56 | 1 | +| portal-focus-text | B | 24.31 | 1.91 | 1.75 | 20.64 | 0.02 | 0.00 | 12.42 | 1 | +| portal-focus-text | C | 26.04 | 1.92 | 1.74 | 22.36 | 0.02 | 0.00 | 12.43 | 1 | +| poster-mount | A | 67.40 | 7.94 | 3.87 | 54.94 | 0.65 | 0.00 | 9.33 | 1 | +| poster-mount | B | 28.02 | 7.99 | 3.87 | 15.51 | 0.65 | 0.00 | 9.00 | 1 | +| poster-mount | C | 28.10 | 8.00 | 3.87 | 15.58 | 0.65 | 0.00 | 8.94 | 1 | +| poster-swap | A | 125.53 | 13.43 | 7.53 | 101.35 | 3.22 | 0.00 | 9.46 | 1 | +| poster-swap | B | 45.35 | 13.47 | 7.53 | 21.14 | 3.21 | 0.00 | 8.96 | 1 | +| poster-swap | C | 45.36 | 13.49 | 7.53 | 21.13 | 3.21 | 0.00 | 8.95 | 1 | +| rows-lr-always | A | 13.28 | 1.86 | 0.82 | 10.59 | 0.02 | 0.00 | 13.30 | 1 | +| rows-lr-always | B | 13.24 | 1.86 | 0.82 | 10.55 | 0.02 | 0.00 | 12.21 | 1 | +| rows-lr-always | C | 13.19 | 1.86 | 0.82 | 10.49 | 0.02 | 0.00 | 12.26 | 1 | +| rows-lr-auto | A | 13.27 | 1.86 | 0.82 | 10.58 | 0.02 | 0.00 | 13.35 | 1 | +| rows-lr-auto | B | 13.19 | 1.86 | 0.82 | 10.50 | 0.02 | 0.00 | 12.25 | 1 | +| rows-lr-auto | C | 13.17 | 1.85 | 0.82 | 10.48 | 0.02 | 0.00 | 12.27 | 1 | +| rows-lr-noshift | A | 5.06 | 1.80 | 0.81 | 2.43 | 0.01 | 0.00 | 10.94 | 1 | +| rows-lr-noshift | B | 3.45 | 1.80 | 0.82 | 0.81 | 0.01 | 0.00 | 10.43 | 1 | +| rows-lr-noshift | C | 3.45 | 1.81 | 0.81 | 0.82 | 0.01 | 0.00 | 10.42 | 1 | +| rows-ud-always | A | 54.32 | 2.41 | 0.81 | 51.08 | 0.02 | 0.00 | 13.92 | 1 | +| rows-ud-always | B | 69.37 | 2.40 | 0.81 | 66.13 | 0.02 | 0.00 | 12.34 | 1 | +| rows-ud-always | C | 69.39 | 2.41 | 0.81 | 66.15 | 0.02 | 0.00 | 12.30 | 1 | +| rows-ud-auto | A | 46.44 | 2.40 | 0.81 | 43.21 | 0.02 | 0.00 | 13.72 | 1 | +| rows-ud-auto | B | 59.93 | 2.39 | 0.81 | 56.71 | 0.02 | 0.00 | 12.23 | 1 | +| rows-ud-auto | C | 60.10 | 2.39 | 0.81 | 56.88 | 0.02 | 0.00 | 12.25 | 1 | +| text-details-panel | A | 28.03 | 11.93 | 2.05 | 14.05 | 0.00 | 0.00 | 10.79 | 1 | +| text-details-panel | B | 21.94 | 12.06 | 2.05 | 7.83 | 0.00 | 0.00 | 10.28 | 1 | +| text-details-panel | C | 21.99 | 12.05 | 2.06 | 7.87 | 0.00 | 0.00 | 10.26 | 1 | +| text-flex-mount-new | A | 232.20 | 44.53 | 17.95 | 155.20 | 14.52 | 0.00 | 9.03 | 1 | +| text-flex-mount-new | B | 240.89 | 54.69 | 17.90 | 153.79 | 14.52 | 0.00 | 9.03 | 1 | +| text-flex-mount-new | C | 240.89 | 54.70 | 17.91 | 153.76 | 14.52 | 0.00 | 9.03 | 1 | +| text-flex-mount-same | A | 202.44 | 44.59 | 17.85 | 125.48 | 14.52 | 0.00 | 9.06 | 1 | +| text-flex-mount-same | B | 136.75 | 54.69 | 17.91 | 49.63 | 14.52 | 0.00 | 9.06 | 1 | +| text-flex-mount-same | C | 136.46 | 54.73 | 17.87 | 49.34 | 14.52 | 0.00 | 9.31 | 1 | +| text-virtual-row | A | 69.57 | 9.92 | 2.88 | 56.77 | 0.00 | 0.00 | 13.99 | 1 | +| text-virtual-row | B | 38.97 | 10.03 | 2.88 | 26.06 | 0.00 | 0.00 | 12.18 | 1 | +| text-virtual-row | C | 38.75 | 9.91 | 2.88 | 25.95 | 0.00 | 0.00 | 12.22 | 1 | +| thumbnail-focus | A | 17.69 | 2.90 | 0.82 | 13.96 | 0.01 | 0.00 | 13.13 | 1 | +| thumbnail-focus | B | 12.34 | 2.89 | 0.82 | 8.62 | 0.01 | 0.00 | 11.88 | 1 | +| thumbnail-focus | C | 12.39 | 2.89 | 0.82 | 8.67 | 0.01 | 0.00 | 11.88 | 1 | +| virtual-grid | A | 47.92 | 11.36 | 5.66 | 30.64 | 0.26 | 0.00 | 13.97 | 1 | +| virtual-grid | B | 86.13 | 12.55 | 5.66 | 67.66 | 0.26 | 0.00 | 12.05 | 1 | +| virtual-grid | C | 37.94 | 11.14 | 5.67 | 20.86 | 0.26 | 0.00 | 12.49 | 1 | +| virtual-row | A | 26.40 | 8.34 | 2.76 | 15.27 | 0.03 | 0.00 | 13.34 | 1 | +| virtual-row | B | 21.71 | 8.37 | 2.75 | 10.56 | 0.02 | 0.00 | 12.17 | 1 | +| virtual-row | C | 21.64 | 8.36 | 2.75 | 10.51 | 0.02 | 0.00 | 12.20 | 1 | + +Top allocating functions (bytes per op, mean over runs; harness excluded): + +- navdrawer-toggle A: `renderQuads (renderer:2424)` 8060, `finalizeSdfBatch (renderer:4857)` 5890, `createValueKey (renderer:1988)` 5361, `_stateChanged (framework:831)` 4005, `States (framework:137)` 3801 +- navdrawer-toggle B: `_stateChanged (framework:825)` 3997, `States (framework:131)` 3808, `merge (framework:148)` 3512, `(anonymous) (framework:833)` 1271, `_super (framework:132)` 1153 +- navdrawer-toggle C: `(anonymous) (renderer:1826)` 7661, `_stateChanged (framework:825)` 4004, `States (framework:131)` 3805, `merge (framework:148)` 3514, `(anonymous) (framework:833)` 1270 +- page-mount A: `defineProps (renderer:1967)` 202202, `CoreNode (renderer:467)` 136682, `resolveNodeDefaults (renderer:2963)` 125712, `PageTile (user:415)` 54040, `resolveTextNodeDefaults (renderer:2931)` 43050 +- page-mount B: `PageTile (user:415)` 54040, `createComputation (reactivity:199)` 21812, `ElementNode (framework:531)` 20952, `createTextNode (renderer:4235)` 20664, `insertChild (framework:613)` 17464 +- page-mount C: `PageTile (user:415)` 54040, `createComputation (reactivity:199)` 21812, `ElementNode (framework:531)` 21114, `createTextNode (renderer:4235)` 20664, `insertChild (framework:613)` 17464 +- page-swap A: `defineProps (renderer:1967)` 405745, `CoreNode (renderer:467)` 274805, `resolveNodeDefaults (renderer:2963)` 251424, `PageTile (user:415)` 108080, `CoreTextNode (renderer:2343)` 75768 +- page-swap B: `PageTile (user:415)` 108016, `(anonymous) (renderer:1826)` 52544, `createComputation (reactivity:199)` 43665, `ElementNode (framework:531)` 41937, `createTextNode (renderer:4235)` 41328 +- page-swap C: `PageTile (user:415)` 108016, `(anonymous) (renderer:1826)` 52347, `createComputation (reactivity:199)` 43925, `ElementNode (framework:531)` 41906, `createTextNode (renderer:4235)` 41529 +- portal-focus-text A: `renderQuads (renderer:2424)` 29944, `buildRenderList (renderer:2884)` 15434, `renderQuads (renderer:5084)` 7242, `updateGlobalGeometry (renderer:676)` 6849, `update (renderer:576)` 4268 +- portal-focus-text B: `visit (renderer:1810)` 11866, `write (renderer:1035)` 2961, `(anonymous) (renderer:1826)` 2340, `mergeColorProgress (renderer:753)` 991, `tick (renderer:4742)` 744 +- portal-focus-text C: `visit (renderer:1810)` 11872, `(anonymous) (renderer:1826)` 4052, `write (renderer:1035)` 2937, `mergeColorProgress (renderer:753)` 980, `tick (renderer:4742)` 728 +- poster-mount A: `defineProps (renderer:1967)` 14440, `createValueKey (renderer:1988)` 6361, `CoreNode (renderer:467)` 4483, `resolveNodeDefaults (renderer:2963)` 3987, `(anonymous) (renderer:5055)` 2200 +- poster-mount B: `(anonymous) (renderer:3801)` 2300, `propsKey (renderer:3115)` 1800, `createElement (framework:1030)` 1392, `calculateFlex (framework:322)` 1189, `createComputation (reactivity:199)` 1160 +- poster-mount C: `(anonymous) (renderer:3801)` 2309, `propsKey (renderer:3115)` 1800, `createElement (framework:1030)` 1360, `calculateFlex (framework:322)` 1189, `createComputation (reactivity:199)` 1160 +- poster-swap A: `defineProps (renderer:1967)` 28901, `createValueKey (renderer:1988)` 12710, `CoreNode (renderer:467)` 9400, `resolveNodeDefaults (renderer:2963)` 8044, `(anonymous) (renderer:5055)` 4400 +- poster-swap B: `(anonymous) (renderer:3801)` 4520, `propsKey (renderer:3115)` 3607, `Poster$1 (user:438)` 3208, `calculateFlex (framework:322)` 2375, `createComputation (reactivity:199)` 2240 +- poster-swap C: `(anonymous) (renderer:3801)` 4520, `propsKey (renderer:3115)` 3629, `Poster$1 (user:438)` 3203, `calculateFlex (framework:322)` 2377, `createComputation (reactivity:199)` 2240 +- rows-lr-always A: `update (renderer:576)` 2589, `updateGlobalGeometry (renderer:676)` 2582, `updateFrameTime (renderer:2706)` 1014, `(anonymous) (renderer:3054)` 936, `newRenderOp (renderer:4809)` 854 +- rows-lr-always B: `visit (renderer:1810)` 7392, `tick (renderer:4742)` 899, `FrameLoop.request (renderer:4722)` 404, `runUpdates (reactivity:262)` 360, `ease (renderer:1005)` 256 +- rows-lr-always C: `visit (renderer:1810)` 7392, `tick (renderer:4742)` 898, `FrameLoop.request (renderer:4722)` 402, `runUpdates (reactivity:262)` 360, `ease (renderer:1005)` 256 +- rows-lr-auto A: `update (renderer:576)` 2606, `updateGlobalGeometry (renderer:676)` 2596, `updateFrameTime (renderer:2706)` 992, `(anonymous) (renderer:3054)` 910, `newRenderOp (renderer:4809)` 859 +- rows-lr-auto B: `visit (renderer:1810)` 7392, `tick (renderer:4742)` 898, `FrameLoop.request (renderer:4722)` 402, `runUpdates (reactivity:262)` 361, `ease (renderer:1005)` 256 +- rows-lr-auto C: `visit (renderer:1810)` 7392, `tick (renderer:4742)` 898, `FrameLoop.request (renderer:4722)` 402, `runUpdates (reactivity:262)` 360, `ease (renderer:1005)` 256 +- rows-lr-noshift A: `updateFrameTime (renderer:2706)` 806, `(anonymous) (renderer:3054)` 682, `runUpdates (reactivity:262)` 356, `_stateChanged (framework:831)` 232, `propagateKeyPress (framework:225)` 220 +- rows-lr-noshift B: `runUpdates (reactivity:262)` 356, `_stateChanged (framework:825)` 232, `propagateKeyPress (framework:219)` 220, `keyIdentities (framework:271)` 200, `States (framework:131)` 200 +- rows-lr-noshift C: `runUpdates (reactivity:262)` 356, `_stateChanged (framework:825)` 237, `propagateKeyPress (framework:219)` 220, `keyIdentities (framework:271)` 200, `States (framework:131)` 200 +- rows-ud-always A: `updateGlobalGeometry (renderer:676)` 22128, `update (renderer:576)` 22116, `(anonymous) (renderer:3054)` 1948, `newRenderOp (renderer:4809)` 1405, `updateFrameTime (renderer:2706)` 1134 +- rows-ud-always B: `visit (renderer:1810)` 61391, `(anonymous) (renderer:1826)` 2666, `tick (renderer:4742)` 983, `FrameLoop.request (renderer:4722)` 729, `States (framework:131)` 400 +- rows-ud-always C: `visit (renderer:1810)` 61198, `(anonymous) (renderer:1826)` 2835, `tick (renderer:4742)` 977, `FrameLoop.request (renderer:4722)` 722, `States (framework:131)` 400 +- rows-ud-auto A: `updateGlobalGeometry (renderer:676)` 18519, `update (renderer:576)` 18511, `(anonymous) (renderer:3054)` 1799, `newRenderOp (renderer:4809)` 1103, `updateFrameTime (renderer:2706)` 1064 +- rows-ud-auto B: `visit (renderer:1810)` 51943, `(anonymous) (renderer:1826)` 2696, `tick (renderer:4742)` 935, `FrameLoop.request (renderer:4722)` 585, `States (framework:131)` 403 +- rows-ud-auto C: `visit (renderer:1810)` 52112, `(anonymous) (renderer:1826)` 2710, `tick (renderer:4742)` 937, `FrameLoop.request (renderer:4722)` 572, `States (framework:131)` 403 +- text-details-panel A: `calculateFlex (framework:328)` 9749, `(anonymous) (renderer:5055)` 3084, `renderText (renderer:5050)` 1659, `renderQuads (renderer:5084)` 1581, `renderQuads (renderer:2424)` 1026 +- text-details-panel B: `calculateFlex (framework:322)` 9714, `(anonymous) (renderer:3801)` 3202, `layoutText (renderer:3791)` 1053, `get (renderer:3772)` 775, `get w (renderer:1562)` 504 +- text-details-panel C: `calculateFlex (framework:322)` 9725, `(anonymous) (renderer:3801)` 3202, `layoutText (renderer:3791)` 1055, `get (renderer:3772)` 780, `get w (renderer:1562)` 504 +- text-flex-mount-new A: `CoreNode (renderer:467)` 38065, `resolveNodeDefaults (renderer:2963)` 33719, `calculateFlex (framework:328)` 18526, `TextTile (user:941)` 14320, `generateTextLayout (renderer:4983)` 13066 +- text-flex-mount-new B: `(anonymous) (renderer:3805)` 88479, `calculateFlex (framework:322)` 28886, `(anonymous) (renderer:1826)` 23652, `TextTile (user:941)` 14320, `(anonymous) (renderer:3801)` 8960 +- text-flex-mount-new C: `(anonymous) (renderer:3805)` 88576, `calculateFlex (framework:322)` 28905, `(anonymous) (renderer:1826)` 23652, `TextTile (user:941)` 14320, `(anonymous) (renderer:3801)` 8960 +- text-flex-mount-same A: `CoreNode (renderer:467)` 38059, `resolveNodeDefaults (renderer:2963)` 33696, `calculateFlex (framework:328)` 18524, `TextTile (user:941)` 14320, `resolveTextNodeDefaults (renderer:2931)` 12000 +- text-flex-mount-same B: `calculateFlex (framework:322)` 28898, `(anonymous) (renderer:1826)` 23652, `TextTile (user:941)` 14320, `(anonymous) (renderer:3801)` 8960, `_layoutOnLoad (framework:697)` 6720 +- text-flex-mount-same C: `calculateFlex (framework:322)` 28897, `(anonymous) (renderer:1826)` 23652, `TextTile (user:941)` 14320, `(anonymous) (renderer:3801)` 8960, `_layoutOnLoad (framework:697)` 6720 +- text-virtual-row A: `renderQuads (renderer:2424)` 23411, `updateGlobalGeometry (renderer:676)` 6689, `renderQuads (renderer:5084)` 6618, `update (renderer:576)` 6472, `calculateFlex (framework:328)` 6360 +- text-virtual-row B: `visit (renderer:1810)` 18502, `calculateFlex (framework:322)` 6445, `(anonymous) (renderer:1826)` 3394, `(anonymous) (framework:1333)` 967, `(anonymous) (renderer:3801)` 860 +- text-virtual-row C: `visit (renderer:1810)` 18364, `calculateFlex (framework:322)` 6323, `(anonymous) (renderer:1826)` 3415, `(anonymous) (framework:1333)` 964, `(anonymous) (renderer:3801)` 859 +- thumbnail-focus A: `createValueKey (renderer:1988)` 2849, `updateLocalTransform (renderer:539)` 1820, `(anonymous) (renderer:3054)` 1494, `multiply (renderer:215)` 1456, `newRenderOp (renderer:4809)` 1191 +- thumbnail-focus B: `(anonymous) (renderer:1826)` 3689, `visit (renderer:1810)` 993, `propsKey (renderer:3115)` 766, `tick (renderer:4742)` 741, `uploadSystem (renderer:2737)` 721 +- thumbnail-focus C: `(anonymous) (renderer:1826)` 3747, `visit (renderer:1810)` 995, `propsKey (renderer:3115)` 760, `tick (renderer:4742)` 739, `uploadSystem (renderer:2737)` 722 +- virtual-grid A: `createValueKey (renderer:1988)` 3918, `addQuad (renderer:4791)` 3012, `(anonymous) (framework:1332)` 2798, `defineProps (renderer:1967)` 2553, `updateGlobalGeometry (renderer:676)` 2265 +- virtual-grid B: `(anonymous) (renderer:1826)` 53498, `visit (renderer:1810)` 6169, `(anonymous) (framework:1333)` 2942, `calculateFlex (framework:322)` 2258, `ease (renderer:1005)` 1807 +- virtual-grid C: `visit (renderer:1810)` 6252, `(anonymous) (renderer:1826)` 5746, `(anonymous) (framework:1333)` 2794, `calculateFlex (framework:322)` 2259, `ease (renderer:1005)` 1807 +- virtual-row A: `calculateFlex (framework:328)` 4724, `updateGlobalGeometry (renderer:676)` 2448, `update (renderer:576)` 1815, `updateLocalTransform (renderer:539)` 1350, `multiply (renderer:215)` 1314 +- virtual-row B: `visit (renderer:1810)` 5965, `calculateFlex (framework:322)` 4728, `(anonymous) (framework:1333)` 1013, `tick (renderer:4742)` 893, `Animation (renderer:855)` 754 +- virtual-row C: `visit (renderer:1810)` 5939, `calculateFlex (framework:322)` 4736, `(anonymous) (framework:1333)` 1019, `tick (renderer:4742)` 885, `Animation (renderer:855)` 748 + +## Counts per op (instrumented build; its timings are not reported) + +`node writes` and `shader writes` are setter calls on renderer nodes and on shader `props` made by app code (Solid and the scenario). A write made while renderer code is on the stack (a renderer frame, `createNode`/`createTextNode`/`createShader`/`animate`, another setter, a texture's event dispatch) is not counted; the app's listeners that the renderer calls (`loaded`, `idle`) are app code. `in frames`: the part of those writes made during a renderer frame (Solid's flex on `loaded`). Creation is counted on its own, the same way on both majors: `created` nodes and their `creation props` (keys with a defined value in the bag passed to `createNode`/`createTextNode`; renderer v2 applies the bag through its setters, v1 in its constructor). `loaded`: emitted / heard by a listener (v1 emits on every text layout and texture load, v2 queues one only for a node with a listener). + +| scenario | arm | flex passes | node writes | shader writes | in frames | animations | walks/drawn frame | drawn frames | created | creation props | loaded text (emitted / heard) | loaded other (emitted / heard) | runs | +| -------------------- | ----------- | ----------- | ----------- | ------------- | --------- | ---------- | ----------------- | ------------ | ------- | -------------- | ----------------------------- | ------------------------------ | ---- | +| navdrawer-toggle | A | 0.0 | 25.0 | 0.0 | 0.0 | 2.0 | 1.00 | 16.1 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| navdrawer-toggle | B | 0.0 | 25.0 | 2.0 | 0.0 | 2.0 | 1.00 | 15.5 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| navdrawer-toggle | C | 0.0 | 25.0 | 2.0 | 0.0 | 2.0 | 1.00 | 15.5 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| page-mount | A | 4.0 | 77.5 | 0.0 | 0.0 | 1.0 | 2.80 | 0.5 | 291.0 | 2946.5 | 1.5 / 0.0 | 70.0 / 0.0 | 1 | +| page-mount | A [create] | 8.0 | 155.0 | 0.0 | 0.0 | 2.0 | n/a | 0.0 | 582.0 | 5893.0 | 3.0 / 0.0 | 140.0 / 0.0 | 1 | +| page-mount | A [destroy] | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| page-mount | B | 4.0 | 78.0 | 2.0 | 0.0 | 1.0 | 1.00 | 6.8 | 291.0 | 2946.5 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| page-mount | B [create] | 8.0 | 156.0 | 4.0 | 0.0 | 2.0 | 1.00 | 12.5 | 582.0 | 5893.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| page-mount | B [destroy] | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| page-mount | C | 4.0 | 78.0 | 2.0 | 0.0 | 1.0 | 1.00 | 6.8 | 291.0 | 2946.5 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| page-mount | C [create] | 8.0 | 156.0 | 4.0 | 0.0 | 2.0 | 1.00 | 12.6 | 582.0 | 5893.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| page-mount | C [destroy] | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| page-swap | A | 8.0 | 155.0 | 0.0 | 0.0 | 2.0 | 1.00 | 12.4 | 582.0 | 5893.0 | 63.0 / 0.0 | 140.0 / 0.0 | 1 | +| page-swap | B | 8.0 | 156.0 | 4.0 | 0.0 | 2.0 | 1.00 | 12.7 | 582.0 | 5893.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| page-swap | C | 8.0 | 156.0 | 4.0 | 0.0 | 2.0 | 1.00 | 12.5 | 582.0 | 5893.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| portal-focus-text | A | 0.0 | 6.0 | 0.0 | 0.0 | 3.0 | 1.00 | 15.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| portal-focus-text | B | 0.0 | 6.0 | 0.0 | 0.0 | 3.0 | 1.00 | 15.5 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| portal-focus-text | C | 0.0 | 6.0 | 0.0 | 0.0 | 3.0 | 1.00 | 15.5 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| poster-mount | A | 0.5 | 5.0 | 0.0 | 0.0 | 0.0 | 1.17 | 1.5 | 10.0 | 115.0 | 0.0 / 0.0 | 5.0 / 0.0 | 1 | +| poster-mount | B | 0.5 | 5.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 10.0 | 115.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| poster-mount | C | 0.5 | 5.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 10.0 | 115.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| poster-swap | A | 1.0 | 10.0 | 0.0 | 0.0 | 0.0 | 1.00 | 2.0 | 20.0 | 230.0 | 10.0 / 0.0 | 10.0 / 0.0 | 1 | +| poster-swap | B | 1.0 | 10.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 20.0 | 230.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| poster-swap | C | 1.0 | 10.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 20.0 | 230.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-lr-always | A | 0.0 | 2.0 | 0.0 | 0.0 | 1.0 | 1.00 | 11.2 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-lr-always | B | 0.0 | 2.0 | 0.0 | 0.0 | 1.0 | 1.00 | 11.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-lr-always | C | 0.0 | 2.0 | 0.0 | 0.0 | 1.0 | 1.00 | 11.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-lr-auto | A | 0.0 | 2.0 | 0.0 | 0.0 | 1.0 | 1.00 | 11.3 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-lr-auto | B | 0.0 | 2.0 | 0.0 | 0.0 | 1.0 | 1.00 | 11.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-lr-auto | C | 0.0 | 2.0 | 0.0 | 0.0 | 1.0 | 1.00 | 11.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-lr-noshift | A | 0.0 | 2.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-lr-noshift | B | 0.0 | 2.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-lr-noshift | C | 0.0 | 2.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-ud-always | A | 0.0 | 2.0 | 0.0 | 0.0 | 1.0 | 1.00 | 18.6 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-ud-always | B | 0.0 | 2.0 | 0.0 | 0.0 | 1.0 | 1.00 | 18.6 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-ud-always | C | 0.0 | 2.0 | 0.0 | 0.0 | 1.0 | 1.00 | 18.7 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-ud-auto | A | 0.0 | 2.0 | 0.0 | 0.0 | 0.8 | 1.00 | 14.6 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-ud-auto | B | 0.0 | 2.0 | 0.0 | 0.0 | 0.8 | 1.00 | 14.6 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-ud-auto | C | 0.0 | 2.0 | 0.0 | 0.0 | 0.8 | 1.00 | 14.6 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| text-details-panel | A | 7.0 | 55.0 | 0.0 | 45.0 | 0.0 | 2.00 | 1.0 | 0.0 | 0.0 | 7.0 / 5.0 | 0.0 / 0.0 | 1 | +| text-details-panel | B | 7.0 | 54.4 | 0.0 | 44.4 | 0.0 | 2.00 | 1.0 | 0.0 | 0.0 | 5.0 / 5.0 | 0.0 / 0.0 | 1 | +| text-details-panel | C | 7.0 | 54.4 | 0.0 | 44.4 | 0.0 | 2.00 | 1.0 | 0.0 | 0.0 | 5.0 / 5.0 | 0.0 / 0.0 | 1 | +| text-flex-mount-new | A | 42.0 | 61.0 | 0.0 | 40.0 | 0.0 | 2.00 | 1.0 | 81.0 | 646.0 | 20.0 / 20.0 | 0.0 / 0.0 | 1 | +| text-flex-mount-new | B | 42.0 | 91.0 | 0.0 | 70.0 | 0.0 | 2.00 | 1.0 | 81.0 | 646.0 | 20.0 / 20.0 | 0.0 / 0.0 | 1 | +| text-flex-mount-new | C | 42.0 | 91.0 | 0.0 | 70.0 | 0.0 | 2.00 | 1.0 | 81.0 | 646.0 | 20.0 / 20.0 | 0.0 / 0.0 | 1 | +| text-flex-mount-same | A | 42.0 | 61.0 | 0.0 | 40.0 | 0.0 | 2.00 | 1.0 | 81.0 | 646.0 | 20.0 / 20.0 | 0.0 / 0.0 | 1 | +| text-flex-mount-same | B | 42.0 | 91.0 | 0.0 | 70.0 | 0.0 | 2.00 | 1.0 | 81.0 | 646.0 | 20.0 / 20.0 | 0.0 / 0.0 | 1 | +| text-flex-mount-same | C | 42.0 | 91.0 | 0.0 | 70.0 | 0.0 | 2.00 | 1.0 | 81.0 | 646.0 | 20.0 / 20.0 | 0.0 / 0.0 | 1 | +| text-virtual-row | A | 4.2 | 29.7 | 0.0 | 6.0 | 1.0 | 1.06 | 15.6 | 0.0 | 0.0 | 1.9 / 1.9 | 0.0 / 0.0 | 1 | +| text-virtual-row | B | 4.2 | 29.7 | 0.0 | 6.0 | 1.0 | 1.03 | 15.6 | 0.0 | 0.0 | 1.9 / 1.9 | 0.0 / 0.0 | 1 | +| text-virtual-row | C | 4.2 | 29.7 | 0.0 | 6.0 | 1.0 | 1.03 | 15.6 | 0.0 | 0.0 | 1.9 / 1.9 | 0.0 / 0.0 | 1 | +| thumbnail-focus | A | 0.0 | 0.0 | 0.0 | 0.0 | 2.0 | 1.00 | 15.6 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| thumbnail-focus | B | 0.0 | 0.0 | 6.2 | 0.0 | 2.0 | 1.00 | 15.4 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| thumbnail-focus | C | 0.0 | 0.0 | 6.2 | 0.0 | 2.0 | 1.00 | 15.5 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| virtual-grid | A | 2.0 | 179.0 | 0.0 | 0.0 | 2.3 | 1.00 | 15.6 | 0.9 | 8.8 | 0.0 / 0.0 | 6.0 / 0.0 | 1 | +| virtual-grid | B | 2.0 | 179.0 | 6.0 | 0.0 | 2.3 | 1.00 | 15.6 | 0.9 | 8.8 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| virtual-grid | C | 2.0 | 179.0 | 6.0 | 0.0 | 2.3 | 1.00 | 15.5 | 0.9 | 8.8 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| virtual-row | A | 1.9 | 26.1 | 0.0 | 0.0 | 3.0 | 1.00 | 15.6 | 0.0 | 0.0 | 0.0 / 0.0 | 0.9 / 0.0 | 1 | +| virtual-row | B | 1.9 | 26.1 | 0.0 | 0.0 | 3.0 | 1.00 | 15.5 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| virtual-row | C | 1.9 | 26.1 | 0.0 | 0.0 | 3.0 | 1.00 | 15.6 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | + +### Text metrics per op (count mode) + +| scenario | arm | text layout calls | text layout ms | layout cache hit rate | frames to final layout | ms to final layout | +| -------------------- | --- | ----------------- | -------------- | --------------------- | ---------------------- | ------------------ | +| page-mount | A | 1.5 | 0.005 | 1.00 | 0.0 | 26.7 | +| page-mount | B | 31.5 | 0.090 | 1.00 | 1.0 | 14.1 | +| page-mount | C | 31.5 | 0.291 | 1.00 | 1.0 | 15.6 | +| page-swap | A | 63.0 | 0.175 | 1.00 | 1.0 | 18.5 | +| page-swap | B | 63.0 | 0.178 | 1.00 | 1.0 | 16.2 | +| page-swap | C | 63.0 | 0.211 | 1.00 | 1.0 | 15.5 | +| text-details-panel | A | 7.0 | 0.033 | 1.00 | 1.0 | 16.7 | +| text-details-panel | B | 7.0 | 0.036 | 1.00 | 1.0 | 6.7 | +| text-details-panel | C | 7.0 | 0.030 | 1.00 | 1.0 | 6.8 | +| text-flex-mount-new | A | 20.0 | 0.277 | 0.00 | 1.0 | 17.5 | +| text-flex-mount-new | B | 20.0 | 0.378 | 0.00 | 1.0 | 7.5 | +| text-flex-mount-new | C | 20.0 | 0.229 | 0.00 | 1.0 | 7.4 | +| text-flex-mount-same | A | 20.0 | 0.024 | 1.00 | 1.0 | 17.1 | +| text-flex-mount-same | B | 20.0 | 0.023 | 1.00 | 1.0 | 7.3 | +| text-flex-mount-same | C | 20.0 | 0.055 | 1.00 | 1.0 | 7.2 | +| text-virtual-row | A | 1.9 | 0.005 | 1.00 | 1.0 | 16.3 | +| text-virtual-row | B | 1.9 | 0.011 | 1.00 | 1.0 | 6.1 | +| text-virtual-row | C | 1.9 | 0.014 | 1.00 | 1.0 | 6.7 | + +## Profile: self time per op (ms, mean over runs) + +### navdrawer-toggle A + +By chunk: (program) 3.992, renderer 1.663, harness 0.734, framework 0.546, (garbage collector) 0.357, native 0.129, reactivity 0.072, user 0.020 + +| # | function (chunk:line) | self ms/op | +| --- | -------------------------------------------- | ---------- | +| 1 | `(program)` | 3.992 | +| 2 | `(garbage collector)` | 0.357 | +| 3 | `getError [native] (renderer)` | 0.217 | +| 4 | `requestAnimationFrame [native] (harness)` | 0.173 | +| 5 | `_stateChanged (framework:831)` | 0.152 | +| 6 | `clear [native] (harness)` | 0.108 | +| 7 | `bindVertexArrayOES [native] (renderer)` | 0.108 | +| 8 | `wrapped (harness:76)` | 0.104 | +| 9 | `(anonymous) [native] (native)` | 0.102 | +| 10 | `bufferData [native] (renderer)` | 0.093 | +| 11 | `useProgram [native] (renderer)` | 0.077 | +| 12 | `drawElements [native] (renderer)` | 0.076 | +| 13 | `bindRenderOp (renderer:3760)` | 0.075 | +| 14 | `dispatchEvent [native] (harness)` | 0.073 | +| 15 | `remove (framework:162)` | 0.072 | +| 16 | `addQuad (renderer:4791)` | 0.071 | +| 17 | `setTimeout [native] (renderer)` | 0.070 | +| 18 | `bindTexture [native] (renderer)` | 0.068 | +| 19 | `setTimeout [native] (harness)` | 0.068 | +| 20 | `_sendToLightningAnimatable (framework:636)` | 0.068 | + +### navdrawer-toggle B + +By chunk: (program) 3.502, renderer 1.602, harness 0.649, framework 0.605, (garbage collector) 0.353, native 0.100, reactivity 0.035, user 0.004 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------- | ---------- | +| 1 | `(program)` | 3.502 | +| 2 | `getError [native] (renderer)` | 0.494 | +| 3 | `(garbage collector)` | 0.353 | +| 4 | `clear [native] (harness)` | 0.149 | +| 5 | `_stateChanged (framework:825)` | 0.140 | +| 6 | `requestAnimationFrame [native] (renderer)` | 0.119 | +| 7 | `bindVertexArrayOES [native] (renderer)` | 0.104 | +| 8 | `postMessage [native] (harness)` | 0.101 | +| 9 | `bindTexture [native] (renderer)` | 0.084 | +| 10 | `wrapped (harness:76)` | 0.080 | +| 11 | `visit (renderer:1810)` | 0.066 | +| 12 | `setTimeout [native] (renderer)` | 0.066 | +| 13 | `(anonymous) [native] (native)` | 0.063 | +| 14 | `keyEvent (harness:226)` | 0.058 | +| 15 | `merge (framework:148)` | 0.055 | +| 16 | `useProgram [native] (renderer)` | 0.053 | +| 17 | `remove (framework:156)` | 0.053 | +| 18 | `KeyboardEvent [native] (harness)` | 0.045 | +| 19 | `bufferData [native] (renderer)` | 0.044 | +| 20 | `drawElements [native] (renderer)` | 0.043 | + +### portal-focus-text A + +By chunk: (program) 4.326, renderer 2.265, harness 0.814, framework 0.390, (garbage collector) 0.360, native 0.134, reactivity 0.084, user 0.005 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------ | ---------- | +| 1 | `(program)` | 4.326 | +| 2 | `(garbage collector)` | 0.360 | +| 3 | `getError [native] (renderer)` | 0.237 | +| 4 | `requestAnimationFrame [native] (harness)` | 0.193 | +| 5 | `bufferData [native] (renderer)` | 0.189 | +| 6 | `addSdfCachedQuads (renderer:4851)` | 0.145 | +| 7 | `wrapped (harness:76)` | 0.141 | +| 8 | `renderQuads (renderer:5084)` | 0.113 | +| 9 | `(anonymous) [native] (native)` | 0.111 | +| 10 | `clear [native] (harness)` | 0.109 | +| 11 | `addQuad (renderer:4791)` | 0.084 | +| 12 | `renderQuads (renderer:2424)` | 0.082 | +| 13 | `remove (framework:162)` | 0.081 | +| 14 | `update (renderer:576)` | 0.080 | +| 15 | `setTimeout [native] (renderer)` | 0.076 | +| 16 | `(anonymous) (renderer:3054)` | 0.074 | +| 17 | `postMessage [native] (harness)` | 0.068 | +| 18 | `propagateKeyPress (framework:225)` | 0.059 | +| 19 | `drawElements [native] (renderer)` | 0.058 | +| 20 | `bindVertexArrayOES [native] (renderer)` | 0.056 | + +### portal-focus-text B + +By chunk: (program) 3.946, renderer 2.357, framework 0.408, harness 0.382, (garbage collector) 0.193, native 0.120, reactivity 0.050, user 0.005 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------- | ---------- | +| 1 | `(program)` | 3.946 | +| 2 | `getError [native] (renderer)` | 0.660 | +| 3 | `emitText (renderer:3973)` | 0.277 | +| 4 | `(garbage collector)` | 0.193 | +| 5 | `requestAnimationFrame [native] (renderer)` | 0.187 | +| 6 | `clear [native] (renderer)` | 0.176 | +| 7 | `bufferData [native] (renderer)` | 0.098 | +| 8 | `(anonymous) [native] (native)` | 0.091 | +| 9 | `visit (renderer:1810)` | 0.086 | +| 10 | `wrapped (harness:76)` | 0.085 | +| 11 | `remove (framework:156)` | 0.081 | +| 12 | `animateProp (renderer:1499)` | 0.065 | +| 13 | `drawElements [native] (renderer)` | 0.064 | +| 14 | `setTimeout [native] (renderer)` | 0.064 | +| 15 | `bindTexture [native] (renderer)` | 0.047 | +| 16 | `setTimeout [native] (harness)` | 0.044 | +| 17 | `disable [native] (renderer)` | 0.044 | +| 18 | `KeyboardEvent [native] (harness)` | 0.039 | +| 19 | `run (renderer:1775)` | 0.032 | +| 20 | `dispatch (renderer:5113)` | 0.031 | + +### poster-mount A + +By chunk: renderer 1.383, (program) 1.359, harness 0.384, framework 0.193, reactivity 0.170, native 0.120, (garbage collector) 0.079, user 0.024 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------ | ---------- | +| 1 | `(program)` | 1.359 | +| 2 | `getError [native] (renderer)` | 0.404 | +| 3 | `requestAnimationFrame [native] (harness)` | 0.082 | +| 4 | `(anonymous) (renderer:3054)` | 0.081 | +| 5 | `(garbage collector)` | 0.079 | +| 6 | `(anonymous) [native] (native)` | 0.067 | +| 7 | `requestLoop (renderer:3051)` | 0.057 | +| 8 | `(anonymous) (reactivity:482)` | 0.053 | +| 9 | `WebGlShaderNode (renderer:3527)` | 0.053 | +| 10 | `setTimeout [native] (renderer)` | 0.050 | +| 11 | `CoreNode (renderer:467)` | 0.047 | +| 12 | `wrapped (harness:76)` | 0.042 | +| 13 | `renderQuads (renderer:5084)` | 0.041 | +| 14 | `(anonymous) (harness:320)` | 0.040 | +| 15 | `(anonymous) (renderer:2015)` | 0.039 | +| 16 | `setTimeout [native] (harness)` | 0.036 | +| 17 | `clear [native] (harness)` | 0.036 | +| 18 | `calculateFlex (framework:328)` | 0.035 | +| 19 | `postMessage [native] (harness)` | 0.035 | +| 20 | `setProp (reactivity:665)` | 0.035 | + +### poster-mount B + +By chunk: renderer 1.500, (program) 0.781, framework 0.332, reactivity 0.277, harness 0.228, native 0.107, user 0.068, (garbage collector) 0.053 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------ | ---------- | +| 1 | `getError [native] (renderer)` | 0.882 | +| 2 | `(program)` | 0.781 | +| 3 | `(anonymous) [native] (native)` | 0.073 | +| 4 | `setProp (reactivity:665)` | 0.060 | +| 5 | `createTextNode (renderer:4235)` | 0.060 | +| 6 | `set style (framework:719)` | 0.056 | +| 7 | `(garbage collector)` | 0.053 | +| 8 | `runPostMutation (framework:480)` | 0.052 | +| 9 | `systemMask.perOp (renderer:2719)` | 0.052 | +| 10 | `visit (renderer:1810)` | 0.050 | +| 11 | `clear [native] (harness)` | 0.045 | +| 12 | `runQueue (reactivity:306)` | 0.042 | +| 13 | `render (framework:866)` | 0.040 | +| 14 | `requestAnimationFrame [native] (harness)` | 0.038 | +| 15 | `postMessage [native] (harness)` | 0.036 | +| 16 | `Poster$1 (user:438)` | 0.033 | +| 17 | `(anonymous) (framework:520)` | 0.033 | +| 18 | `setTimeout [native] (harness)` | 0.033 | +| 19 | `bindTexture [native] (renderer)` | 0.031 | +| 20 | `pack (renderer:2968)` | 0.027 | + +### poster-swap A + +By chunk: (program) 1.996, renderer 1.902, framework 0.546, harness 0.312, reactivity 0.226, (garbage collector) 0.199, native 0.108, user 0.002 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------ | ---------- | +| 1 | `(program)` | 1.996 | +| 2 | `getError [native] (renderer)` | 0.412 | +| 3 | `(garbage collector)` | 0.199 | +| 4 | `set style (framework:725)` | 0.166 | +| 5 | `(anonymous) [native] (native)` | 0.078 | +| 6 | `renderQuads (renderer:5084)` | 0.077 | +| 7 | `createShader (renderer:2010)` | 0.076 | +| 8 | `render (framework:872)` | 0.072 | +| 9 | `wrapped (harness:76)` | 0.070 | +| 10 | `defineProps (renderer:1967)` | 0.058 | +| 11 | `setTimeout [native] (harness)` | 0.058 | +| 12 | `(anonymous) (renderer:2015)` | 0.055 | +| 13 | `setTimeout [native] (renderer)` | 0.054 | +| 14 | `CoreNode (renderer:467)` | 0.053 | +| 15 | `bindBuffer [native] (renderer)` | 0.053 | +| 16 | `calculateFlex (framework:328)` | 0.048 | +| 17 | `destroy (renderer:712)` | 0.046 | +| 18 | `resolveNodeDefaults (renderer:2963)` | 0.045 | +| 19 | `createNode (renderer:2916)` | 0.044 | +| 20 | `requestAnimationFrame [native] (harness)` | 0.042 | + +### poster-swap B + +By chunk: renderer 1.382, (program) 1.032, framework 0.460, harness 0.287, reactivity 0.266, native 0.129, (garbage collector) 0.048, user 0.002 + +| # | function (chunk:line) | self ms/op | +| --- | -------------------------------------------- | ---------- | +| 1 | `(program)` | 1.032 | +| 2 | `getError [native] (renderer)` | 0.761 | +| 3 | `(anonymous) [native] (native)` | 0.087 | +| 4 | `set style (framework:719)` | 0.065 | +| 5 | `_sendToLightningAnimatable (framework:630)` | 0.059 | +| 6 | `parseAndAssignShaderProps (framework:512)` | 0.058 | +| 7 | `wrapped (harness:76)` | 0.057 | +| 8 | `untrack (reactivity:84)` | 0.052 | +| 9 | `(anonymous) (renderer:4086)` | 0.049 | +| 10 | `setProp (reactivity:665)` | 0.049 | +| 11 | `(garbage collector)` | 0.048 | +| 12 | `frame (renderer:5708)` | 0.048 | +| 13 | `postMessage [native] (harness)` | 0.043 | +| 14 | `requestAnimationFrame [native] (harness)` | 0.042 | +| 15 | `runPostMutation (framework:480)` | 0.040 | +| 16 | `insertExpression (reactivity:540)` | 0.039 | +| 17 | `(anonymous) (reactivity:482)` | 0.039 | +| 18 | `clear [native] (harness)` | 0.038 | +| 19 | `setProperty (framework:1037)` | 0.037 | +| 20 | `channel.port1.onmessage (harness:146)` | 0.036 | + +### rows-lr-always A + +By chunk: (program) 5.607, renderer 1.690, harness 1.224, framework 0.407, native 0.131, reactivity 0.064, (garbage collector) 0.026, user 0.002 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------ | ---------- | +| 1 | `(program)` | 5.607 | +| 2 | `getError [native] (renderer)` | 0.397 | +| 3 | `clear [native] (harness)` | 0.255 | +| 4 | `requestAnimationFrame [native] (harness)` | 0.238 | +| 5 | `setTimeout [native] (renderer)` | 0.185 | +| 6 | `(anonymous) (renderer:3054)` | 0.164 | +| 7 | `update (renderer:576)` | 0.126 | +| 8 | `(anonymous) [native] (native)` | 0.108 | +| 9 | `bufferData [native] (renderer)` | 0.108 | +| 10 | `postMessage [native] (harness)` | 0.102 | +| 11 | `addQuad (renderer:4791)` | 0.090 | +| 12 | `wrapped (harness:76)` | 0.083 | +| 13 | `setTimeout [native] (harness)` | 0.073 | +| 14 | `updateGlobalGeometry (renderer:676)` | 0.070 | +| 15 | `drawElements [native] (renderer)` | 0.069 | +| 16 | `keyEvent (harness:226)` | 0.069 | +| 17 | `dispatchEvent [native] (harness)` | 0.059 | +| 18 | `_stateChanged (framework:831)` | 0.053 | +| 19 | `settle (harness:172)` | 0.048 | +| 20 | `add (framework:148)` | 0.041 | + +### rows-lr-always B + +By chunk: (program) 5.222, renderer 1.971, harness 0.995, framework 0.405, native 0.130, reactivity 0.073, (garbage collector) 0.049 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------- | ---------- | +| 1 | `(program)` | 5.222 | +| 2 | `getError [native] (renderer)` | 0.803 | +| 3 | `clear [native] (harness)` | 0.294 | +| 4 | `requestAnimationFrame [native] (renderer)` | 0.144 | +| 5 | `postMessage [native] (harness)` | 0.143 | +| 6 | `setTimeout [native] (renderer)` | 0.133 | +| 7 | `bufferData [native] (renderer)` | 0.105 | +| 8 | `(anonymous) [native] (native)` | 0.089 | +| 9 | `wrapped (harness:76)` | 0.084 | +| 10 | `KeyboardEvent [native] (harness)` | 0.075 | +| 11 | `drawElements [native] (renderer)` | 0.074 | +| 12 | `keyEvent (harness:226)` | 0.070 | +| 13 | `run (renderer:1775)` | 0.062 | +| 14 | `setTimeout [native] (harness)` | 0.057 | +| 15 | `visit (renderer:1810)` | 0.055 | +| 16 | `emit (renderer:2013)` | 0.054 | +| 17 | `(garbage collector)` | 0.049 | +| 18 | `dispatchEvent [native] (harness)` | 0.047 | +| 19 | `propagateKeyPress (framework:219)` | 0.044 | +| 20 | `requestAnimationFrame [native] (harness)` | 0.042 | + +### rows-lr-auto A + +By chunk: (program) 5.548, renderer 1.492, harness 0.825, framework 0.474, native 0.170, (garbage collector) 0.050, reactivity 0.039 + +| # | function (chunk:line) | self ms/op | +| --- | -------------------------------------------- | ---------- | +| 1 | `(program)` | 5.548 | +| 2 | `getError [native] (renderer)` | 0.320 | +| 3 | `requestAnimationFrame [native] (renderer)` | 0.175 | +| 4 | `requestAnimationFrame [native] (harness)` | 0.170 | +| 5 | `setTimeout [native] (renderer)` | 0.145 | +| 6 | `bufferData [native] (renderer)` | 0.139 | +| 7 | `clear [native] (harness)` | 0.136 | +| 8 | `remove (framework:162)` | 0.112 | +| 9 | `wrapped (harness:76)` | 0.105 | +| 10 | `(anonymous) [native] (native)` | 0.097 | +| 11 | `postMessage [native] (harness)` | 0.090 | +| 12 | `(anonymous) (renderer:3054)` | 0.090 | +| 13 | `addQuad (renderer:4791)` | 0.077 | +| 14 | `propagateKeyPress (framework:225)` | 0.065 | +| 15 | `(garbage collector)` | 0.050 | +| 16 | `_sendToLightningAnimatable (framework:636)` | 0.049 | +| 17 | `keyEvent (harness:226)` | 0.049 | +| 18 | `render (renderer:4885)` | 0.048 | +| 19 | `update (renderer:576)` | 0.047 | +| 20 | `drawElements [native] (renderer)` | 0.047 | + +### rows-lr-auto B + +By chunk: (program) 5.085, renderer 2.355, harness 0.845, framework 0.455, native 0.154, reactivity 0.070, (garbage collector) 0.042, user 0.035 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------- | ---------- | +| 1 | `(program)` | 5.085 | +| 2 | `getError [native] (renderer)` | 0.883 | +| 3 | `clear [native] (harness)` | 0.262 | +| 4 | `bufferData [native] (renderer)` | 0.173 | +| 5 | `setTimeout [native] (renderer)` | 0.126 | +| 6 | `(anonymous) [native] (native)` | 0.118 | +| 7 | `requestAnimationFrame [native] (renderer)` | 0.115 | +| 8 | `postMessage [native] (harness)` | 0.098 | +| 9 | `run (renderer:1775)` | 0.094 | +| 10 | `dispatchEvent [native] (harness)` | 0.088 | +| 11 | `wrapped (harness:76)` | 0.083 | +| 12 | `(anonymous) (framework:231)` | 0.065 | +| 13 | `setTimeout [native] (harness)` | 0.065 | +| 14 | `tick (renderer:4742)` | 0.057 | +| 15 | `keyEvent (harness:226)` | 0.056 | +| 16 | `visit (renderer:1810)` | 0.054 | +| 17 | `setTimeout (renderer:3306)` | 0.051 | +| 18 | `draw (renderer:4609)` | 0.050 | +| 19 | `emit (renderer:2013)` | 0.044 | +| 20 | `findSuppression (framework:276)` | 0.044 | + +### rows-lr-noshift A + +By chunk: (program) 1.970, renderer 0.737, harness 0.521, framework 0.429, native 0.138, (garbage collector) 0.054, reactivity 0.040, user 0.001 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------ | ---------- | +| 1 | `(program)` | 1.970 | +| 2 | `getError [native] (renderer)` | 0.360 | +| 3 | `(anonymous) [native] (native)` | 0.101 | +| 4 | `setTimeout [native] (renderer)` | 0.086 | +| 5 | `(anonymous) (renderer:3054)` | 0.084 | +| 6 | `postMessage [native] (harness)` | 0.076 | +| 7 | `setTimeout [native] (harness)` | 0.074 | +| 8 | `States (framework:137)` | 0.064 | +| 9 | `requestAnimationFrame [native] (harness)` | 0.063 | +| 10 | `add (framework:148)` | 0.055 | +| 11 | `(garbage collector)` | 0.054 | +| 12 | `(anonymous) (framework:237)` | 0.045 | +| 13 | `propagateKeyPress (framework:225)` | 0.041 | +| 14 | `bufferData [native] (renderer)` | 0.040 | +| 15 | `has (framework:142)` | 0.031 | +| 16 | `dispatchEvent [native] (harness)` | 0.030 | +| 17 | `findSuppression (framework:282)` | 0.030 | +| 18 | `readSignal (reactivity:133)` | 0.026 | +| 19 | `wrapped (harness:76)` | 0.026 | +| 20 | `remove (framework:162)` | 0.026 | + +### rows-lr-noshift B + +By chunk: renderer 1.015, (program) 0.927, harness 0.453, framework 0.425, native 0.115, (garbage collector) 0.033, reactivity 0.014 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------ | ---------- | +| 1 | `(program)` | 0.927 | +| 2 | `getError [native] (renderer)` | 0.782 | +| 3 | `postMessage [native] (harness)` | 0.124 | +| 4 | `(anonymous) [native] (native)` | 0.069 | +| 5 | `dispatchEvent [native] (harness)` | 0.067 | +| 6 | `remove (framework:156)` | 0.060 | +| 7 | `propagateKeyPress (framework:219)` | 0.058 | +| 8 | `KeyboardEvent [native] (harness)` | 0.056 | +| 9 | `keyEvent (harness:226)` | 0.046 | +| 10 | `(garbage collector)` | 0.033 | +| 11 | `_super (framework:132)` | 0.033 | +| 12 | `(anonymous) (framework:231)` | 0.032 | +| 13 | `setTimeout [native] (renderer)` | 0.029 | +| 14 | `setTimeout [native] (harness)` | 0.027 | +| 15 | `clear [native] (harness)` | 0.022 | +| 16 | `now [native] (framework)` | 0.020 | +| 17 | `innerSerialize [native] (native)` | 0.019 | +| 18 | `isElementThrottled (framework:219)` | 0.018 | +| 19 | `_stateChanged (framework:825)` | 0.018 | +| 20 | `now [native] (harness)` | 0.017 | + +### rows-ud-always A + +By chunk: (program) 5.104, renderer 1.500, harness 0.940, framework 0.421, (garbage collector) 0.279, native 0.131, reactivity 0.027 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------ | ---------- | +| 1 | `(program)` | 5.104 | +| 2 | `update (renderer:576)` | 0.283 | +| 3 | `(garbage collector)` | 0.279 | +| 4 | `requestAnimationFrame [native] (harness)` | 0.248 | +| 5 | `getError [native] (renderer)` | 0.232 | +| 6 | `clear [native] (harness)` | 0.225 | +| 7 | `bufferData [native] (renderer)` | 0.156 | +| 8 | `wrapped (harness:76)` | 0.102 | +| 9 | `setTimeout [native] (renderer)` | 0.095 | +| 10 | `(anonymous) [native] (native)` | 0.082 | +| 11 | `remove (framework:162)` | 0.074 | +| 12 | `drawFrame (renderer:2738)` | 0.067 | +| 13 | `(anonymous) (renderer:3054)` | 0.067 | +| 14 | `postMessage [native] (harness)` | 0.065 | +| 15 | `setTimeout [native] (harness)` | 0.063 | +| 16 | `updateGlobalGeometry (renderer:676)` | 0.050 | +| 17 | `translate (renderer:271)` | 0.048 | +| 18 | `addQuad (renderer:4791)` | 0.048 | +| 19 | `innerSerialize [native] (native)` | 0.035 | +| 20 | `keyEvent (harness:226)` | 0.032 | + +### rows-ud-always B + +By chunk: (program) 4.250, renderer 2.014, framework 0.484, harness 0.423, (garbage collector) 0.253, native 0.142, reactivity 0.035 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------- | ---------- | +| 1 | `(program)` | 4.250 | +| 2 | `getError [native] (renderer)` | 0.695 | +| 3 | `(garbage collector)` | 0.253 | +| 4 | `visit (renderer:1810)` | 0.235 | +| 5 | `clear [native] (renderer)` | 0.168 | +| 6 | `requestAnimationFrame [native] (renderer)` | 0.142 | +| 7 | `bufferData [native] (renderer)` | 0.136 | +| 8 | `setTimeout [native] (renderer)` | 0.108 | +| 9 | `(anonymous) (renderer:1826)` | 0.094 | +| 10 | `(anonymous) [native] (native)` | 0.090 | +| 11 | `remove (framework:156)` | 0.087 | +| 12 | `setTimeout [native] (harness)` | 0.070 | +| 13 | `postMessage [native] (harness)` | 0.067 | +| 14 | `propagateKeyPress (framework:219)` | 0.067 | +| 15 | `dispatchEvent [native] (harness)` | 0.055 | +| 16 | `tick (renderer:4742)` | 0.048 | +| 17 | `run (renderer:1775)` | 0.045 | +| 18 | `queueMicrotask [native] (framework)` | 0.045 | +| 19 | `keyEvent (harness:226)` | 0.034 | +| 20 | `FrameLoop.request (renderer:4722)` | 0.032 | + +### rows-ud-auto A + +By chunk: (program) 7.379, renderer 2.009, harness 1.476, framework 0.493, (garbage collector) 0.241, native 0.113, reactivity 0.077 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------ | ---------- | +| 1 | `(program)` | 7.379 | +| 2 | `requestAnimationFrame [native] (harness)` | 0.386 | +| 3 | `getError [native] (renderer)` | 0.360 | +| 4 | `clear [native] (harness)` | 0.253 | +| 5 | `(garbage collector)` | 0.241 | +| 6 | `update (renderer:576)` | 0.213 | +| 7 | `bufferData [native] (renderer)` | 0.158 | +| 8 | `(anonymous) (renderer:3054)` | 0.154 | +| 9 | `wrapped (harness:76)` | 0.124 | +| 10 | `checkRenderBounds (renderer:624)` | 0.104 | +| 11 | `postMessage [native] (harness)` | 0.099 | +| 12 | `setTimeout [native] (harness)` | 0.093 | +| 13 | `addQuad (renderer:4791)` | 0.089 | +| 14 | `translate (renderer:271)` | 0.087 | +| 15 | `drawFrame (renderer:2738)` | 0.084 | +| 16 | `now [native] (harness)` | 0.083 | +| 17 | `setTimeout [native] (renderer)` | 0.077 | +| 18 | `updateGlobalGeometry (renderer:676)` | 0.077 | +| 19 | `remove (framework:162)` | 0.074 | +| 20 | `keyEvent (harness:226)` | 0.072 | + +### rows-ud-auto B + +By chunk: (program) 5.321, renderer 2.100, harness 0.685, framework 0.436, (garbage collector) 0.168, native 0.159, reactivity 0.054 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------- | ---------- | +| 1 | `(program)` | 5.321 | +| 2 | `getError [native] (renderer)` | 0.819 | +| 3 | `clear [native] (harness)` | 0.220 | +| 4 | `(garbage collector)` | 0.168 | +| 5 | `requestAnimationFrame [native] (renderer)` | 0.135 | +| 6 | `setTimeout [native] (renderer)` | 0.123 | +| 7 | `bufferData [native] (renderer)` | 0.118 | +| 8 | `(anonymous) [native] (native)` | 0.118 | +| 9 | `visit (renderer:1810)` | 0.088 | +| 10 | `(anonymous) (framework:231)` | 0.086 | +| 11 | `wrapped (harness:76)` | 0.083 | +| 12 | `setTimeout [native] (harness)` | 0.081 | +| 13 | `(anonymous) (renderer:1826)` | 0.071 | +| 14 | `run (renderer:1775)` | 0.068 | +| 15 | `drawElements [native] (renderer)` | 0.062 | +| 16 | `remove (framework:156)` | 0.061 | +| 17 | `frame (renderer:5708)` | 0.051 | +| 18 | `dispatchEvent [native] (harness)` | 0.044 | +| 19 | `FrameLoop.run (renderer:4713)` | 0.041 | +| 20 | `classify (renderer:1979)` | 0.039 | + +### text-details-panel A + +By chunk: (program) 1.840, renderer 1.136, framework 0.623, harness 0.479, native 0.114, (garbage collector) 0.091, reactivity 0.085, user 0.001 + +| # | function (chunk:line) | self ms/op | +| --- | -------------------------------------------- | ---------- | +| 1 | `(program)` | 1.840 | +| 2 | `getError [native] (renderer)` | 0.222 | +| 3 | `(garbage collector)` | 0.091 | +| 4 | `renderQuads (renderer:5084)` | 0.091 | +| 5 | `setTimeout [native] (renderer)` | 0.086 | +| 6 | `postMessage [native] (harness)` | 0.085 | +| 7 | `calculateFlex (framework:328)` | 0.084 | +| 8 | `(anonymous) (framework:237)` | 0.082 | +| 9 | `(anonymous) [native] (native)` | 0.077 | +| 10 | `requestAnimationFrame [native] (harness)` | 0.072 | +| 11 | `remove (framework:162)` | 0.072 | +| 12 | `_sendToLightningAnimatable (framework:636)` | 0.063 | +| 13 | `wrapped (harness:76)` | 0.061 | +| 14 | `propagateKeyPress (framework:225)` | 0.056 | +| 15 | `(anonymous) (renderer:3054)` | 0.048 | +| 16 | `setTimeout [native] (harness)` | 0.042 | +| 17 | `runUpdates (reactivity:262)` | 0.040 | +| 18 | `renderText (renderer:5050)` | 0.040 | +| 19 | `renderQuads (renderer:724)` | 0.040 | +| 20 | `addSdfQuads (renderer:4831)` | 0.039 | + +### text-details-panel B + +By chunk: (program) 1.200, renderer 1.183, framework 0.628, harness 0.571, native 0.158, reactivity 0.118, (garbage collector) 0.063 + +| # | function (chunk:line) | self ms/op | +| --- | -------------------------------------------- | ---------- | +| 1 | `(program)` | 1.200 | +| 2 | `getError [native] (renderer)` | 0.838 | +| 3 | `(anonymous) [native] (native)` | 0.095 | +| 4 | `postMessage [native] (harness)` | 0.088 | +| 5 | `clear [native] (harness)` | 0.080 | +| 6 | `(anonymous) (framework:231)` | 0.074 | +| 7 | `calculateFlex (framework:322)` | 0.070 | +| 8 | `keyEvent (harness:226)` | 0.069 | +| 9 | `_sendToLightningAnimatable (framework:630)` | 0.065 | +| 10 | `(garbage collector)` | 0.063 | +| 11 | `emitText (renderer:3973)` | 0.058 | +| 12 | `(anonymous) (harness:320)` | 0.057 | +| 13 | `setTimeout [native] (harness)` | 0.047 | +| 14 | `(anonymous) (harness:342)` | 0.045 | +| 15 | `States (framework:131)` | 0.037 | +| 16 | `(anonymous) (reactivity:538)` | 0.037 | +| 17 | `remove (framework:156)` | 0.035 | +| 18 | `set (framework:948)` | 0.035 | +| 19 | `findSuppression (framework:276)` | 0.029 | +| 20 | `_super (framework:132)` | 0.029 | + +### text-flex-mount-new A + +By chunk: renderer 2.040, (program) 1.460, framework 0.944, reactivity 0.356, harness 0.304, (garbage collector) 0.207, user 0.122, native 0.093 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------ | ---------- | +| 1 | `(program)` | 1.460 | +| 2 | `getError [native] (renderer)` | 0.352 | +| 3 | `(garbage collector)` | 0.207 | +| 4 | `set style (framework:725)` | 0.202 | +| 5 | `CoreNode (renderer:467)` | 0.169 | +| 6 | `calculateFlex (framework:328)` | 0.166 | +| 7 | `renderQuads (renderer:5084)` | 0.164 | +| 8 | `generateTextLayout (renderer:4983)` | 0.162 | +| 9 | `mergeProps (reactivity:423)` | 0.130 | +| 10 | `measureText (renderer:4114)` | 0.110 | +| 11 | `updateLayout (framework:818)` | 0.090 | +| 12 | `TextTile (user:941)` | 0.087 | +| 13 | `addSdfQuads (renderer:4831)` | 0.084 | +| 14 | `get (framework:960)` | 0.074 | +| 15 | `requestAnimationFrame [native] (harness)` | 0.067 | +| 16 | `renderText (renderer:5050)` | 0.062 | +| 17 | `CoreTextNode (renderer:2343)` | 0.061 | +| 18 | `clear [native] (harness)` | 0.057 | +| 19 | `render (framework:872)` | 0.054 | +| 20 | `wrapText (renderer:2070)` | 0.051 | + +### text-flex-mount-new B + +By chunk: renderer 2.424, framework 1.230, (program) 1.037, reactivity 0.370, harness 0.203, (garbage collector) 0.124, user 0.109, native 0.107 + +| # | function (chunk:line) | self ms/op | +| --- | -------------------------------------------- | ---------- | +| 1 | `(program)` | 1.037 | +| 2 | `getError [native] (renderer)` | 0.823 | +| 3 | `layoutText (renderer:3791)` | 0.298 | +| 4 | `calculateFlex (framework:322)` | 0.269 | +| 5 | `render (framework:866)` | 0.258 | +| 6 | `set style (framework:719)` | 0.207 | +| 7 | `(anonymous) (renderer:3805)` | 0.196 | +| 8 | `visit (renderer:1810)` | 0.187 | +| 9 | `(garbage collector)` | 0.124 | +| 10 | `TextTile (user:941)` | 0.087 | +| 11 | `destroyNode (renderer:4452)` | 0.066 | +| 12 | `emitText (renderer:3973)` | 0.065 | +| 13 | `mergeProps (reactivity:423)` | 0.064 | +| 14 | `(anonymous) [native] (native)` | 0.057 | +| 15 | `spliceItem (framework:77)` | 0.055 | +| 16 | `setTimeout [native] (harness)` | 0.054 | +| 17 | `updateLayout (framework:812)` | 0.046 | +| 18 | `get (framework:945)` | 0.045 | +| 19 | `_sendToLightningAnimatable (framework:630)` | 0.042 | +| 20 | `postMessage [native] (harness)` | 0.041 | + +### text-flex-mount-same A + +By chunk: renderer 1.370, (program) 1.335, framework 0.914, reactivity 0.305, (garbage collector) 0.246, harness 0.186, user 0.129, native 0.089 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------ | ---------- | +| 1 | `(program)` | 1.335 | +| 2 | `getError [native] (renderer)` | 0.347 | +| 3 | `(garbage collector)` | 0.246 | +| 4 | `set style (framework:725)` | 0.212 | +| 5 | `calculateFlex (framework:328)` | 0.188 | +| 6 | `CoreNode (renderer:467)` | 0.172 | +| 7 | `renderQuads (renderer:5084)` | 0.097 | +| 8 | `renderText (renderer:5050)` | 0.094 | +| 9 | `TextTile (user:941)` | 0.089 | +| 10 | `get (framework:951)` | 0.075 | +| 11 | `get (framework:960)` | 0.065 | +| 12 | `(anonymous) [native] (native)` | 0.059 | +| 13 | `insertNode (framework:1039)` | 0.054 | +| 14 | `get width (framework:597)` | 0.052 | +| 15 | `bufferData [native] (renderer)` | 0.051 | +| 16 | `mergeProps (reactivity:423)` | 0.048 | +| 17 | `requestLoop (renderer:3051)` | 0.041 | +| 18 | `postMessage [native] (harness)` | 0.041 | +| 19 | `requestAnimationFrame [native] (harness)` | 0.040 | +| 20 | `CoreTextNode (renderer:2343)` | 0.038 | + +### text-flex-mount-same B + +By chunk: renderer 1.610, framework 1.007, (program) 1.003, reactivity 0.381, harness 0.254, user 0.179, native 0.100, (garbage collector) 0.100 + +| # | function (chunk:line) | self ms/op | +| --- | -------------------------------------------- | ---------- | +| 1 | `(program)` | 1.003 | +| 2 | `getError [native] (renderer)` | 0.700 | +| 3 | `render (framework:866)` | 0.177 | +| 4 | `calculateFlex (framework:322)` | 0.165 | +| 5 | `set style (framework:719)` | 0.147 | +| 6 | `TextTile (user:941)` | 0.118 | +| 7 | `mergeProps (reactivity:423)` | 0.111 | +| 8 | `(garbage collector)` | 0.100 | +| 9 | `updateLayout (framework:812)` | 0.085 | +| 10 | `get height (framework:585)` | 0.067 | +| 11 | `cleanNode (reactivity:346)` | 0.067 | +| 12 | `destroyNode (renderer:4452)` | 0.064 | +| 13 | `clear [native] (harness)` | 0.060 | +| 14 | `visit (renderer:1810)` | 0.059 | +| 15 | `(anonymous) (renderer:1826)` | 0.057 | +| 16 | `get width (framework:591)` | 0.055 | +| 17 | `_sendToLightningAnimatable (framework:630)` | 0.052 | +| 18 | `(anonymous) [native] (native)` | 0.052 | +| 19 | `setTimeout [native] (renderer)` | 0.046 | +| 20 | `createNode (renderer:4232)` | 0.044 | + +### text-virtual-row A + +By chunk: (program) 5.682, renderer 2.605, harness 1.252, framework 0.754, (garbage collector) 0.220, native 0.138, reactivity 0.131, user 0.017 + +| # | function (chunk:line) | self ms/op | +| --- | -------------------------------------------- | ---------- | +| 1 | `(program)` | 5.682 | +| 2 | `getError [native] (renderer)` | 0.317 | +| 3 | `clear [native] (harness)` | 0.287 | +| 4 | `requestAnimationFrame [native] (harness)` | 0.238 | +| 5 | `(garbage collector)` | 0.220 | +| 6 | `bufferData [native] (renderer)` | 0.219 | +| 7 | `addSdfCachedQuads (renderer:4851)` | 0.199 | +| 8 | `wrapped (harness:76)` | 0.171 | +| 9 | `update (renderer:576)` | 0.140 | +| 10 | `postMessage [native] (harness)` | 0.130 | +| 11 | `renderQuads (renderer:5084)` | 0.128 | +| 12 | `(anonymous) (renderer:3054)` | 0.126 | +| 13 | `setTimeout [native] (harness)` | 0.114 | +| 14 | `drawElements [native] (renderer)` | 0.112 | +| 15 | `uniform2f [native] (renderer)` | 0.095 | +| 16 | `drawFrame (renderer:2738)` | 0.094 | +| 17 | `(anonymous) [native] (native)` | 0.091 | +| 18 | `setTimeout [native] (renderer)` | 0.089 | +| 19 | `_sendToLightningAnimatable (framework:636)` | 0.080 | +| 20 | `dispatchEvent [native] (harness)` | 0.074 | + +### text-virtual-row B + +By chunk: (program) 4.231, renderer 2.136, framework 0.708, harness 0.526, (garbage collector) 0.205, reactivity 0.173, native 0.133 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------- | ---------- | +| 1 | `(program)` | 4.231 | +| 2 | `getError [native] (renderer)` | 0.612 | +| 3 | `requestAnimationFrame [native] (renderer)` | 0.211 | +| 4 | `(garbage collector)` | 0.205 | +| 5 | `emitText (renderer:3973)` | 0.114 | +| 6 | `setTimeout [native] (renderer)` | 0.106 | +| 7 | `calculateFlex (framework:322)` | 0.099 | +| 8 | `clear [native] (renderer)` | 0.094 | +| 9 | `bufferData [native] (renderer)` | 0.092 | +| 10 | `(anonymous) [native] (native)` | 0.087 | +| 11 | `postMessage [native] (harness)` | 0.083 | +| 12 | `propagateKeyPress (framework:219)` | 0.078 | +| 13 | `setTimeout [native] (harness)` | 0.073 | +| 14 | `visit (renderer:1810)` | 0.070 | +| 15 | `bindTexture [native] (renderer)` | 0.062 | +| 16 | `KeyboardEvent [native] (harness)` | 0.055 | +| 17 | `remove (framework:156)` | 0.052 | +| 18 | `dispatchEvent [native] (harness)` | 0.051 | +| 19 | `wrapped (harness:76)` | 0.050 | +| 20 | `updateLayout (framework:812)` | 0.050 | + +### thumbnail-focus A + +By chunk: (program) 3.422, renderer 1.086, harness 0.542, framework 0.273, (garbage collector) 0.195, native 0.122, reactivity 0.038 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------------------ | ---------- | +| 1 | `(program)` | 3.422 | +| 2 | `getError [native] (renderer)` | 0.245 | +| 3 | `(garbage collector)` | 0.195 | +| 4 | `clear [native] (harness)` | 0.115 | +| 5 | `requestAnimationFrame [native] (harness)` | 0.106 | +| 6 | `requestAnimationFrame [native] (renderer)` | 0.096 | +| 7 | `wrapped (harness:76)` | 0.080 | +| 8 | `bufferData [native] (renderer)` | 0.070 | +| 9 | `(anonymous) [native] (native)` | 0.069 | +| 10 | `uniform4fv [native] (renderer)` | 0.066 | +| 11 | `(anonymous) (renderer:3054)` | 0.064 | +| 12 | `setTimeout [native] (renderer)` | 0.057 | +| 13 | `remove (framework:162)` | 0.057 | +| 14 | `setTimeout [native] (harness)` | 0.047 | +| 15 | `bindTexture [native] (renderer)` | 0.041 | +| 16 | `drawFrame (renderer:2738)` | 0.040 | +| 17 | `bindRenderOp (renderer:3760)` | 0.033 | +| 18 | `postMessage [native] (harness)` | 0.033 | +| 19 | `createValueKey (renderer:1988)` | 0.030 | +| 20 | `WebGlShaderNode.config.update.update (renderer:3535)` | 0.030 | + +### thumbnail-focus B + +By chunk: (program) 3.308, renderer 1.689, framework 0.418, harness 0.344, (garbage collector) 0.134, native 0.119, reactivity 0.069, user 0.001 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------- | ---------- | +| 1 | `(program)` | 3.308 | +| 2 | `getError [native] (renderer)` | 0.587 | +| 3 | `requestAnimationFrame [native] (renderer)` | 0.209 | +| 4 | `(garbage collector)` | 0.134 | +| 5 | `clear [native] (renderer)` | 0.134 | +| 6 | `(anonymous) [native] (native)` | 0.084 | +| 7 | `bufferData [native] (renderer)` | 0.077 | +| 8 | `wrapped (harness:76)` | 0.068 | +| 9 | `drawElements [native] (renderer)` | 0.060 | +| 10 | `bindTexture [native] (renderer)` | 0.059 | +| 11 | `postMessage [native] (harness)` | 0.053 | +| 12 | `uniform4fv [native] (renderer)` | 0.051 | +| 13 | `get states (framework:763)` | 0.039 | +| 14 | `setTimeout [native] (renderer)` | 0.037 | +| 15 | `propagateKeyPress (framework:219)` | 0.036 | +| 16 | `FrameLoop.request (renderer:4722)` | 0.035 | +| 17 | `remove (framework:156)` | 0.035 | +| 18 | `KeyboardEvent [native] (harness)` | 0.031 | +| 19 | `(anonymous) (framework:520)` | 0.031 | +| 20 | `draw (renderer:4609)` | 0.029 | + +### virtual-grid A + +By chunk: (program) 4.065, renderer 2.114, framework 0.964, harness 0.683, (garbage collector) 0.375, reactivity 0.245, native 0.106, user 0.015 + +| # | function (chunk:line) | self ms/op | +| --- | -------------------------------------------- | ---------- | +| 1 | `(program)` | 4.065 | +| 2 | `(garbage collector)` | 0.375 | +| 3 | `getError [native] (renderer)` | 0.271 | +| 4 | `bindRenderOp (renderer:3760)` | 0.205 | +| 5 | `requestAnimationFrame [native] (renderer)` | 0.123 | +| 6 | `setTimeout [native] (renderer)` | 0.121 | +| 7 | `calculateFlex (framework:328)` | 0.120 | +| 8 | `bufferData [native] (renderer)` | 0.117 | +| 9 | `wrapped (harness:76)` | 0.116 | +| 10 | `_sendToLightningAnimatable (framework:636)` | 0.113 | +| 11 | `clear [native] (harness)` | 0.110 | +| 12 | `uniform4fv [native] (renderer)` | 0.105 | +| 13 | `(anonymous) (renderer:3054)` | 0.083 | +| 14 | `requestAnimationFrame [native] (harness)` | 0.082 | +| 15 | `setTimeout [native] (harness)` | 0.069 | +| 16 | `updateFocusPath (framework:190)` | 0.064 | +| 17 | `drawElements [native] (renderer)` | 0.063 | +| 18 | `postMessage [native] (harness)` | 0.062 | +| 19 | `remove (framework:162)` | 0.062 | +| 20 | `updateComputation (reactivity:169)` | 0.060 | + +### virtual-grid B + +By chunk: (program) 3.183, renderer 2.018, framework 0.854, harness 0.498, (garbage collector) 0.344, reactivity 0.241, native 0.132, user 0.020 + +| # | function (chunk:line) | self ms/op | +| --- | -------------------------------------------- | ---------- | +| 1 | `(program)` | 3.183 | +| 2 | `getError [native] (renderer)` | 0.555 | +| 3 | `(garbage collector)` | 0.344 | +| 4 | `requestAnimationFrame [native] (renderer)` | 0.135 | +| 5 | `bindTexture [native] (renderer)` | 0.106 | +| 6 | `visit (renderer:1810)` | 0.100 | +| 7 | `(anonymous) [native] (native)` | 0.092 | +| 8 | `calculateFlex (framework:322)` | 0.089 | +| 9 | `_sendToLightningAnimatable (framework:630)` | 0.089 | +| 10 | `wrapped (harness:76)` | 0.088 | +| 11 | `(anonymous) (reactivity:643)` | 0.084 | +| 12 | `drawElements [native] (renderer)` | 0.079 | +| 13 | `keyEvent (harness:226)` | 0.077 | +| 14 | `uniform4fv [native] (renderer)` | 0.063 | +| 15 | `clear [native] (harness)` | 0.063 | +| 16 | `(anonymous) (renderer:1826)` | 0.061 | +| 17 | `get width (framework:591)` | 0.059 | +| 18 | `emit (renderer:2013)` | 0.056 | +| 19 | `frame (renderer:5708)` | 0.048 | +| 20 | `untrack (reactivity:84)` | 0.046 | + +### virtual-row A + +By chunk: (program) 3.516, renderer 1.477, framework 0.580, harness 0.574, reactivity 0.181, (garbage collector) 0.128, native 0.125, user 0.002 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------- | ---------- | +| 1 | `(program)` | 3.516 | +| 2 | `getError [native] (renderer)` | 0.299 | +| 3 | `(garbage collector)` | 0.128 | +| 4 | `remove (framework:162)` | 0.121 | +| 5 | `requestAnimationFrame [native] (harness)` | 0.110 | +| 6 | `clear [native] (harness)` | 0.099 | +| 7 | `requestAnimationFrame [native] (renderer)` | 0.086 | +| 8 | `update (renderer:576)` | 0.083 | +| 9 | `(anonymous) [native] (native)` | 0.080 | +| 10 | `setTimeout [native] (harness)` | 0.069 | +| 11 | `bindTexture [native] (renderer)` | 0.068 | +| 12 | `bufferData [native] (renderer)` | 0.067 | +| 13 | `drawElements [native] (renderer)` | 0.063 | +| 14 | `untrack (reactivity:84)` | 0.062 | +| 15 | `(anonymous) (renderer:3054)` | 0.061 | +| 16 | `setTimeout [native] (renderer)` | 0.057 | +| 17 | `_stateChanged (framework:831)` | 0.040 | +| 18 | `writeValues (renderer:1215)` | 0.040 | +| 19 | `set texture (renderer:1108)` | 0.039 | +| 20 | `wrapped (harness:76)` | 0.039 | + +### virtual-row B + +By chunk: (program) 3.337, renderer 1.615, framework 0.656, harness 0.310, reactivity 0.152, (garbage collector) 0.114, native 0.101, user 0.017 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------- | ---------- | +| 1 | `(program)` | 3.337 | +| 2 | `getError [native] (renderer)` | 0.555 | +| 3 | `(garbage collector)` | 0.114 | +| 4 | `requestAnimationFrame [native] (renderer)` | 0.110 | +| 5 | `clear [native] (renderer)` | 0.103 | +| 6 | `bufferData [native] (renderer)` | 0.098 | +| 7 | `(anonymous) [native] (native)` | 0.077 | +| 8 | `bindTexture [native] (renderer)` | 0.075 | +| 9 | `updateLayout (framework:812)` | 0.073 | +| 10 | `calculateFlex (framework:322)` | 0.069 | +| 11 | `setTimeout [native] (harness)` | 0.068 | +| 12 | `Animation (renderer:855)` | 0.065 | +| 13 | `setTimeout [native] (renderer)` | 0.061 | +| 14 | `drawElements [native] (renderer)` | 0.054 | +| 15 | `wrapped (harness:76)` | 0.047 | +| 16 | `FrameLoop.request (renderer:4722)` | 0.045 | +| 17 | `remove (framework:156)` | 0.044 | +| 18 | `dispatchEvent [native] (harness)` | 0.037 | +| 19 | `KeyboardEvent [native] (harness)` | 0.035 | +| 20 | `visit (renderer:1810)` | 0.035 | diff --git a/docs/perf/results/2026-10-04/summary.md b/docs/perf/results/2026-10-04/summary.md new file mode 100644 index 00000000..cc7e2580 --- /dev/null +++ b/docs/perf/results/2026-10-04/summary.md @@ -0,0 +1,324 @@ +# Benchmark summary + +Generated by `node bench/run.mjs` from the 220 result files in this directory. Methodology: [docs/perf/README.md](../../README.md). + +- CPU throttling: 6x +- GPU: ANGLE (Apple, ANGLE Metal Renderer: Apple M4 Pro, Unspecified Version) +- Flex: new (src/core/flexLayout.ts) +- Chromium: 141.0.7390.37 +- crossOriginIsolated: true; clock resolution 5.0 µs at worst +- 1-minute load average at run start: 0.7–3.9 + +Each cell is the median over runs of the per-run value, with the min–max over runs in parentheses. Times are ms of wall clock under CPU throttling. The per-run value of a time is its **mean over ops**: the throttler is a duty cycle (at 6x about 0.17 ms running, 0.85 ms suspended), so a sub-millisecond interval reads either unthrottled or one suspension longer, and only the mean estimates rate × CPU (see the README). + +## Time per op (ms, per-run mean over ops) + +`total` = handler + tail + frame (keydown to the end of the frame that shows it); `cpu` adds every later frame until idle; `p95 total` is the per-run 95th percentile. + +| scenario | arm | handler | tail | frame | total | p95 total | cpu | drawn frames | settle | runs | +| -------------------- | ----------- | ------------------- | ------------------- | ------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------- | ------------------- | ---- | +| navdrawer-toggle | A | 0.030 (0.028–0.046) | 0.178 (0.139–0.223) | 0.066 (0.059–0.073) | 0.267 (0.257–0.317) | 0.900 (0.865–0.990) | 0.767 (0.719–0.786) | 16.0 (15.9–16.1) | 261.4 (259.8–261.9) | 3 | +| navdrawer-toggle | B | 0.036 (0.027–0.046) | 0.251 (0.237–0.262) | 0.054 (0.048–0.074) | 0.347 (0.338–0.351) | 0.995 (0.950–1.315) | 0.626 (0.607–0.635) | 15.6 (15.4–15.7) | 249.5 (247.6–251.1) | 3 | +| navdrawer-toggle | C | 0.041 (0.028–0.046) | 0.177 (0.153–0.182) | 0.043 (0.039–0.051) | 0.248 (0.245–0.268) | 0.800 (0.760–0.905) | 0.562 (0.521–0.585) | 15.5 (15.4–15.5) | 248.6 (247.1–249.0) | 3 | +| page-mount | A | 4.671 (4.453–4.914) | 0.679 (0.512–0.830) | 0.386 (0.372–0.513) | 5.735 (5.656–5.939) | 12.865 (12.815–13.370) | 6.323 (6.156–6.440) | 6.8 (6.8–6.9) | 109.5 (109.0–113.0) | 3 | +| page-mount | A [create] | 9.196 (8.761–9.460) | 0.998 (0.878–1.402) | 0.763 (0.738–1.017) | 10.957 (10.901–11.356) | 12.865 (12.815–13.370) | 12.088 (11.659–12.238) | 12.7 (12.5–12.8) | 204.0 (203.1–207.1) | 3 | +| page-mount | A [destroy] | 0.146 (0.145–0.367) | 0.259 (0.146–0.359) | 0.008 (0.007–0.008) | 0.514 (0.410–0.521) | 1.000 (0.985–1.175) | 0.643 (0.558–0.653) | 1.0 (1.0–1.0) | 15.9 (14.0–18.9) | 3 | +| page-mount | B | 3.709 (3.329–3.987) | 0.486 (0.474–0.790) | 0.475 (0.409–0.478) | 4.938 (4.224–4.973) | 10.290 (9.270–10.960) | 5.137 (4.463–5.182) | 6.8 (6.7–6.9) | 103.6 (101.6–105.5) | 3 | +| page-mount | B [create] | 7.292 (6.459–7.536) | 0.714 (0.567–0.926) | 0.943 (0.812–0.945) | 9.047 (7.986–9.162) | 10.290 (9.270–10.960) | 9.445 (8.465–9.579) | 12.6 (12.4–12.8) | 199.8 (195.8–205.0) | 3 | +| page-mount | B [destroy] | 0.198 (0.126–0.437) | 0.381 (0.258–0.653) | 0.006 (0.005–0.011) | 0.785 (0.462–0.829) | 1.500 (1.280–1.630) | 0.785 (0.462–0.829) | 1.0 (1.0–1.0) | 7.4 (6.1–7.4) | 3 | +| page-mount | C | 3.305 (3.243–3.542) | 0.524 (0.511–0.835) | 0.407 (0.318–0.466) | 4.458 (4.233–4.459) | 10.460 (10.040–15.795) | 4.682 (4.555–4.734) | 6.8 (6.8–6.8) | 104.3 (103.2–104.5) | 3 | +| page-mount | C [create] | 6.394 (6.388–6.849) | 0.592 (0.553–1.370) | 0.809 (0.630–0.925) | 8.212 (7.905–8.393) | 10.460 (10.040–15.795) | 8.763 (8.548–8.841) | 12.6 (12.5–12.7) | 201.2 (199.4–202.6) | 3 | +| page-mount | C [destroy] | 0.217 (0.098–0.234) | 0.456 (0.300–0.468) | 0.007 (0.004–0.007) | 0.561 (0.523–0.706) | 1.320 (1.090–1.415) | 0.561 (0.523–0.706) | 1.0 (1.0–1.0) | 6.9 (6.4–7.4) | 3 | +| page-swap | A | 8.955 (8.930–9.071) | 1.400 (1.369–1.499) | 0.908 (0.631–0.919) | 11.275 (11.060–11.348) | 13.105 (12.960–13.210) | 11.919 (11.897–12.056) | 12.5 (12.4–12.5) | 203.0 (201.8–205.9) | 3 | +| page-swap | B | 7.438 (7.094–7.594) | 1.385 (1.353–1.511) | 0.895 (0.820–1.096) | 9.769 (9.374–10.043) | 10.880 (10.455–11.815) | 10.236 (9.985–10.810) | 12.5 (12.4–12.6) | 198.9 (197.3–200.3) | 3 | +| page-swap | C | 6.966 (6.783–8.125) | 0.968 (0.896–0.969) | 0.738 (0.674–0.801) | 8.599 (8.553–9.767) | 11.265 (10.065–12.735) | 9.331 (9.299–10.493) | 12.4 (12.4–12.6) | 198.4 (198.1–199.9) | 3 | +| portal-focus-text | A | 0.044 (0.040–0.070) | 0.117 (0.109–0.125) | 0.069 (0.031–0.069) | 0.238 (0.180–0.256) | 0.670 (0.515–0.810) | 0.766 (0.658–0.784) | 15.0 (15.0–15.1) | 245.0 (244.5–245.5) | 3 | +| portal-focus-text | B | 0.119 (0.099–0.123) | 0.149 (0.118–0.174) | 0.022 (0.017–0.023) | 0.289 (0.240–0.315) | 0.815 (0.790–0.835) | 0.616 (0.592–0.641) | 15.5 (15.5–15.6) | 248.0 (247.9–250.3) | 3 | +| portal-focus-text | C | 0.088 (0.078–0.096) | 0.090 (0.070–0.114) | 0.018 (0.016–0.062) | 0.218 (0.184–0.230) | 0.790 (0.760–0.875) | 0.553 (0.542–0.601) | 15.5 (15.4–15.6) | 248.3 (247.1–250.5) | 3 | +| poster-mount | A | 0.299 (0.286–0.351) | 0.047 (0.047–0.088) | 0.120 (0.089–0.172) | 0.487 (0.453–0.560) | 1.560 (1.380–1.785) | 0.635 (0.621–0.728) | 1.5 (1.5–1.5) | 21.6 (20.3–23.0) | 3 | +| poster-mount | B | 0.188 (0.145–0.202) | 0.034 (0.031–0.081) | 0.086 (0.074–0.099) | 0.308 (0.300–0.332) | 1.245 (1.025–1.375) | 0.308 (0.300–0.332) | 1.0 (1.0–1.0) | 7.5 (7.4–7.6) | 3 | +| poster-mount | C | 0.182 (0.165–0.213) | 0.096 (0.063–0.099) | 0.070 (0.064–0.092) | 0.370 (0.292–0.381) | 1.345 (0.990–1.415) | 0.370 (0.292–0.381) | 1.0 (1.0–1.0) | 7.4 (7.3–7.6) | 3 | +| poster-swap | A | 0.333 (0.316–0.393) | 0.097 (0.095–0.112) | 0.075 (0.055–0.083) | 0.505 (0.483–0.570) | 1.360 (1.340–1.930) | 0.694 (0.619–0.701) | 2.0 (2.0–2.0) | 28.4 (27.4–28.9) | 3 | +| poster-swap | B | 0.238 (0.180–0.267) | 0.051 (0.015–0.069) | 0.057 (0.056–0.068) | 0.340 (0.306–0.357) | 1.015 (0.920–1.290) | 0.340 (0.306–0.357) | 1.0 (1.0–1.0) | 7.6 (7.5–7.7) | 3 | +| poster-swap | C | 0.256 (0.181–0.266) | 0.081 (0.046–0.098) | 0.063 (0.039–0.070) | 0.376 (0.291–0.433) | 1.125 (0.815–1.520) | 0.376 (0.291–0.433) | 1.0 (1.0–1.0) | 7.4 (7.3–7.6) | 3 | +| rows-lr-always | A | 0.041 (0.037–0.044) | 0.087 (0.071–0.090) | 0.014 (0.013–0.022) | 0.141 (0.128–0.149) | 0.485 (0.475–0.515) | 0.440 (0.364–0.480) | 11.3 (11.3–11.3) | 182.0 (181.2–184.2) | 3 | +| rows-lr-always | B | 0.081 (0.071–0.107) | 0.090 (0.057–0.135) | 0.014 (0.011–0.034) | 0.211 (0.162–0.227) | 0.725 (0.595–0.805) | 0.355 (0.289–0.361) | 11.0 (11.0–11.0) | 173.5 (173.4–173.7) | 3 | +| rows-lr-always | C | 0.060 (0.045–0.062) | 0.079 (0.078–0.107) | 0.013 (0.012–0.014) | 0.154 (0.152–0.165) | 0.650 (0.650–0.750) | 0.317 (0.301–0.337) | 11.0 (11.0–11.0) | 173.5 (173.4–173.5) | 3 | +| rows-lr-auto | A | 0.046 (0.045–0.075) | 0.070 (0.050–0.073) | 0.017 (0.010–0.021) | 0.133 (0.116–0.158) | 0.450 (0.410–0.560) | 0.424 (0.351–0.444) | 11.2 (11.1–11.2) | 181.0 (180.2–181.4) | 3 | +| rows-lr-auto | B | 0.094 (0.085–0.133) | 0.091 (0.027–0.106) | 0.016 (0.011–0.028) | 0.187 (0.149–0.255) | 0.830 (0.555–1.120) | 0.326 (0.283–0.483) | 11.0 (11.0–11.0) | 173.5 (173.5–173.6) | 3 | +| rows-lr-auto | C | 0.059 (0.057–0.079) | 0.085 (0.035–0.089) | 0.014 (0.011–0.066) | 0.159 (0.157–0.178) | 0.730 (0.620–0.830) | 0.294 (0.293–0.333) | 11.0 (11.0–11.0) | 173.3 (173.3–173.5) | 3 | +| rows-lr-noshift | A | 0.044 (0.029–0.050) | 0.044 (0.032–0.049) | 0.026 (0.019–0.031) | 0.104 (0.094–0.125) | 0.345 (0.290–0.375) | 0.247 (0.242–0.286) | 1.0 (1.0–1.0) | 14.6 (14.0–16.3) | 3 | +| rows-lr-noshift | B | 0.055 (0.040–0.063) | 0.095 (0.095–0.134) | 0.046 (0.021–0.070) | 0.220 (0.156–0.244) | 0.955 (0.620–1.495) | 0.220 (0.156–0.244) | 1.0 (1.0–1.0) | 6.7 (6.7–7.0) | 3 | +| rows-lr-noshift | C | 0.036 (0.027–0.042) | 0.048 (0.036–0.095) | 0.035 (0.014–0.036) | 0.103 (0.098–0.167) | 0.575 (0.480–0.660) | 0.103 (0.098–0.167) | 1.0 (1.0–1.0) | 6.8 (6.6–6.9) | 3 | +| rows-ud-always | A | 0.050 (0.046–0.088) | 0.082 (0.076–0.091) | 0.030 (0.020–0.040) | 0.157 (0.156–0.210) | 0.570 (0.560–0.670) | 0.672 (0.648–0.722) | 18.5 (18.5–18.6) | 303.7 (303.3–303.9) | 3 | +| rows-ud-always | B | 0.102 (0.083–0.132) | 0.100 (0.095–0.135) | 0.015 (0.015–0.015) | 0.242 (0.199–0.252) | 0.805 (0.800–0.805) | 0.563 (0.477–0.623) | 18.5 (18.5–18.6) | 298.8 (298.7–299.5) | 3 | +| rows-ud-always | C | 0.108 (0.085–0.118) | 0.072 (0.052–0.092) | 0.015 (0.014–0.017) | 0.204 (0.151–0.217) | 0.745 (0.580–0.745) | 0.503 (0.483–0.513) | 18.6 (18.5–18.6) | 299.4 (298.2–300.1) | 3 | +| rows-ud-auto | A | 0.062 (0.056–0.075) | 0.069 (0.060–0.102) | 0.021 (0.017–0.029) | 0.153 (0.139–0.199) | 0.500 (0.445–0.500) | 0.662 (0.569–0.695) | 14.6 (14.5–14.7) | 239.2 (239.1–239.5) | 3 | +| rows-ud-auto | B | 0.090 (0.072–0.118) | 0.097 (0.083–0.125) | 0.015 (0.015–0.026) | 0.229 (0.181–0.229) | 0.660 (0.645–0.770) | 0.448 (0.437–0.475) | 14.6 (14.6–14.6) | 233.5 (233.1–233.9) | 3 | +| rows-ud-auto | C | 0.084 (0.073–0.103) | 0.064 (0.036–0.087) | 0.025 (0.014–0.037) | 0.173 (0.145–0.204) | 0.560 (0.550–0.630) | 0.401 (0.391–0.511) | 14.6 (14.6–14.7) | 233.5 (232.9–234.4) | 3 | +| text-details-panel | A | 0.037 (0.034–0.048) | 0.033 (0.031–0.043) | 0.212 (0.211–0.230) | 0.293 (0.281–0.307) | 0.905 (0.690–1.075) | 0.432 (0.418–0.487) | 1.0 (1.0–1.0) | 15.0 (14.2–15.9) | 3 | +| text-details-panel | B | 0.058 (0.036–0.072) | 0.036 (0.015–0.038) | 0.150 (0.105–0.151) | 0.201 (0.201–0.259) | 0.755 (0.515–0.945) | 0.201 (0.201–0.259) | 1.0 (1.0–1.0) | 6.9 (6.8–6.9) | 3 | +| text-details-panel | C | 0.074 (0.059–0.101) | 0.113 (0.098–0.162) | 0.086 (0.040–0.087) | 0.254 (0.244–0.322) | 1.135 (0.890–1.190) | 0.254 (0.244–0.322) | 1.0 (1.0–1.0) | 6.9 (6.9–7.1) | 3 | +| text-flex-mount-new | A | 0.704 (0.701–0.761) | 0.205 (0.139–0.240) | 0.456 (0.371–0.501) | 1.364 (1.211–1.502) | 2.385 (2.185–2.825) | 1.527 (1.338–1.656) | 1.0 (1.0–1.0) | 14.4 (13.6–15.4) | 3 | +| text-flex-mount-new | B | 0.591 (0.585–0.601) | 0.211 (0.106–0.248) | 0.621 (0.614–0.766) | 1.447 (1.327–1.568) | 2.715 (2.485–2.835) | 1.447 (1.327–1.568) | 1.0 (1.0–1.0) | 7.5 (7.3–7.5) | 3 | +| text-flex-mount-new | C | 0.424 (0.417–0.637) | 0.719 (0.547–0.961) | 0.034 (0.032–0.067) | 1.170 (1.003–1.665) | 2.010 (1.745–2.660) | 1.170 (1.003–1.665) | 1.0 (1.0–1.0) | 7.5 (7.4–7.5) | 3 | +| text-flex-mount-same | A | 0.740 (0.450–0.760) | 0.197 (0.112–0.223) | 0.239 (0.226–0.279) | 1.162 (0.841–1.222) | 2.045 (1.860–2.595) | 1.298 (0.966–1.342) | 1.0 (1.0–1.0) | 14.9 (13.4–16.7) | 3 | +| text-flex-mount-same | B | 0.504 (0.479–0.550) | 0.102 (0.097–0.132) | 0.143 (0.121–0.171) | 0.779 (0.697–0.822) | 1.555 (1.435–1.785) | 0.779 (0.697–0.822) | 1.0 (1.0–1.0) | 7.4 (7.4–7.6) | 3 | +| text-flex-mount-same | C | 0.417 (0.404–0.447) | 0.140 (0.118–0.174) | 0.032 (0.025–0.047) | 0.610 (0.582–0.613) | 1.315 (1.300–1.385) | 0.610 (0.582–0.613) | 1.0 (1.0–1.0) | 7.3 (7.3–7.7) | 3 | +| text-virtual-row | A | 0.121 (0.100–0.154) | 0.183 (0.162–0.196) | 0.089 (0.082–0.094) | 0.406 (0.365–0.411) | 0.970 (0.895–1.300) | 0.905 (0.865–0.935) | 15.6 (15.6–15.6) | 254.6 (253.2–254.9) | 3 | +| text-virtual-row | B | 0.174 (0.173–0.200) | 0.209 (0.199–0.210) | 0.047 (0.036–0.080) | 0.453 (0.418–0.457) | 1.225 (1.090–1.245) | 0.711 (0.628–0.797) | 15.4 (15.4–15.5) | 247.1 (247.1–248.8) | 3 | +| text-virtual-row | C | 0.135 (0.100–0.153) | 0.245 (0.200–0.255) | 0.027 (0.023–0.044) | 0.396 (0.378–0.407) | 1.040 (1.025–1.115) | 0.701 (0.604–0.710) | 15.5 (15.4–15.6) | 248.3 (247.3–250.3) | 3 | +| thumbnail-focus | A | 0.026 (0.019–0.028) | 0.088 (0.072–0.154) | 0.028 (0.018–0.042) | 0.144 (0.133–0.198) | 0.485 (0.445–0.710) | 0.523 (0.520–0.532) | 15.6 (15.5–15.7) | 252.8 (251.9–254.4) | 3 | +| thumbnail-focus | B | 0.041 (0.038–0.044) | 0.145 (0.109–0.173) | 0.031 (0.021–0.033) | 0.207 (0.180–0.248) | 0.785 (0.775–0.870) | 0.376 (0.364–0.445) | 15.5 (15.5–15.6) | 249.0 (248.4–249.6) | 3 | +| thumbnail-focus | C | 0.040 (0.024–0.043) | 0.124 (0.114–0.165) | 0.028 (0.025–0.044) | 0.195 (0.179–0.233) | 0.650 (0.620–0.730) | 0.418 (0.363–0.450) | 15.5 (15.4–15.6) | 248.8 (247.1–249.6) | 3 | +| virtual-grid | A | 0.287 (0.256–0.398) | 0.510 (0.388–0.512) | 0.062 (0.048–0.073) | 0.845 (0.829–0.859) | 1.510 (1.375–1.950) | 1.327 (1.294–1.385) | 15.6 (15.5–15.7) | 253.4 (252.9–254.6) | 3 | +| virtual-grid | B | 0.246 (0.223–0.270) | 0.497 (0.451–0.501) | 0.047 (0.046–0.072) | 0.814 (0.720–0.819) | 1.640 (1.420–1.975) | 1.036 (0.984–1.075) | 15.5 (15.4–15.5) | 248.9 (246.9–249.4) | 3 | +| virtual-grid | C | 0.220 (0.206–0.233) | 0.313 (0.272–0.337) | 0.070 (0.063–0.143) | 0.619 (0.590–0.647) | 1.450 (1.380–1.580) | 0.849 (0.839–0.865) | 15.4 (15.3–15.5) | 247.5 (245.1–249.1) | 3 | +| virtual-row | A | 0.132 (0.108–0.176) | 0.213 (0.203–0.214) | 0.018 (0.018–0.023) | 0.364 (0.339–0.401) | 0.900 (0.885–1.145) | 0.706 (0.667–0.790) | 15.5 (15.4–15.7) | 254.4 (252.4–254.5) | 3 | +| virtual-row | B | 0.131 (0.130–0.194) | 0.259 (0.217–0.276) | 0.016 (0.015–0.017) | 0.424 (0.406–0.428) | 1.140 (1.000–1.355) | 0.631 (0.607–0.675) | 15.6 (15.5–15.6) | 249.5 (248.5–249.6) | 3 | +| virtual-row | C | 0.146 (0.102–0.210) | 0.128 (0.104–0.181) | 0.026 (0.019–0.035) | 0.293 (0.240–0.417) | 0.980 (0.860–1.140) | 0.475 (0.444–0.600) | 15.5 (15.5–15.5) | 248.5 (248.4–248.7) | 3 | + +## Ratios (medians over runs) + +A/B: shipping 1.6.4 on renderer 1.9.3 over the lockstep port on renderer v2. B/C: the same code today, so B/C is the in-session noise floor. + +| scenario | A/B total | B/C total | A/B handler | B/C handler | A/B frame | B/C frame | A/B bytes/op | B/C bytes/op | A/B writes/op | B/C writes/op | +| -------------------- | --------- | --------- | ----------- | ----------- | --------- | --------- | ------------ | ------------ | ------------- | ------------- | +| navdrawer-toggle | 0.77 | 1.40 | 0.83 | 0.89 | 1.22 | 1.25 | n/a | n/a | n/a | 1.09 | +| page-mount | 1.16 | 1.11 | 1.26 | 1.12 | 0.81 | 1.17 | n/a | n/a | n/a | 1.06 | +| page-swap | 1.15 | 1.14 | 1.20 | 1.07 | 1.01 | 1.21 | n/a | n/a | n/a | 1.05 | +| portal-focus-text | 0.82 | 1.32 | 0.37 | 1.35 | 3.07 | 1.26 | n/a | n/a | n/a | 1.00 | +| poster-mount | 1.58 | 0.83 | 1.59 | 1.03 | 1.40 | 1.23 | n/a | n/a | n/a | 1.11 | +| poster-swap | 1.48 | 0.90 | 1.40 | 0.93 | 1.30 | 0.91 | n/a | n/a | n/a | 1.11 | +| rows-lr-always | 0.67 | 1.38 | 0.50 | 1.34 | 1.00 | 1.09 | n/a | n/a | n/a | 1.00 | +| rows-lr-auto | 0.71 | 1.17 | 0.49 | 1.60 | 1.08 | 1.11 | n/a | n/a | n/a | 1.00 | +| rows-lr-noshift | 0.47 | 2.13 | 0.79 | 1.55 | 0.57 | 1.33 | n/a | n/a | n/a | 1.00 | +| rows-ud-always | 0.65 | 1.19 | 0.49 | 0.95 | 1.99 | 1.03 | n/a | n/a | n/a | 1.00 | +| rows-ud-auto | 0.67 | 1.32 | 0.69 | 1.06 | 1.46 | 0.58 | n/a | n/a | n/a | 1.00 | +| text-details-panel | 1.45 | 0.79 | 0.64 | 0.78 | 1.41 | 1.76 | n/a | n/a | n/a | 3.63 | +| text-flex-mount-new | 0.94 | 1.24 | 1.19 | 1.39 | 0.73 | 18.30 | n/a | n/a | n/a | 1.11 | +| text-flex-mount-same | 1.49 | 1.28 | 1.47 | 1.21 | 1.68 | 4.41 | n/a | n/a | n/a | 1.11 | +| text-virtual-row | 0.90 | 1.14 | 0.70 | 1.28 | 1.90 | 1.73 | n/a | n/a | n/a | 1.92 | +| thumbnail-focus | 0.69 | 1.06 | 0.63 | 1.03 | 0.91 | 1.12 | n/a | n/a | n/a | n/a | +| virtual-grid | 1.04 | 1.31 | 1.17 | 1.12 | 1.31 | 0.68 | n/a | n/a | n/a | 3.59 | +| virtual-row | 0.86 | 1.45 | 1.01 | 0.90 | 1.09 | 0.63 | n/a | n/a | n/a | 1.73 | + +## Allocation per op (KiB, sampling heap profiler, collected objects included) + +`total` is the app: framework + reactivity + renderer + user. `harness` (the op loop) and `no script` (allocations with no script frame on the stack, mostly Blink objects such as the harness's own MessageEvents) are shown beside it, not in it. + +| scenario | arm | total | framework | reactivity | renderer | user | harness | no script | runs | +| -------------------- | --- | ------ | --------- | ---------- | -------- | ------ | ------- | --------- | ---- | +| navdrawer-toggle | C | 8.66 | 1.47 | 0.72 | 6.41 | 0.07 | 0.00 | 12.70 | 1 | +| page-mount | C | 304.81 | 76.32 | 66.52 | 79.34 | 82.63 | 0.00 | 10.90 | 1 | +| page-swap | C | 635.75 | 160.53 | 132.12 | 180.10 | 163.00 | 0.00 | 11.81 | 1 | +| portal-focus-text | C | 23.63 | 0.30 | 1.06 | 22.25 | 0.02 | 0.00 | 12.57 | 1 | +| poster-mount | C | 23.26 | 5.79 | 3.89 | 12.94 | 0.65 | 0.00 | 8.95 | 1 | +| poster-swap | C | 35.87 | 8.51 | 7.49 | 15.68 | 4.20 | 0.00 | 8.95 | 1 | +| rows-lr-always | C | 11.48 | 0.28 | 0.69 | 10.50 | 0.02 | 0.00 | 12.25 | 1 | +| rows-lr-auto | C | 11.49 | 0.28 | 0.69 | 10.50 | 0.02 | 0.00 | 12.23 | 1 | +| rows-lr-noshift | C | 1.76 | 0.25 | 0.69 | 0.80 | 0.01 | 0.00 | 10.44 | 1 | +| rows-ud-always | C | 67.36 | 0.35 | 0.70 | 66.28 | 0.02 | 0.00 | 12.34 | 1 | +| rows-ud-auto | C | 55.43 | 0.35 | 0.70 | 54.37 | 0.02 | 0.00 | 12.21 | 1 | +| text-details-panel | C | 8.16 | 2.09 | 1.93 | 4.14 | 0.00 | 0.00 | 10.27 | 1 | +| text-flex-mount-new | C | 188.80 | 18.59 | 17.85 | 131.90 | 20.46 | 0.00 | 8.86 | 1 | +| text-flex-mount-same | C | 70.61 | 18.55 | 17.85 | 13.75 | 20.46 | 0.00 | 8.89 | 1 | +| text-virtual-row | C | 30.51 | 2.68 | 2.60 | 25.23 | 0.00 | 0.00 | 12.14 | 1 | +| thumbnail-focus | C | 9.69 | 0.17 | 0.69 | 8.81 | 0.01 | 0.00 | 11.88 | 1 | +| virtual-grid | C | 30.54 | 5.24 | 5.34 | 19.69 | 0.28 | 0.00 | 12.49 | 1 | +| virtual-row | C | 15.72 | 2.55 | 2.44 | 10.71 | 0.02 | 0.00 | 12.21 | 1 | + +Top allocating functions (bytes per op, mean over runs; harness excluded): + +- navdrawer-toggle C: `visit (renderer:1832)` 1024, `merge (framework:195)` 760, `tick (renderer:4800)` 704, `keyOf (renderer:2955)` 691, `(anonymous) (renderer:1848)` 672 +- page-mount C: `PageTile (user:415)` 75320, `createComputation (reactivity:199)` 21814, `ElementNode (framework:1234)` 20962, `createTextNode (renderer:4293)` 20664, `insertChild (framework:1334)` 17468 +- page-swap C: `PageTile (user:415)` 150546, `(anonymous) (renderer:1848)` 53044, `createComputation (reactivity:199)` 43626, `ElementNode (framework:1234)` 41906, `createTextNode (renderer:4293)` 33941 +- portal-focus-text C: `visit (renderer:1832)` 11872, `(anonymous) (renderer:1848)` 3991, `write (renderer:1044)` 2961, `mergeColorProgress (renderer:762)` 1019, `tick (renderer:4800)` 743 +- poster-mount C: `createElement (framework:2428)` 2122, `propsKey (renderer:3137)` 1822, `createComputation (reactivity:199)` 1160, `packUv (renderer:2425)` 1040, `uploadSystem (renderer:2759)` 972 +- poster-swap C: `Poster$1 (user:310)` 4219, `propsKey (renderer:3137)` 3620, `createComputation (reactivity:199)` 2240, `insertChild (framework:1334)` 1596, `createTextNode (renderer:4293)` 1450 +- rows-lr-always C: `visit (renderer:1832)` 7392, `tick (renderer:4800)` 898, `FrameLoop.request (renderer:4780)` 403, `runUpdates (reactivity:262)` 272, `ease (renderer:1014)` 256 +- rows-lr-auto C: `visit (renderer:1832)` 7392, `tick (renderer:4800)` 898, `FrameLoop.request (renderer:4780)` 403, `runUpdates (reactivity:262)` 272, `ease (renderer:1014)` 256 +- rows-lr-noshift C: `runUpdates (reactivity:262)` 272, `premultiplyColorABGR (renderer:753)` 144, `premultiply (renderer:2016)` 108, `(anonymous) (reactivity:268)` 108, `readSignal (reactivity:133)` 100 +- rows-ud-always C: `visit (renderer:1832)` 61407, `(anonymous) (renderer:1848)` 2762, `tick (renderer:4800)` 991, `FrameLoop.request (renderer:4780)` 720, `updateClip (renderer:1988)` 373 +- rows-ud-auto C: `visit (renderer:1832)` 51515, `tick (renderer:4800)` 939, `(anonymous) (renderer:1848)` 689, `FrameLoop.request (renderer:4780)` 567, `updateClip (renderer:1988)` 320 +- text-details-panel C: `layout (framework:286)` 1235, `(anonymous) (renderer:1848)` 881, `emit (renderer:2035)` 608, `runTop (reactivity:240)` 420, `runUpdates (reactivity:262)` 408 +- text-flex-mount-new C: `(anonymous) (renderer:3870)` 66160, `TextTile (user:1098)` 20400, `(anonymous) (renderer:1848)` 13212, `wrapLine (renderer:3654)` 12147, `mapTextLayout (renderer:3595)` 7987 +- text-flex-mount-same C: `TextTile (user:1098)` 20400, `ElementNode (framework:1234)` 5885, `createTextNode (renderer:4293)` 5770, `createComputation (reactivity:199)` 4984, `insertChild (framework:1334)` 4816 +- text-virtual-row C: `visit (renderer:1832)` 18293, `(anonymous) (renderer:1848)` 3639, `layout (framework:286)` 1187, `(anonymous) (framework:2748)` 951, `Animation (renderer:864)` 736 +- thumbnail-focus C: `(anonymous) (renderer:1848)` 3877, `visit (renderer:1832)` 988, `propsKey (renderer:3137)` 765, `tick (renderer:4800)` 734, `uploadSystem (renderer:2759)` 719 +- virtual-grid C: `visit (renderer:1832)` 6259, `(anonymous) (renderer:1848)` 4328, `(anonymous) (framework:2748)` 2749, `ease (renderer:1014)` 1779, `reconcileArrays (reactivity:586)` 1389 +- virtual-row C: `visit (renderer:1832)` 5958, `layout (framework:286)` 1078, `(anonymous) (framework:2748)` 986, `tick (renderer:4800)` 887, `Animation (renderer:864)` 736 + +## Counts per op (instrumented build; its timings are not reported) + +`node writes` and `shader writes` are setter calls on renderer nodes and on shader `props` made by app code (Solid and the scenario). A write made while renderer code is on the stack (a renderer frame, `createNode`/`createTextNode`/`createShader`/`animate`, another setter, a texture's event dispatch) is not counted; the app's listeners that the renderer calls (`loaded`, `idle`) are app code. `in frames`: the part of those writes made during a renderer frame (Solid's flex on `loaded`). Creation is counted on its own, the same way on both majors: `created` nodes and their `creation props` (keys with a defined value in the bag passed to `createNode`/`createTextNode`; renderer v2 applies the bag through its setters, v1 in its constructor). `loaded`: emitted / heard by a listener (v1 emits on every text layout and texture load, v2 queues one only for a node with a listener). + +| scenario | arm | flex passes | node writes | shader writes | in frames | animations | walks/drawn frame | drawn frames | created | creation props | loaded text (emitted / heard) | loaded other (emitted / heard) | runs | +| -------------------- | ----------- | ----------- | ----------- | ------------- | --------- | ---------- | ----------------- | ------------ | ------- | -------------- | ----------------------------- | ------------------------------ | ---- | +| navdrawer-toggle | B | 0.0 | 25.0 | 2.0 | 0.0 | 2.0 | 1.00 | 15.5 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| navdrawer-toggle | C | 0.0 | 23.0 | 1.0 | 0.0 | 2.0 | 1.00 | 15.5 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| page-mount | B | 4.0 | 78.0 | 2.0 | 0.0 | 1.0 | 1.00 | 6.8 | 291.0 | 2946.5 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| page-mount | B [create] | 8.0 | 156.0 | 4.0 | 0.0 | 2.0 | 1.00 | 12.7 | 582.0 | 5893.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| page-mount | B [destroy] | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| page-mount | C | 4.0 | 73.5 | 1.5 | 0.0 | 1.0 | 1.00 | 6.8 | 291.0 | 2946.5 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| page-mount | C [create] | 8.0 | 147.0 | 3.0 | 0.0 | 2.0 | 1.00 | 12.6 | 582.0 | 5893.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| page-mount | C [destroy] | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| page-swap | B | 8.0 | 156.0 | 4.0 | 0.0 | 2.0 | 1.00 | 12.7 | 582.0 | 5893.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| page-swap | C | 8.0 | 148.0 | 3.0 | 0.0 | 2.0 | 1.00 | 12.6 | 582.0 | 5893.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| portal-focus-text | B | 0.0 | 6.0 | 0.0 | 0.0 | 3.0 | 1.00 | 15.5 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| portal-focus-text | C | 0.0 | 6.0 | 0.0 | 0.0 | 3.0 | 1.00 | 15.5 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| poster-mount | B | 0.5 | 5.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 10.0 | 115.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| poster-mount | C | 0.5 | 4.5 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 10.0 | 115.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| poster-swap | B | 1.0 | 10.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 20.0 | 230.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| poster-swap | C | 1.0 | 9.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 20.0 | 230.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-lr-always | B | 0.0 | 2.0 | 0.0 | 0.0 | 1.0 | 1.00 | 11.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-lr-always | C | 0.0 | 2.0 | 0.0 | 0.0 | 1.0 | 1.00 | 11.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-lr-auto | B | 0.0 | 2.0 | 0.0 | 0.0 | 1.0 | 1.00 | 11.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-lr-auto | C | 0.0 | 2.0 | 0.0 | 0.0 | 1.0 | 1.00 | 11.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-lr-noshift | B | 0.0 | 2.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-lr-noshift | C | 0.0 | 2.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-ud-always | B | 0.0 | 2.0 | 0.0 | 0.0 | 1.0 | 1.00 | 18.5 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-ud-always | C | 0.0 | 2.0 | 0.0 | 0.0 | 1.0 | 1.00 | 18.5 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-ud-auto | B | 0.0 | 2.0 | 0.0 | 0.0 | 0.8 | 1.00 | 14.6 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| rows-ud-auto | C | 0.0 | 2.0 | 0.0 | 0.0 | 0.8 | 1.00 | 14.6 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| text-details-panel | B | 7.0 | 54.4 | 0.0 | 44.4 | 0.0 | 2.00 | 1.0 | 0.0 | 0.0 | 5.0 / 5.0 | 0.0 / 0.0 | 1 | +| text-details-panel | C | 3.0 | 15.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| text-flex-mount-new | B | 42.0 | 91.0 | 0.0 | 70.0 | 0.0 | 2.00 | 1.0 | 81.0 | 646.0 | 20.0 / 20.0 | 0.0 / 0.0 | 1 | +| text-flex-mount-new | C | 21.0 | 82.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 81.0 | 646.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| text-flex-mount-same | B | 42.0 | 91.0 | 0.0 | 70.0 | 0.0 | 2.00 | 1.0 | 81.0 | 646.0 | 20.0 / 20.0 | 0.0 / 0.0 | 1 | +| text-flex-mount-same | C | 21.0 | 82.0 | 0.0 | 0.0 | 0.0 | 1.00 | 1.0 | 81.0 | 646.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| text-virtual-row | B | 4.2 | 29.7 | 0.0 | 6.0 | 1.0 | 1.03 | 15.5 | 0.0 | 0.0 | 1.9 / 1.9 | 0.0 / 0.0 | 1 | +| text-virtual-row | C | 1.9 | 15.5 | 0.0 | 0.0 | 1.0 | 1.00 | 15.5 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| thumbnail-focus | B | 0.0 | 0.0 | 6.2 | 0.0 | 2.0 | 1.00 | 15.5 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| thumbnail-focus | C | 0.0 | 0.0 | 6.0 | 0.0 | 2.0 | 1.00 | 15.5 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| virtual-grid | B | 2.0 | 179.0 | 6.0 | 0.0 | 2.3 | 1.00 | 15.5 | 0.9 | 8.8 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| virtual-grid | C | 1.0 | 49.9 | 6.0 | 0.0 | 2.3 | 1.00 | 15.5 | 0.9 | 8.8 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| virtual-row | B | 1.9 | 26.1 | 0.0 | 0.0 | 3.0 | 1.00 | 15.5 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | +| virtual-row | C | 0.9 | 15.2 | 0.0 | 0.0 | 3.0 | 1.00 | 15.6 | 0.0 | 0.0 | 0.0 / 0.0 | 0.0 / 0.0 | 1 | + +### Text metrics per op (count mode) + +| scenario | arm | text layout calls | text layout ms | layout cache hit rate | frames to final layout | ms to final layout | +| -------------------- | --- | ----------------- | -------------- | --------------------- | ---------------------- | ------------------ | +| page-mount | B | 31.5 | 0.138 | 1.00 | 1.0 | 12.0 | +| page-mount | C | 31.5 | 0.008 | 1.00 | 1.0 | 10.5 | +| page-swap | B | 63.0 | 0.262 | 1.00 | 1.0 | 11.1 | +| page-swap | C | 63.0 | 0.075 | 1.00 | 1.0 | 10.6 | +| text-details-panel | B | 7.0 | 0.018 | 1.00 | 1.0 | 6.6 | +| text-details-panel | C | 7.0 | 0.012 | 1.00 | 1.0 | 6.8 | +| text-flex-mount-new | B | 20.0 | 0.314 | 0.00 | 1.0 | 7.5 | +| text-flex-mount-new | C | 40.0 | 0.933 | 0.00 | 0.0 | 1.7 | +| text-flex-mount-same | B | 20.0 | 0.029 | 1.00 | 1.0 | 7.4 | +| text-flex-mount-same | C | 40.0 | 0.035 | 1.00 | 0.0 | 0.6 | +| text-virtual-row | B | 1.9 | 0.016 | 1.00 | 1.0 | 6.0 | +| text-virtual-row | C | 1.9 | 0.089 | 1.00 | 0.0 | 0.1 | + +## Profile: self time per op (ms, mean over runs) + +### page-swap C + +By chunk: framework 5.504, renderer 4.678, (program) 2.221, reactivity 1.053, harness 0.554, (garbage collector) 0.423, user 0.289, native 0.174 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------ | ---------- | +| 1 | `set style (framework:1539)` | 2.822 | +| 2 | `(program)` | 2.221 | +| 3 | `render (framework:1760)` | 0.807 | +| 4 | `getError [native] (renderer)` | 0.471 | +| 5 | `(garbage collector)` | 0.423 | +| 6 | `visit (renderer:1832)` | 0.360 | +| 7 | `alloc (renderer:621)` | 0.274 | +| 8 | `destroyNode (renderer:4510)` | 0.266 | +| 9 | `wrapped (harness:78)` | 0.205 | +| 10 | `(anonymous) (renderer:4144)` | 0.197 | +| 11 | `setProperty (framework:2435)` | 0.192 | +| 12 | `markDirty (renderer:666)` | 0.191 | +| 13 | `emitText (renderer:4031)` | 0.176 | +| 14 | `get (renderer:3802)` | 0.175 | +| 15 | `mergeProps (reactivity:423)` | 0.168 | +| 16 | `replayGroup (framework:1028)` | 0.167 | +| 17 | `create (renderer:2973)` | 0.156 | +| 18 | `requestAnimationFrame [native] (harness)` | 0.149 | +| 19 | `(anonymous) (reactivity:643)` | 0.143 | +| 20 | `PageTile (user:415)` | 0.140 | + +### rows-ud-auto C + +By chunk: (program) 1.875, renderer 0.958, harness 0.178, framework 0.133, native 0.121, (garbage collector) 0.065, reactivity 0.044 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------- | ---------- | +| 1 | `(program)` | 1.875 | +| 2 | `getError [native] (renderer)` | 0.418 | +| 3 | `requestAnimationFrame [native] (renderer)` | 0.123 | +| 4 | `(anonymous) [native] (native)` | 0.077 | +| 5 | `(garbage collector)` | 0.065 | +| 6 | `visit (renderer:1832)` | 0.060 | +| 7 | `dispatchEvent [native] (harness)` | 0.052 | +| 8 | `(anonymous) (renderer:1848)` | 0.042 | +| 9 | `clear [native] (renderer)` | 0.037 | +| 10 | `propagateKeyPress (framework:644)` | 0.035 | +| 11 | `run (renderer:1797)` | 0.034 | +| 12 | `classify (renderer:2001)` | 0.031 | +| 13 | `wrapped (harness:78)` | 0.028 | +| 14 | `setTimeout [native] (renderer)` | 0.024 | +| 15 | `evaluate [native] (native)` | 0.020 | +| 16 | `settle (harness:174)` | 0.019 | +| 17 | `updateFocusPath (framework:591)` | 0.018 | +| 18 | `now (renderer:3331)` | 0.017 | +| 19 | `emit (renderer:2035)` | 0.015 | +| 20 | `register (renderer:2136)` | 0.015 | + +### thumbnail-focus C + +By chunk: (program) 1.869, renderer 0.958, (garbage collector) 0.222, harness 0.199, framework 0.165, native 0.116, reactivity 0.018, user 0.001 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------- | ---------- | +| 1 | `(program)` | 1.869 | +| 2 | `getError [native] (renderer)` | 0.474 | +| 3 | `(garbage collector)` | 0.222 | +| 4 | `requestAnimationFrame [native] (renderer)` | 0.115 | +| 5 | `(anonymous) [native] (native)` | 0.092 | +| 6 | `setTimeout [native] (renderer)` | 0.040 | +| 7 | `wrapped (harness:78)` | 0.035 | +| 8 | `_applyStates (framework:1690)` | 0.031 | +| 9 | `writeShaderGroup (framework:1136)` | 0.030 | +| 10 | `FrameLoop.request (renderer:4780)` | 0.027 | +| 11 | `uniform4fv [native] (renderer)` | 0.026 | +| 12 | `clear [native] (renderer)` | 0.025 | +| 13 | `KeyboardEvent [native] (harness)` | 0.023 | +| 14 | `now (renderer:3331)` | 0.022 | +| 15 | `add (framework:189)` | 0.022 | +| 16 | `postMessage [native] (harness)` | 0.019 | +| 17 | `bindTexture [native] (renderer)` | 0.018 | +| 18 | `(anonymous) (harness:322)` | 0.018 | +| 19 | `frame (renderer:5733)` | 0.018 | +| 20 | `keyEvent (harness:228)` | 0.018 | + +### virtual-grid C + +By chunk: (program) 1.817, renderer 1.027, framework 0.509, harness 0.243, (garbage collector) 0.166, reactivity 0.135, native 0.126, user 0.033 + +| # | function (chunk:line) | self ms/op | +| --- | ------------------------------------------- | ---------- | +| 1 | `(program)` | 1.817 | +| 2 | `getError [native] (renderer)` | 0.402 | +| 3 | `(garbage collector)` | 0.166 | +| 4 | `wrapped (harness:78)` | 0.093 | +| 5 | `(anonymous) [native] (native)` | 0.088 | +| 6 | `requestAnimationFrame [native] (renderer)` | 0.080 | +| 7 | `replayGroup (framework:1028)` | 0.046 | +| 8 | `(anonymous) (framework:2748)` | 0.039 | +| 9 | `clear [native] (harness)` | 0.036 | +| 10 | `propsKey (renderer:3137)` | 0.033 | +| 11 | `create (renderer:2973)` | 0.030 | +| 12 | `cleanNode (reactivity:346)` | 0.028 | +| 13 | `has (framework:183)` | 0.028 | +| 14 | `removeChild (framework:1355)` | 0.027 | +| 15 | `now [native] (harness)` | 0.026 | +| 16 | `bufferData [native] (renderer)` | 0.025 | +| 17 | `updateFocusPath (framework:591)` | 0.023 | +| 18 | `postMessage [native] (harness)` | 0.022 | +| 19 | `drawElements [native] (renderer)` | 0.022 | +| 20 | `setTimeout [native] (renderer)` | 0.022 | diff --git a/docs/perf/results/routes-2026-10-03.md b/docs/perf/results/routes-2026-10-03.md new file mode 100644 index 00000000..901c76d3 --- /dev/null +++ b/docs/perf/results/routes-2026-10-03.md @@ -0,0 +1,136 @@ +# Route creation times + +Generated by `node bench/demo/route-times.mjs` (2026-10-03). Method: the header of [bench/demo/route-times.mjs](../../../bench/demo/route-times.mjs). + +- Arms: A (solid 71c170f, renderer npm 1.9.3); B (solid f1c8ab0, renderer faf4b9f); C (solid fe5c3f9, renderer faf4b9f); demo c202f2db +- 3 visits per route and arm, each in a fresh page started on `#/does-not-exist`; CPU throttling 6x; TMDB fixtures; fps heartbeat off; settled = no drawn frame for 500 ms and no request in flight, at most 12 s +- 141.0.7390.37, ANGLE (Apple, ANGLE Metal Renderer: Apple M4 Pro, Unspecified Version); 1-minute load average 7.4 at the start, 6.5 at the end + +## Time from the hash change to the page settling (ms, median of the visits, min-max in parentheses) + +| route | A | B | C | C/B | B/A | +| --------------------------------- | ---------------- | ---------------- | ---------------- | ---- | ---- | +| #/ | 662 (660-668) | 674 (673-688) | 668 (664-673) | 0.99 | 1.02 | +| #/browse/all | 626 (617-649) | 651 (637-651) | 640 (637-645) | 0.98 | 1.04 | +| #/examples | 312 (311-320) | 327 (316-328) | 321 (319-324) | 0.98 | 1.05 | +| #/examples/tmdb | 261 (249-301) | 487 (485-488) | 486 (476-516) | 1.00 | 1.87 | +| #/loops | 282 (273-284) | 292 (280-298) | 287 (287-297) | 0.99 | 1.03 | +| #/infinite | 575 (571-585) | 565 (562-568) | 569 (561-569) | 1.01 | 0.98 | +| #/tmdbgrid | 361 (353-364) | 364 (354-383) | 363 (357-376) | 1.00 | 1.01 | +| #/virtual | 300 (278-302) | 309 (303-309) | 312 (304-317) | 1.01 | 1.03 | +| #/destroy | 582 (574-594) | 583 (581-587) | 585 (583-590) | 1.00 | 1.00 | +| #/grid | 309 (307-319) | 310 (310-631) | 315 (302-661) | 1.02 | 1.00 | +| #/matrix | 86 (83-95) | 88 (87-94) | 90 (86-107) | 1.03 | 1.02 | +| #/text | 127 (122-129) | 111 (111-117) | 111 (109-115) | 1.00 | 0.88 | +| #/firebolt | 105 (104-105) | 101 (99-102) | 100 (96-106) | 1.00 | 0.96 | +| #/login | 125 (123-129) | 116 (114-121) | 116 (108-128) | 0.99 | 0.93 | +| #/nested | 103 (95-117) | 99 (95-103) | 93 (93-109) | 0.94 | 0.96 | +| #/textposter | 203 (179-563) | 255 (164-316) | 190 (174-322) | 0.75 | 1.26 | +| #/textcentering | 112 (112-120) | 110 (110-111) | 107 (107-107) | 0.98 | 0.98 | +| #/countdown | no idle | no idle | no idle | - | - | +| #/custombuttons | 274 (272-287) | 268 (267-276) | 269 (266-277) | 1.00 | 0.98 | +| #/positioning | no idle | no idle | no idle | - | - | +| #/layout | 98 (96-99) | 90 (88-90) | 95 (90-99) | 1.05 | 0.91 | +| #/focusbasics | 95 (92-101) | 89 (88-91) | 89 (88-89) | 0.99 | 0.94 | +| #/transitions | 85 (80-95) | 79 (78-85) | 82 (80-84) | 1.03 | 0.93 | +| #/components | 106 (95-107) | 90 (90-90) | 92 (89-93) | 1.02 | 0.85 | +| #/focushandling | 90 (87-93) | 89 (87-95) | 86 (86-88) | 0.97 | 1.00 | +| #/keyhandling | 104 (96-109) | 91 (86-99) | 89 (88-94) | 0.97 | 0.88 | +| #/gradients | 91 (87-91) | 82 (81-86) | 84 (84-88) | 1.04 | 0.90 | +| #/flex | 89 (89-112) | 95 (90-99) | 90 (88-92) | 0.94 | 1.07 | +| #/create | 4077 (4077-4086) | 4071 (4066-4072) | 4074 (4062-4076) | 1.00 | 1.00 | +| #/viewport | 1318 (1317-1323) | 1309 (1308-1315) | 1311 (1309-1314) | 1.00 | 0.99 | +| #/flexsize | 93 (88-102) | 94 (90-96) | 93 (93-94) | 0.99 | 1.01 | +| #/flexmenu | 92 (90-95) | 82 (82-85) | 87 (83-87) | 1.06 | 0.89 | +| #/flexcolumnsize | 96 (93-99) | 89 (89-89) | 87 (85-97) | 0.98 | 0.93 | +| #/flexcolumn | 100 (90-101) | 90 (88-90) | 88 (86-92) | 0.98 | 0.89 | +| #/flexgrow | 87 (86-90) | 90 (86-90) | 92 (88-93) | 1.02 | 1.03 | +| #/flexjustifywidth | 293 (289-304) | 319 (314-324) | 321 (321-322) | 1.01 | 1.09 | +| #/keepalive | 320 (314-333) | 314 (307-317) | 322 (315-322) | 1.03 | 0.98 | +| #/suspense | 323 (319-326) | 313 (307-314) | 307 (307-307) | 0.98 | 0.97 | +| #/superflex | 411 (407-422) | 409 (405-414) | 414 (414-419) | 1.01 | 1.00 | +| #/tags | 94 (92-96) | 87 (84-89) | 88 (87-93) | 1.02 | 0.92 | +| #/buttonsmaterial | 103 (100-114) | 101 (89-106) | 99 (90-101) | 0.98 | 0.98 | +| #/entity/movie/1013 | 639 (626-644) | 636 (623-647) | 636 (633-638) | 1.00 | 1.00 | +| #/entity/tv/1013 | 622 (621-629) | 635 (624-646) | 634 (629-636) | 1.00 | 1.02 | +| #/entity/people/1013 | 131 (125-151) | 353 (348-354) | 353 (353-357) | 1.00 | 2.69 | +| #/image-performance | 146 (140-148) | 149 (146-157) | 148 (136-149) | 0.99 | 1.02 | +| #/large-image-performance | 165 (163-560) | 146 (145-146) | 153 (146-162) | 1.05 | 0.89 | +| #/mixed-image-performance | 138 (126-216) | 134 (124-153) | 132 (123-151) | 0.98 | 0.97 | +| #/texture-compression-performance | 134 (132-149) | 143 (135-151) | 151 (142-154) | 1.05 | 1.07 | +| #/complexflex | 761 (751-766) | 722 (718-730) | 716 (710-736) | 0.99 | 0.95 | +| #/complexflexcaps | 112 (110-113) | 107 (103-120) | 106 (105-111) | 0.99 | 0.95 | +| #/benchmark | 752 (747-752) | 763 (747-774) | 760 (751-770) | 1.00 | 1.01 | +| #/versions | 91 (85-93) | 84 (81-88) | 92 (85-101) | 1.10 | 0.92 | +| #/does-not-exist | 11 (7-12) | 7 (7-7) | 7 (6-7) | 0.97 | 0.61 | +| **sum of 51 routes** | **17273** | **17664** | **17600** | 1.00 | 1.02 | + +Left out of the sums (no settle time in at least one arm): #/countdown, #/positioning. + +## Main-thread busy time over the same window (ms of task time, throttled; median, min-max) + +The settle time includes timers and animations (a debounce, a 250 ms transition): it is what a person waits. The busy time is what the page spends on the main thread (CDP `TaskDuration`, sampled at the last drawn frame): script, renderer frames, GC. It is the figure to compare between arms. + +| route | A | B | C | C/B | B/A | +| --------------------------------- | ------------- | ------------- | ------------- | ---- | ---- | +| #/ | 119 (113-123) | 104 (103-136) | 97 (91-113) | 0.93 | 0.87 | +| #/browse/all | 139 (97-159) | 136 (94-150) | 105 (88-137) | 0.77 | 0.98 | +| #/examples | 73 (72-84) | 69 (68-83) | 70 (65-74) | 1.02 | 0.94 | +| #/examples/tmdb | 122 (122-128) | 127 (119-143) | 162 (127-179) | 1.28 | 1.04 | +| #/loops | 85 (80-110) | 86 (80-96) | 86 (85-92) | 1.00 | 1.02 | +| #/infinite | 83 (79-100) | 82 (80-82) | 84 (77-86) | 1.03 | 0.98 | +| #/tmdbgrid | 156 (153-164) | 152 (147-191) | 147 (147-172) | 0.97 | 0.98 | +| #/virtual | 100 (99-112) | 115 (105-122) | 107 (104-127) | 0.93 | 1.15 | +| #/destroy | 78 (70-116) | 81 (77-85) | 85 (79-87) | 1.05 | 1.03 | +| #/grid | 58 (53-59) | 54 (47-56) | 51 (48-55) | 0.95 | 0.93 | +| #/matrix | 28 (26-31) | 29 (28-33) | 28 (28-35) | 0.97 | 1.04 | +| #/text | 39 (39-39) | 39 (35-41) | 38 (35-40) | 0.96 | 1.01 | +| #/firebolt | 36 (35-39) | 38 (36-39) | 36 (35-38) | 0.93 | 1.05 | +| #/login | 64 (61-66) | 56 (54-57) | 53 (52-64) | 0.94 | 0.88 | +| #/nested | 47 (38-103) | 38 (36-39) | 35 (34-41) | 0.93 | 0.80 | +| #/textposter | 57 (55-57) | 48 (47-54) | 50 (49-51) | 1.03 | 0.84 | +| #/textcentering | 53 (49-57) | 48 (45-52) | 50 (50-51) | 1.04 | 0.90 | +| #/countdown | no idle | no idle | no idle | - | - | +| #/custombuttons | 62 (60-156) | 66 (62-71) | 63 (59-66) | 0.96 | 1.06 | +| #/positioning | no idle | no idle | no idle | - | - | +| #/layout | 38 (35-38) | 34 (33-35) | 37 (35-39) | 1.09 | 0.89 | +| #/focusbasics | 35 (33-37) | 31 (31-33) | 32 (32-33) | 1.05 | 0.87 | +| #/transitions | 23 (18-24) | 23 (23-26) | 25 (24-26) | 1.09 | 1.00 | +| #/components | 37 (35-38) | 34 (33-36) | 35 (31-35) | 1.01 | 0.93 | +| #/focushandling | 28 (27-30) | 29 (28-30) | 28 (27-31) | 0.97 | 1.02 | +| #/keyhandling | 37 (36-40) | 32 (29-33) | 34 (32-35) | 1.05 | 0.87 | +| #/gradients | 21 (21-25) | 24 (23-25) | 25 (23-26) | 1.05 | 1.12 | +| #/flex | 32 (28-36) | 33 (31-38) | 33 (33-34) | 1.01 | 1.04 | +| #/create | 196 (189-233) | 153 (152-167) | 173 (166-177) | 1.13 | 0.78 | +| #/viewport | 63 (63-66) | 68 (61-74) | 68 (62-79) | 0.99 | 1.08 | +| #/flexsize | 32 (32-34) | 37 (36-38) | 34 (33-34) | 0.90 | 1.16 | +| #/flexmenu | 27 (26-29) | 27 (26-28) | 27 (26-27) | 0.98 | 1.02 | +| #/flexcolumnsize | 29 (29-31) | 31 (30-32) | 30 (28-37) | 0.95 | 1.06 | +| #/flexcolumn | 29 (28-32) | 31 (31-32) | 32 (32-32) | 1.03 | 1.09 | +| #/flexgrow | 28 (26-30) | 29 (26-29) | 29 (29-32) | 1.03 | 1.01 | +| #/flexjustifywidth | 78 (74-84) | 67 (67-69) | 68 (64-73) | 1.01 | 0.86 | +| #/keepalive | 38 (36-39) | 35 (34-39) | 33 (32-36) | 0.93 | 0.94 | +| #/suspense | 39 (34-52) | 36 (34-36) | 36 (34-36) | 1.00 | 0.93 | +| #/superflex | 45 (44-48) | 50 (42-53) | 47 (42-49) | 0.94 | 1.13 | +| #/tags | 33 (32-33) | 32 (32-33) | 31 (30-33) | 0.96 | 0.99 | +| #/buttonsmaterial | 34 (32-35) | 34 (29-35) | 32 (30-34) | 0.94 | 0.99 | +| #/entity/movie/1013 | 150 (115-159) | 105 (102-121) | 111 (110-120) | 1.06 | 0.69 | +| #/entity/tv/1013 | 115 (113-123) | 110 (107-115) | 110 (110-116) | 1.00 | 0.96 | +| #/entity/people/1013 | 50 (47-53) | 75 (73-76) | 77 (73-79) | 1.02 | 1.49 | +| #/image-performance | 65 (62-67) | 61 (60-64) | 59 (57-60) | 0.97 | 0.94 | +| #/large-image-performance | 70 (65-70) | 69 (68-71) | 74 (69-78) | 1.07 | 0.99 | +| #/mixed-image-performance | 56 (54-60) | 62 (52-73) | 61 (59-78) | 0.99 | 1.10 | +| #/texture-compression-performance | 68 (67-69) | 70 (64-79) | 74 (74-82) | 1.05 | 1.03 | +| #/complexflex | 133 (129-136) | 116 (109-128) | 113 (108-118) | 0.97 | 0.87 | +| #/complexflexcaps | 56 (54-58) | 54 (50-55) | 54 (51-55) | 0.99 | 0.96 | +| #/benchmark | 167 (155-175) | 162 (146-191) | 156 (147-164) | 0.96 | 0.97 | +| #/versions | 27 (27-28) | 29 (28-30) | 30 (28-31) | 1.01 | 1.08 | +| #/does-not-exist | 9 (8-9) | 10 (10-10) | 9 (9-9) | 0.93 | 1.14 | +| **sum of 51 routes** | **3289** | **3163** | **3162** | 1.00 | 0.96 | + +## Errors logged while timing + +- #/grid A: console: [GLOBAL_REJECTION] No compatible text renderer found for Roboto600 +- #/grid A: pageerror: No compatible text renderer found for Roboto600 +- #/entity/people/1013 A: console: [GLOBAL_REJECTION] No compatible text renderer found for Robotonormal +- #/entity/people/1013 A: pageerror: No compatible text renderer found for Robotonormal diff --git a/docs/perf/results/routes-2026-10-04.md b/docs/perf/results/routes-2026-10-04.md new file mode 100644 index 00000000..38c3cf55 --- /dev/null +++ b/docs/perf/results/routes-2026-10-04.md @@ -0,0 +1,136 @@ +# Route creation times + +Generated by `node bench/demo/route-times.mjs` (2026-10-04). Method: the header of [bench/demo/route-times.mjs](../../../bench/demo/route-times.mjs). + +- Arms: A (solid 71c170f, renderer npm 1.9.3); B (solid f1c8ab0, renderer faf4b9f); C (solid 8886583, renderer 6392ce4); demo e8918364 +- 3 visits per route and arm, each in a fresh page started on `#/does-not-exist`; CPU throttling 6x; TMDB fixtures; fps heartbeat off; settled = no drawn frame for 500 ms and no request in flight, at most 20 s +- 141.0.7390.37, ANGLE (Apple, ANGLE Metal Renderer: Apple M4 Pro, Unspecified Version); 1-minute load average 0.8 at the start, 1.1 at the end + +## Time from the hash change to the page settling (ms, median of the visits, min-max in parentheses) + +| route | A | B | C | C/B | B/A | +| --------------------------------- | ---------------- | ---------------- | ---------------- | ---- | ---- | +| #/ | 666 (666-675) | 679 (675-682) | 681 (680-689) | 1.00 | 1.02 | +| #/browse/all | 634 (631-645) | 649 (640-656) | 647 (644-651) | 1.00 | 1.02 | +| #/examples | 319 (311-321) | 334 (330-336) | 339 (338-341) | 1.02 | 1.05 | +| #/examples/tmdb | 282 (266-289) | 500 (493-504) | 511 (508-514) | 1.02 | 1.77 | +| #/loops | 288 (288-302) | 293 (291-295) | 291 (282-298) | 1.00 | 1.02 | +| #/infinite | 591 (588-595) | 578 (574-588) | 580 (577-581) | 1.00 | 0.98 | +| #/tmdbgrid | 364 (358-380) | 373 (366-376) | 366 (359-374) | 0.98 | 1.02 | +| #/virtual | 307 (292-309) | 314 (312-325) | 314 (312-321) | 1.00 | 1.02 | +| #/destroy | 598 (593-602) | 590 (586-594) | 598 (591-599) | 1.01 | 0.99 | +| #/grid | 607 (319-675) | 599 (599-914) | 898 (659-950) | 1.50 | 0.99 | +| #/matrix | 112 (105-112) | 99 (99-102) | 99 (87-101) | 1.00 | 0.89 | +| #/text | 115 (111-124) | 114 (110-116) | 109 (108-109) | 0.96 | 0.99 | +| #/firebolt | 103 (100-103) | 103 (90-106) | 105 (102-105) | 1.02 | 1.01 | +| #/login | 126 (125-127) | 120 (114-122) | 120 (120-124) | 1.00 | 0.96 | +| #/nested | 117 (111-118) | 105 (104-108) | 109 (106-110) | 1.03 | 0.90 | +| #/textposter | 230 (172-448) | 197 (175-351) | 224 (189-393) | 1.14 | 0.85 | +| #/textcentering | 121 (118-126) | 116 (116-118) | 114 (108-115) | 0.98 | 0.95 | +| #/countdown | no idle | no idle | no idle | - | - | +| #/custombuttons | 279 (279-285) | 279 (277-283) | 282 (276-284) | 1.01 | 1.00 | +| #/positioning | no idle | no idle | no idle | - | - | +| #/layout | 109 (107-111) | 105 (104-106) | 105 (104-106) | 1.00 | 0.96 | +| #/focusbasics | 106 (104-108) | 103 (102-105) | 105 (105-106) | 1.02 | 0.98 | +| #/transitions | 97 (94-98) | 89 (83-96) | 91 (90-100) | 1.03 | 0.92 | +| #/components | 109 (107-126) | 94 (87-101) | 104 (102-105) | 1.10 | 0.86 | +| #/focushandling | 100 (84-107) | 96 (92-98) | 100 (99-101) | 1.04 | 0.96 | +| #/keyhandling | 108 (104-111) | 96 (91-104) | 107 (105-108) | 1.11 | 0.89 | +| #/gradients | 98 (94-99) | 95 (94-98) | 96 (95-97) | 1.02 | 0.96 | +| #/flex | 102 (100-106) | 106 (103-107) | 101 (101-101) | 0.95 | 1.03 | +| #/create | 4085 (4085-4092) | 4085 (4078-4088) | 4079 (4074-4084) | 1.00 | 1.00 | +| #/viewport | 1338 (1331-1340) | 1328 (1324-1331) | 1327 (1324-1330) | 1.00 | 0.99 | +| #/flexsize | 103 (101-106) | 105 (104-109) | 103 (98-105) | 0.99 | 1.02 | +| #/flexmenu | 100 (99-105) | 98 (98-99) | 98 (87-98) | 1.00 | 0.98 | +| #/flexcolumnsize | 102 (99-119) | 102 (100-105) | 101 (97-104) | 0.99 | 0.99 | +| #/flexcolumn | 107 (106-108) | 104 (101-104) | 104 (102-104) | 1.01 | 0.97 | +| #/flexgrow | 103 (95-104) | 99 (99-100) | 98 (91-100) | 0.99 | 0.97 | +| #/flexjustifywidth | 309 (307-311) | 325 (321-333) | 338 (329-339) | 1.04 | 1.05 | +| #/keepalive | 329 (316-330) | 326 (324-326) | 326 (321-334) | 1.00 | 0.99 | +| #/suspense | 343 (317-345) | 328 (322-331) | 324 (324-331) | 0.99 | 0.96 | +| #/superflex | 439 (423-442) | 436 (425-437) | 433 (429-437) | 0.99 | 0.99 | +| #/tags | 106 (104-107) | 103 (102-103) | 101 (100-102) | 0.98 | 0.97 | +| #/buttonsmaterial | 104 (102-113) | 98 (96-99) | 99 (99-101) | 1.01 | 0.95 | +| #/entity/movie/1013 | 642 (631-644) | 650 (646-650) | 642 (642-649) | 0.99 | 1.01 | +| #/entity/tv/1013 | 644 (634-661) | 640 (622-646) | 649 (648-653) | 1.01 | 0.99 | +| #/entity/people/1013 | 144 (141-167) | 361 (352-379) | 357 (350-373) | 0.99 | 2.52 | +| #/image-performance | 147 (145-154) | 154 (152-155) | 155 (147-156) | 1.00 | 1.05 | +| #/large-image-performance | 177 (162-580) | 157 (152-166) | 168 (166-170) | 1.07 | 0.89 | +| #/mixed-image-performance | 163 (142-204) | 140 (138-142) | 137 (136-138) | 0.98 | 0.86 | +| #/texture-compression-performance | 144 (143-149) | 143 (142-151) | 147 (133-150) | 1.03 | 1.00 | +| #/complexflex | 752 (751-758) | 729 (728-736) | 725 (725-726) | 0.99 | 0.97 | +| #/complexflexcaps | 122 (118-123) | 118 (118-120) | 115 (111-116) | 0.97 | 0.97 | +| #/benchmark | 757 (754-797) | 762 (756-777) | 771 (770-790) | 1.01 | 1.01 | +| #/versions | 103 (102-105) | 101 (97-103) | 99 (98-100) | 0.98 | 0.98 | +| #/does-not-exist | 17 (16-26) | 14 (13-15) | 14 (14-14) | 1.00 | 0.79 | +| **sum of 51 routes** | **18067** | **18330** | **18711** | 1.02 | 1.01 | + +Left out of the sums (no settle time in at least one arm): #/countdown, #/positioning. + +## Main-thread busy time over the same window (ms of task time, throttled; median, min-max) + +The settle time includes timers and animations (a debounce, a 250 ms transition): it is what a person waits. The busy time is what the page spends on the main thread (CDP `TaskDuration`, sampled at the last drawn frame): script, renderer frames, GC. It is the figure to compare between arms. + +| route | A | B | C | C/B | B/A | +| --------------------------------- | ------------- | ------------- | ------------- | ---- | ---- | +| #/ | 93 (87-95) | 92 (86-92) | 97 (95-104) | 1.06 | 0.98 | +| #/browse/all | 90 (89-95) | 91 (89-93) | 92 (88-97) | 1.01 | 1.01 | +| #/examples | 68 (64-70) | 60 (57-66) | 69 (68-71) | 1.14 | 0.89 | +| #/examples/tmdb | 116 (114-126) | 127 (120-127) | 131 (122-132) | 1.04 | 1.09 | +| #/loops | 86 (85-89) | 79 (79-84) | 86 (83-89) | 1.09 | 0.92 | +| #/infinite | 82 (78-86) | 75 (73-86) | 82 (80-87) | 1.09 | 0.91 | +| #/tmdbgrid | 161 (147-161) | 150 (149-155) | 151 (145-157) | 1.00 | 0.93 | +| #/virtual | 101 (99-102) | 105 (105-111) | 101 (96-104) | 0.96 | 1.04 | +| #/destroy | 72 (67-76) | 72 (67-75) | 76 (73-81) | 1.05 | 1.00 | +| #/grid | 50 (48-51) | 70 (69-71) | 69 (67-70) | 0.99 | 1.39 | +| #/matrix | 33 (32-38) | 36 (36-37) | 36 (28-40) | 1.00 | 1.09 | +| #/text | 40 (40-41) | 42 (40-42) | 39 (39-41) | 0.93 | 1.04 | +| #/firebolt | 37 (37-43) | 41 (32-43) | 41 (40-42) | 0.99 | 1.10 | +| #/login | 62 (60-63) | 54 (51-58) | 59 (58-63) | 1.08 | 0.87 | +| #/nested | 46 (43-47) | 44 (44-45) | 46 (44-47) | 1.05 | 0.95 | +| #/textposter | 56 (53-57) | 52 (48-53) | 51 (49-51) | 0.98 | 0.93 | +| #/textcentering | 58 (52-59) | 55 (54-56) | 53 (47-55) | 0.95 | 0.95 | +| #/countdown | no idle | no idle | no idle | - | - | +| #/custombuttons | 57 (57-63) | 58 (57-59) | 63 (63-65) | 1.09 | 1.01 | +| #/positioning | no idle | no idle | no idle | - | - | +| #/layout | 42 (41-45) | 41 (41-44) | 44 (40-48) | 1.06 | 0.98 | +| #/focusbasics | 42 (39-43) | 40 (40-43) | 42 (41-47) | 1.04 | 0.97 | +| #/transitions | 31 (25-33) | 29 (25-31) | 29 (28-34) | 1.00 | 0.93 | +| #/components | 42 (42-45) | 36 (31-40) | 42 (42-43) | 1.18 | 0.85 | +| #/focushandling | 37 (25-38) | 33 (32-36) | 37 (36-38) | 1.13 | 0.89 | +| #/keyhandling | 39 (39-42) | 35 (34-40) | 44 (44-44) | 1.23 | 0.92 | +| #/gradients | 32 (28-34) | 32 (32-33) | 34 (31-34) | 1.05 | 1.01 | +| #/flex | 36 (33-40) | 42 (41-42) | 41 (38-42) | 0.96 | 1.17 | +| #/create | 113 (107-116) | 104 (103-109) | 102 (91-107) | 0.98 | 0.92 | +| #/viewport | 56 (52-57) | 51 (51-52) | 58 (55-61) | 1.14 | 0.92 | +| #/flexsize | 40 (36-40) | 42 (41-43) | 41 (36-43) | 0.97 | 1.05 | +| #/flexmenu | 32 (29-35) | 36 (35-37) | 35 (27-36) | 0.96 | 1.13 | +| #/flexcolumnsize | 38 (34-38) | 41 (39-41) | 40 (37-41) | 1.00 | 1.07 | +| #/flexcolumn | 37 (34-40) | 38 (36-40) | 39 (39-41) | 1.05 | 1.01 | +| #/flexgrow | 35 (32-38) | 38 (38-38) | 39 (31-40) | 1.01 | 1.10 | +| #/flexjustifywidth | 73 (71-74) | 70 (63-74) | 69 (68-71) | 0.99 | 0.95 | +| #/keepalive | 39 (36-41) | 40 (33-41) | 40 (39-42) | 1.01 | 1.02 | +| #/suspense | 40 (35-42) | 40 (38-41) | 43 (39-44) | 1.06 | 1.01 | +| #/superflex | 46 (39-48) | 49 (46-52) | 51 (45-52) | 1.03 | 1.07 | +| #/tags | 40 (39-42) | 41 (40-41) | 38 (38-40) | 0.94 | 1.02 | +| #/buttonsmaterial | 36 (36-40) | 35 (32-36) | 37 (37-37) | 1.04 | 0.97 | +| #/entity/movie/1013 | 108 (106-112) | 109 (104-110) | 108 (106-110) | 0.99 | 1.01 | +| #/entity/tv/1013 | 110 (105-111) | 100 (88-107) | 106 (106-112) | 1.06 | 0.91 | +| #/entity/people/1013 | 60 (57-66) | 73 (71-79) | 81 (80-88) | 1.12 | 1.21 | +| #/image-performance | 63 (60-65) | 68 (66-68) | 68 (59-68) | 1.00 | 1.08 | +| #/large-image-performance | 75 (75-92) | 78 (77-82) | 85 (79-87) | 1.09 | 1.04 | +| #/mixed-image-performance | 62 (61-66) | 63 (63-66) | 64 (64-65) | 1.02 | 1.01 | +| #/texture-compression-performance | 66 (65-69) | 73 (69-77) | 69 (67-73) | 0.95 | 1.11 | +| #/complexflex | 120 (118-121) | 110 (107-111) | 98 (93-98) | 0.88 | 0.92 | +| #/complexflexcaps | 60 (60-61) | 57 (56-59) | 52 (50-53) | 0.92 | 0.94 | +| #/benchmark | 142 (141-143) | 144 (139-145) | 149 (148-153) | 1.03 | 1.02 | +| #/versions | 39 (38-39) | 36 (33-39) | 39 (37-39) | 1.06 | 0.94 | +| #/does-not-exist | 16 (9-18) | 18 (18-19) | 19 (18-20) | 1.05 | 1.17 | +| **sum of 51 routes** | **3157** | **3146** | **3224** | 1.02 | 1.00 | + +## Errors logged while timing + +- #/grid A: console: [GLOBAL_REJECTION] No compatible text renderer found for Roboto600 +- #/grid A: pageerror: No compatible text renderer found for Roboto600 +- #/entity/people/1013 A: console: [GLOBAL_REJECTION] No compatible text renderer found for Robotonormal +- #/entity/people/1013 A: pageerror: No compatible text renderer found for Robotonormal diff --git a/docs/perf/survey-verification.md b/docs/perf/survey-verification.md new file mode 100644 index 00000000..fd9fec1d --- /dev/null +++ b/docs/perf/survey-verification.md @@ -0,0 +1,1402 @@ +# Verification of the 2026-10-03 survey leads + +Read-only check of every lead in the brief's "Phase 2 → Leads from the +2026-10-03 survey", against: + +- `solid-1.7` at `517094d` (solid 1.6.4 + renderer-v2 lockstep patch; `src/` unchanged by this work); +- `renderer-v2-solid` at `faf4b9f`; +- `solid-js` 1.9.3 (`node_modules/solid-js/dist/solid.js`, `universal/dist/universal.js`); +- `@solid-primitives/list` 0.1.2. + +Line numbers are current as of those commits. Nothing in `src/` was changed. + +## Method + +- **Code reading** of the whole ArrowRight path, Solid and renderer. +- **Instrumentation probe** (jsdom, DOM renderer, `isDev` true as in all vitest + runs). It lives outside the repo, in the scratchpad + (`.../scratchpad/probe/keypress.probe.tsx`, run with + `npx vitest run --config .../scratchpad/probe/vitest.probe.config.mjs keypress` + from `solid-1.7`). It: + - wraps `ElementNode` methods to count them; + - counts `States[Symbol.species]` reads and setter calls on the DOM handle; + - emulates v2's `reprocessUpdates` on the DOM stage (one stored callback, run + at "frame" time), so it can see which `runPostMutation` run does the work. + + The counts below come from it. They are counts, not timings. + +- **Transforms** in the scratchpad (`.../scratchpad/classfields/`): + - rolldown 1.1.5 `transformSync` (the demo app's), with target `chrome64` and + `assumptions.setPublicClassFields`; + - then `@babel/preset-env` 8.0.2 with targets `chrome 38` and the demo's + `legacy()` assumptions; + - and `babel-preset-solid` 1.9.5 (universal) on `Row`, `Column`, `Virtual`, + `VirtualGrid` and `Grid`, to see the compiled spreads. + +### The concrete case + +Every per-press number below is for this case unless it says otherwise. + +- **Tree:** `Column scroll="auto"` › 10 × `Row scroll="auto"` › 20 × + ``. +- **Thumbnail:** the demo's `styles.Thumbnail`: + - `$focus: { scale: 1.1, border: { color, width: 6, gap: 4, align: 'outside' } }`; + - `transition: { scale }`; + - `borderRadius`; + - `border: { width: 0, color: 0 }`. +- **Focus path depth D = 4:** tile, Row, Column, App root. Demo pages are + deeper (page wrappers, LeftNavWrapper, …), and every per-path cost below + scales with D. +- **The press:** ArrowRight within a Row, in steady state: + - both tiles have been focused before; + - the previous press went the same direction; + - no app key handlers, and the announcer is off; + - production build (`isDev` false); + - renderer v2, animations on. + +### Counting allocations + +"Allocations" counts the JS heap objects that framework code creates on the +path: objects, arrays (an array plus its backing store counts as 1 unless +noted), closures, strings and typed arrays. V8 may escape-analyse a few of the +short-lived ones (for example, a result object returned from an inlined +function), so the totals are upper-bound estimates. + +### Counts measured by the probe + +Both columns are per press, in the probe's terms. + +| Count | Right within a Row | VirtualRow press that shifts the window | +| --------------------------------------------------- | ------------------- | --------------------------------------- | +| `setFocus` | 1 | 1 | +| `reprocessUpdates()` registrations | 1 | 1 | +| `queueMicrotask(runPostMutation)` | 1 | 1 | +| `runPostMutation` that did work (microtask) | 1 | 1 | +| `runPostMutation` no-op (frame callback) | 1 | 1 | +| `_stateChanged` | 2 | 2 | +| `States` species constructions | 1 | 1 | +| `_writeShaderTarget` (border sets) | 2 | 2 | +| animated-prop writes (`_sendToLightningAnimatable`) | 3 (x, scale, scale) | 18 (scale ×2, x ×16) | +| flex passes (`updateLayout` on a flex container) | **0** | **2** | +| `insertChild` / `removeChild` / `render` | 0 | 2 / 3 / 2 (all moves, no node created) | +| `activeElement` effect runs | 1 | 1 | +| renderer handle writes (DOM renderer) | 5 | 23 | +| other microtasks | 0 | 1 (Virtual's own) | + +For ArrowDown to the next Row, the probe counted 4 `_stateChanged` (the two +Rows gain and lose `$focus` too) and 2 species constructions. + +--- + +## 1. Verdicts at a glance + +| # | Lead | Verdict | +| --- | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | +| K1 | closure + `runWithOwner` per key event | Confirmed (keydown **and** keyup) | +| K2 | `keyIdentities` array | Confirmed (keydown and keyup) | +| K3 | `performance.now()` | Partly: a call per event, not reliably a heap allocation | +| K4 | `_pendingHistoryKey` built with history off | Confirmed (per keydown **and** per focus change) | +| K5 | template-string handler names | Confirmed (2 strings per event; built once per event, not per element) | +| K6 | `{ handled, lastHandlerSeen }` per bubble level | Partly: one per bubble pass, not per level | +| K7 | capture walk over the whole path | Confirmed (keydown and keyup) | +| K8 | handlers are per-instance expandos, megamorphic | Confirmed | +| K9 | `chainFunctions` rest-args arrays | Confirmed (only when 2 or more functions are chained) | +| K10 | `Config.focusDebug` not dev-gated | Confirmed | +| R1 | per-press transition object | Confirmed (and it is never read on Virtual) | +| R2 | infinite loop, `wrap` with every child `skipFocus` | Confirmed | +| R3 | `style?.focus` instead of `$focus`; `style` getter allocates `{}` | Partly: the bug is real; in v2 the withScrolling branch is unreachable; live in `Virtual.computeSize` | +| R4 | `absX` recursion | Partly: O(depth), but only on a Row's first scroll | +| R5 | a Row with `selected` re-scrolls on every layout | Confirmed | +| F1 | every focus change schedules two runs | Partly: two registrations; one run does the work, the frame run is a measured no-op | +| F2 | `updateFocusPath` walks every ancestor | Confirmed | +| F3 | lazy `States` plus bound callback per ancestor | Partly: once per node lifetime, not per press | +| F4 | fresh path array per change | Confirmed | +| F5 | O(depth²) `indexOf` diff | Confirmed | +| F6 | `States extends Array` species construction | Confirmed (1 per blur; and probably slow generic builtins, see §3) | +| F7 | unbatched `onFocus` / `onBlur` / `onFocusChanged` | Confirmed | +| F8 | two reactive flushes | Partly: two `runUpdates` passes always; only `setActiveElement` has effects by default | +| G1 | spread re-runs reallocate handlers | Partly: Virtual and VirtualGrid re-run but keep their handlers; Grid reallocates 5 handlers on vertical moves | +| G2 | `SliceState` plus slice array per press | Partly: `SliceState` every press; the slice array only when the window moves | +| G3 | `List` diff cost, `indexOf`, `getNextSibling` | Confirmed (3 `indexOf`s per move, not 2; plus a `Map` and `Uint8Array` per diff) | +| G4 | at least two flex passes per window move | Confirmed (measured: 2) | +| S1 | `set states` has no unchanged check | Confirmed | +| S2 | recompute and `Object.assign` of every key, no diff | Confirmed | +| S3 | quadratic multi-state merge | Confirmed | +| S4 | undo allocates objects and closures | Confirmed | +| S5 | `keyExists` uses `in` | Confirmed | +| S6 | `forwardStates` overwrites the children's states | Confirmed | +| S7 | `parseAndAssignShaderProps` allocates | Confirmed (about 11 allocations per border write) | +| S8 | gradients create a shader per set | Confirmed | +| S9 | `onAnimation.stopped` makes a `setTimeout` per prop | Confirmed | +| L1 | per-pass index array, 7 `Float32Array`s, closure | Confirmed (both implementations) | +| L2 | unconditional `x`/`y` writes | Confirmed (measured: 16 writes for 2 passes over 8 children) | +| L3 | production `console.warn` | Confirmed (`flex.ts` only) | +| L4 | two implementations; `flexLayout.ts` untested | Partly: tests and the bench run `flex.ts`, but **the demo app runs `flexLayout.ts`** | +| L5 | a `$focus` width/height change does not reflow | Confirmed | +| N1 | `ElementNode` size (24 `_` fields, 11-key bag, expandos) | Confirmed (27 own fields at construction; tile +3, Row +18, Column +19 expandos) | +| N2 | unknown names written to the v2 handle | Confirmed: the paths exist (§4.4) | +| N3 | child-list `indexOf`/`splice`; `cleanChildren` O(n²) | Confirmed | +| N4 | class-field emit for `ElementNode` | Refuted for `ElementNode` (it has no class fields). `TextNode` and `States` do, and their emit depends on the tsconfig (§4.5) | + +**Totals: 34 Confirmed, 10 Partly, 1 Refuted (45 leads).** + +The pointer "Layout → Text" is covered in §6. Its leads are confirmed there, +but not counted here. + +--- + +## 2. Trace of one ArrowRight within a Row + +Each step gives its file and line, then what it allocates. Unless a path says +otherwise, it is under `src/`. + +Abbreviations: + +- `fm` = `core/focusManager.ts` +- `en` = `core/elementNode.ts` +- `hn` = `primitives/utils/handleNavigation.ts` +- `ws` = `primitives/utils/withScrolling.ts` +- `sj` = `solid-js/dist/solid.js` +- `rv2` = `renderer-v2-solid/src` + +### A. keydown task + +1. **The `document` keydown listener.** `keyPressHandler`, fm:635-643. It calls + `ownerContext(() => {...})` (fm:623-625). + - Allocates **1 closure**. +2. **`runWithOwner(owner, cb)`**, sj:550 → `runUpdates(fn, true)`, sj:850-856. + - `Effects = []`: **1 array**. + - This batches the effects (but not the memos) of signal writes made inside + the handler until it returns. +3. **`handleKeyEvents`**, fm:537-555. + - `keyIdentities(keydown)` (fm:449-460): **1 array plus its backing store**, + holding `'ArrowRight'` and `39`. + - `liftSuppression` → `findSuppression`: a `for…of` and 2 `Map.get`s. + - `keyMapEntries[e.key]` → `'Right'`. +4. **`propagateKeyPress`**, fm:380-440. + - `performance.now()` (fm:385). + - `_pendingHistoryKey = { keyPressed, mappedKey }` (fm:410): **1 object**. + - `focusPath()`: a signal read; nothing tracks it. +5. **`runCapturePhase`**, fm:297-324. + - `` `onCapture${keyBase}${isUp ? 'Release' : ''}` `` (fm:307): **1 string**. + It is not interned, so each keyed lookup goes through the string table. + - Loops over **all D path elements**. Each one does + `isElementThrottled` (`elm.throttleInput`: a miss through the prototype + chain), `elm[captureEvent]` and `elm[captureKey]`: **3 keyed misses**. +6. **`runBubblePhase`**, fm:328-378. + - `` `on${mappedEvent}` `` (fm:340): **1 string**. + - On the tile: throttle check, `tile.onRight` misses, `tile.onKeyPress` + misses. + - On the Row: `Row.onRight` is found. + - Returns `{ handled: true, lastHandlerSeen }` (fm:374): **1 object**, which + may be escape-analysed away. + - `elm._lastAnyKeyPressTime = currentTime` (fm:373) stores a double. +7. **`Row.onRight`** = `handleNavigation('right')` (Row.tsx:32,42; hn:125-162). + `chainFunctions(undefined, onRight)` returns `onRight` itself, so there is + no wrapper. + - `el.transitionRight` and `el.transition` are expando reads. + - `merged = { ...directional, ...el._navBaseTransition }` (hn:152): + **1 object**. It is stored in `el.transition` and `el._navLastMerged`. +8. **`moveSelection`** (hn:190-221) → `findFirstFocusableChildIdx` (hn:37-53), + which reads `children[i]?.skipFocus` (a miss) → `selectChild` (hn:55-74). + - `el.selected = index` (an expando store). + - `lng.isFocused(child)` → `child.states.has('$focus')` (core/utils.ts:219-221). + The first time a child is touched, the `states` getter allocates a + `States`, a bound `_stateChanged`, and 3 arrays from + `Object.entries({}).filter().map()` (en:1278-1281, states.ts:11-21). + That is once per node lifetime, so 0 in steady state. +9. **`child.setFocus()`** (en:1112-1138). `forwardFocus` misses, then + `nextActiveElement = this`, then `schedulePostMutation()` (en:93-100). + 1. `'reprocessUpdates' in renderer.stage`: the `stage` getter returns the + renderer (rv2 `Renderer.ts`, `RendererCore.ts:322`). + 2. `renderer.reprocessUpdates(runPostMutation)` (rv2 `RendererCore.ts:503-510`) + sets `postUpdate = cb` and `frameRequested = true`, then + `onFrameRequest()` → `loop.schedule()` (`Renderer.ts:331-337`). + - Allocates nothing. + 3. `queueMicrotask(runPostMutation)`. + - Allocates **1 microtask entry** (V8-internal). +10. **`el.onSelectedChanged(index, el, child, lastSelected)`** (hn:71). With no + app handler this is `scrollRow` itself (Row.tsx:51-56). It runs the + `withScrolling` closure (ws:63-242): + - About **25 property reads** on the Row and the tile, many of them misses + on expandos that are absent (`scrollIndex`, `endOffset`, `onScrolled`, + `scrollStopLast`, `upCount`, `centerScroll`, …). + - `lng.stage.root.w` is 2 getter calls. + - `selectedElement.scale` → `ElementNode` accessor → v2 `Node.scale` + (rv2 `Node.ts:307-309`), which always returns `scaleX`, a number. So + `style?.focus` (ws:127) is never evaluated. + - Then `componentRef.x = nextPosition` (ws:238), `_targetPosition`, and + `offset`. +11. **The `x` write.** `ElementNode` accessor (en:1772-1781) → + `_sendToLightningAnimatable('x', v)` (en:993-1032). + - Reads `this.transition`, `Config.animationsEnabled`, + `this.transition.x` and `getPropertyAlias`, then + `'animateProp' in this.lng`. + - → `lng.animateProp('x', v, transition.x)` (rv2 `Node.ts:922-967`). The + settings object is the same as last time (`defaultTransitionForward.x`), + so the controller is reused: `retarget` plus `start()`. + - If the previous run had finished, `start()` allocates a **Promise, its + executor closure and its resolving functions** (rv2 + `Animation.ts:440-451`; a finished run calls `stop()` at :626, which + clears the promise). + - If the direction changed (Left after Right), the settings object + differs. Then `stop()` and a **new `Animation`** (about 12 objects: 4 + typed arrays and 4 arrays at `Animation.ts:270-278`), plus + `{ [name]: value }` and a slot object (`Node.ts:957-965`). + - Then `_fireAnimationEvents`: `this.onAnimation` misses, so it returns. +12. **The handler returns `true`.** `Config.preventDefaultOnHandledKeys` is + false. `runWithOwner` completes: `completeUpdates`, with nothing queued. + +### B. Microtask: `runPostMutation` (en:102-138) + +13. `postMutationQueued = false`. The delete and layout queues are empty. + Then the focus phase: `setActiveElementCore(tile)` (fm:212-222). +14. **`updateFocusPath(tile, prev)`** (fm:226-280). + - `fp = []` plus pushes: **1 array plus its backing store**. + - Walks up D ancestors. Each one gets `current.states.has($focus)` + (`indexOf` on an `Array` subclass, states.ts:28-40), and `parent` + getter reads. + - On the new tile: + - `states.add` → `push` → `onChange` = bound `_stateChanged` + (step 15). + - Then `onFocus` and `onFocusChanged` lookups (both miss). + - The previous path is diffed with `fp.indexOf(elm)` for each of its D + elements: **D² = 16 comparisons**. + - On the old tile: + - `states.remove` (states.ts:93-99) → `splice` → **species construction** + `new States(1)`: a `States` instance and `Object.entries({})`, + `.filter`, `.map` (**4 allocations**). + - Then `_stateChanged` (step 16), then `onBlur` and `onFocusChanged` + lookups. + - `if (Config.focusDebug)` (fm:275). + - `_signalWrapper(() => setFocusPath(fp))` (fm:279): **1 closure**, plus + `runWithOwner` → `Effects = []` (**1 array**). `focusPath` has no + observers unless the announcer is used. +15. **Tile gains `$focus`.** `_stateChanged` (en:1405-1505). + - `forwardStates` misses. + - `_undoStyles` is `[]` from the last blur, so `keyExists(this, states)` + (core/utils.ts:69-79) runs: `'$focus' in tile` is true. + - One state, so `newStyles = this['$focus']`, the static object, without + a copy. + - `this._undoStyles = Object.keys(newStyles)` (en:1493): **1 array**. + - `Object.assign(this, newStyles)` (en:1500). It takes two keys: + - **`scale`** → accessor → `animateProp('scale', 1.1, transition.scale)`. + The controller is reused, plus a renderer Promise if the last run had + finished. + - **`border`** → `shaderAccessor('border').set` (en:1830-1866). + - `lng.shader.props`: the v2 facade (rv2 `ShaderNode.ts:76-78`). + - `transition.border` misses, then `parseAndAssignShaderProps` + (en:175-204), which allocates: + - the `borderSideMap` literal (**1**); + - `Object.entries(obj)` with its 4 pairs (**5**); + - the `forEach` closure (**1**); + - 4 template keys `border-color`, `border-w`, `border-gap` and + `border-align` (**4**). + - That is **11 allocations** in Solid. + - Each keyed store goes into a facade setter (rv2 + `ShaderRegistry.ts:1003-1016`). `border-w` goes through `vec4Prop`'s + `resolve` → `toVec4`: a **new 4-array** (rv2 `borderGeometry.ts:5-9`). + It always stores and marks, because it is an object. + - `border-color`, and `border-gap` on the first focus, mark + `DIRTY_SHADER` through `markUsers` → `markDirty` (rv2 + `NodeStore.ts:472-492`). + - `props.border = obj` (en:193) adds an own `border` field to the + facade object (§4.4). + - `_writeShaderTarget` (en:837-848) does nothing on v2. +16. **Old tile loses `$focus`.** `_stateChanged`. + - `stylesToUndo = {}` (en:1439): **1**. + - `_undoStyles.forEach(closure)` (en:1440): **1**. It reads `this.theme` + (en:1221-1224; allocates `{}` once per node) and `this.style`. + - `numStates === 0` → `Object.assign(this, stylesToUndo)`: + - `scale`: `animateProp`, reused. + - `border` (`{ width: 0, color: 0 }`): `parseAndAssignShaderProps` again + (**7 allocations**), plus 1 renderer `toVec4`. + - `this._undoStyles = []` (en:1459): **1**. +17. **History.** `recordFocusHistory` is gated by `isDev`. + `_pendingHistoryKey = {…}` (fm:218) is **not** gated: **1 object**. +18. **`Config.setActiveElement(tile)`** → `ownerContext(() => setActiveElementSignal(elm))` + (fm:630-631): **1 closure**. + - `runWithOwner` → `Effects = []`: **1**. + - `writeSignal` (sj:687-717) → `runUpdates(closure, false)`: **1 closure + and `Updates = []`**. + - `completeUpdates` → `runUpdates(() => runEffects(e))`: **1 closure and + 1 array**. + - It runs the framework's own render effect (render.ts:76-83: reads + `activeElement()` and sets `tasksEnabled = false`), plus every app + effect on `activeElement`. + +### C. The next rAF: `Renderer.frame` (rv2 `Renderer.ts:340+`) + +19. `step(dt)` advances the `x` and `scale` tracks. +20. `update()` (rv2 `RendererCore.ts:535-590`): + - `scene.run` resets `writes` (`ScenePass.ts:243`) and walks once. + - `textEvents.flush()` follows. + - `cb = postUpdate` → `runPostMutation` runs **as a no-op**: every queue is + empty (measured). It writes nothing, so `writesDuringPass` is 0 and + there is **no re-walk**: `updateIterations = 1`. +21. `backend.draw`. The following frames, for about 250 ms of `scale` and + 180 ms of `x`, each step, walk and draw. That is renderer cost, after the + frame that "shows the result". + +### D. keyup task + +22. Steps 1-6 repeat with `isUp = true`: + - a closure, `Effects = []`, `keyIdentities` (array plus backing store), + and `performance.now()`; + - the strings `onCaptureRightRelease` and `onRightRelease`; + - a **full capture walk (D × 3 keyed misses)**; + - a **full bubble walk** (D × 2 misses; there is no `onKeyPress` fallback + for keyup); + - `{ handled: false, lastHandlerSeen }`. + + Nothing handles it in the common case. That is about **8 allocations and + about 5·D property misses** for nothing. + +### Totals (steady state, modern bundle, Solid framework only) + +| Phase | Allocations | Main work | +| -------------------------------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | +| keydown dispatch and navigation | about 10 | capture D·3 and bubble about 6 keyed loads; about 35 property reads in navigation and scroll; 1 animated write | +| microtask: focus, states, styles | about 38 | D-ancestor walk, D² diff, 2 `_stateChanged`, 2 `animateProp`, 2 shader parses (6 facade writes), 1 species construction, 2 `runUpdates` and 1 effect run | +| frame callback | 0 | a no-op `runPostMutation`, 1 walk | +| keyup | about 8 | capture D·3 and bubble D·2 keyed loads | +| **Total** | **about 56** | **0 flex passes**, 3 `animateProp`s, about 4-6 renderer `markDirty`s plus the animation tracks | + +The renderer adds, per press: + +- 2 `toVec4` arrays; +- up to 3 Promises with their closures (about 12 objects) from + `Animation.start()` restarting finished animations; +- on a change of direction, a new `Animation` (about 15 objects). + +On the **legacy bundle** (Chrome < 64), add about 25 more. Babel helpers do it +(§4.5): + +- two `_objectSpread` calls for the transition merge: each does `Object.keys`, + `getOwnPropertySymbols`, a `forEach` closure and `Object.defineProperty` per + key; +- `_createForOfIteratorHelper` in `keyExists`; +- the `States` species construction through `_wrapNativeSuper` and the + `Reflect.construct` fallback: `_toConsumableArray`, `[].concat` and a + `setPrototypeOf` per instance; +- `.concat()` for every template string. + +--- + +## 3. Lead-by-lead evidence + +### Key dispatch (`src/core/focusManager.ts`) + +**K1, closure plus `runWithOwner`: Confirmed.** fm:635-652. It happens on +**both** keydown and keyup. + +```ts +const keyPressHandler = (event: KeyEventLike) => + ownerContext(() => { if (handleKeyEvents(event as KeyboardEvent, undefined) && ... +``` + +- `ownerContext` = `runWithOwner(owner, cb)` → `runUpdates(fn, true)`, which + allocates `Effects = []` (sj:855). +- Cost: 2 allocations per event, so **4 per press**. +- This wrapper is also the only batching on the keydown path. It defers the + _effects_ of signal writes in handlers until the handler returns. It does + not defer memos. + +**K2, `keyIdentities` array: Confirmed.** fm:449-460, called at fm:542 and +fm:560. + +- 1 array plus backing store per event, so **about 4 per press**. + +**K3, `performance.now()`: Partly.** fm:385, on every event. + +- It is an embedder call, and the double result may be boxed. +- It is not reliably a heap allocation in optimised code. Count it as call + cost: 2 per press. + +**K4, `_pendingHistoryKey` built with history off: Confirmed.** It is +**2 objects per press**: + +- fm:410, per keydown; +- fm:218, per focus change. + +Only `recordFocusHistory` itself checks `isDev && Config.focusHistoryDebug` +(fm:137). + +**K5, template-string handler names: Confirmed.** + +- `` `onCapture${keyBase}${isUp ? 'Release' : ''}` `` (fm:307); +- `` `on${mappedEvent}Release` `` / `` `on${mappedEvent}` `` (fm:339-340). + +They are built once per event, not per element: **4 strings per press**. The +strings are not internalised. Every `elm[name]` lookup is then a keyed +megamorphic load with a non-internalised key: a string-table probe, with its +hash cached after the first. + +**K6, result object per bubble level: Partly.** There is one +`{ handled, lastHandlerSeen }` per `runBubblePhase` call (fm:351, 374, 377). +That is 2 per press, and it may be escape-analysed away. + +**K7, capture walk over the whole path: Confirmed.** fm:310-322 walks root to +leaf over every element, with 3 keyed loads each (`throttleInput`, +`captureEvent`, `captureKey`). + +- For keyup, the bubble walk is also full (fm:348-376), because no handler + answers `on…Release`. +- Per press: about `2 × 3D + 2 + 2D` loads, which is **32 for D = 4** and + grows linearly with page depth. + +**K8, handler storage: Confirmed.** + +- `setProperty` is `node[name] = value` (solidOpts.ts:27-29). +- Of the handlers, only `onLayout` has a prototype accessor (en:1349-1360). + Every `on*` handler is an own expando. +- Measured expandos: + - Row: `transitionLeft`, `transitionRight`, `scroll`, `selected`, `onLeft`, + `onRight`, `forwardFocus`, `scrollToIndex`, `onSelectedChanged`, `gap`, + `preFlexwidth`, `_navBaseTransition`, `transition`, `_navLastMerged`, + `_initialPosition`, `_screenOffset`, `offset`, `_targetPosition` + (18 in a prod build); + - Column: 19; + - tile: `transition`, `$focus`, `item`. +- They are added in component-specific orders, so the hidden classes vary, + and every handler lookup is a keyed load (K5). The lookup sites are + megamorphic. + +**K9, `chainFunctions` rest-args arrays: Confirmed.** chainFunctions.ts:23-25 +(creation) and 49 and 57 (`...innerArgs` on each call). + +- With fewer than 2 functions it returns the original function + (chainFunctions.ts:41-42). +- So the per-call array only appears when the app passes its own `onLeft`, + `onSelectedChanged`, and so on. +- `Grid` re-creates chains on spread re-runs (G1). + +**K10, `Config.focusDebug` not dev-gated: Confirmed.** + +- `if (Config.focusDebug) addFocusDebug(prevFp, fp)` (fm:275-277). +- `addFocusDebug` and its CSS (fm:51-94) ship in production. +- Cost per press: 1 property load. The rest is bundle size. + +### Row and Column (`handleNavigation.ts`, `withScrolling.ts`) + +**R1, per-press transition object: Confirmed.** hn:139-155: + +```ts +const merged = { ...(directional as object), ...el._navBaseTransition }; +el.transition = merged; +el._navLastMerged = merged; +``` + +This is 1 object per press. On the legacy bundle it is two `_objectSpread` +calls, each with `defineProperty` per key. + +- For Row and Column, the `x`/`y` write in `scrollRow` reads it. +- **On Virtual and VirtualRow it is never read.** Virtual moves the row with + `this.lng[axis] = …` and `this.animate(...)` (Virtual.tsx:463-471), not + through the `x` accessor. So it is pure waste there. + +**R2, infinite loop: Confirmed.** See §4.2. + +**R3, the `style` getter and `.focus`: Partly.** There are two sites: + +- ws:125-128: + ```ts + selectedElement.scale ?? (selectedElement.style?.focus as Styles)?.scale ?? 1; + ``` + On v2, `selectedElement.scale` is the v2 `scale` getter, which returns + `scaleX` (rv2 `Node.ts:307-309`, the same as 1.10). So `??` never reaches + `style`, there is **no `{}` allocation**, and the `.focus` typo is latent. +- Virtual.tsx:104, in `computeSize`: + ```ts + const focusStyle = prevSelectedChild.style?.focus; + ``` + This one is live: + - it runs whenever `cachedScaledSize` is empty, or when + `uniformSize === false`; + - `style` allocates `{}` when there is no style (en:1207-1209); + - `.focus` never finds a `$focus` block, so `factorScale` uses the + _current_ scale. + +**R4, `absX`: Partly.** + +- v2 `absX` and `absY` recurse through the `parent` getter (rv2 + `Node.ts:876-895`), so they are O(depth), with 2 getter calls per level. +- They run only when `_screenOffset === undefined` (ws:87-98), which is a + Row's first scroll. That is once per Row, not per press. + +**R5, layout re-scroll: Confirmed.** + +- Row.tsx:45-50 sets `onLayout = props.selected ? chainFunctions(props.onLayout, scrollRow) : …`. + Column.tsx:46-51 does the same. +- `updateLayout` calls `onLayout` after every flex pass (en:1384-1385). +- `scrollRow(node)` with `lastSelected === undefined` takes the + `'always'`/`'center'` path, and may write `x`. +- This applies only when `selected` is truthy at creation. + +### Focus change + +**F1, two runs per focus change: Partly.** The registrations are as the survey +says (en:93-100): + +```ts +if ('reprocessUpdates' in renderer.stage && renderer.stage.reprocessUpdates) { + renderer.stage.reprocessUpdates(runPostMutation); +} +queueMicrotask(runPostMutation); +``` + +What actually runs is in §4.1. + +- The microtask always wins for key-originated work and does everything. +- The frame callback runs once, finds every queue empty and writes nothing + (measured as a no-op on every press). +- Under v2 semantics it causes **no re-walk**. + +The real costs are smaller than the survey implies: + +- an extra function call per frame; +- `frameRequested = true`, which forces a walk and a draw even when the + change wrote nothing to the store (for example a focus move between + unstyled nodes); +- extra registrations whenever `runPostMutation` itself re-schedules (layout + → `addToLayoutQueue(parent)`, or deferred `setFocus`). + +**F2, `updateFocusPath` walks every ancestor: Confirmed.** fm:235-257. + +- It visits every ancestor up to the root. +- Each one pays `states.has`, `onFocus`/`onFocusChanged` lookups and the + `parent` getter. +- Every wrapper gets `$focus` added and removed when focus enters or leaves + its subtree. That runs `_stateChanged` on the wrapper: 4 runs for a Down + press (measured). + +**F3, lazy `States` per ancestor: Partly.** + +- The `states` getter (en:1278-1281) allocates a `States`, a `.bind`, and + 3 arrays from the default `{}` initial state. +- That happens once per node lifetime. In steady state it is 0 per press. +- The same applies to `isFocused(child)` in `selectChild` (hn:66). + +**F4, fresh path array: Confirmed.** fm:234: `const fp: ElementNode[] = [];`. +That is 2 allocations per change. + +**F5, O(depth²) diff: Confirmed.** fm:260-262 runs `fp.indexOf(elm)` for each +element of the previous path. + +**F6, `States extends Array`: Confirmed.** + +- `remove` → `this.splice(...)` (states.ts:96). `splice` and `slice` create + their result through `ArraySpeciesCreate`, which calls `new States(1)`. +- With the default `initialState = {}`, that runs + `Object.entries({}).filter().map()` (states.ts:17-21). +- Measured: 1 species construction per Right press, 2 per Down press. +- It also leaves `onChange = 1`, a number, on the throwaway instance. That + changes the field representation of the `States` map once. +- `forwardStates` calls `this.states.slice()` (en:1421): another species + construction. + +Beyond the survey: V8's fast paths for `indexOf`, `push` and `splice` check +for the initial `Array.prototype`. So on `States` instances, `has`, `add` and +`remove` probably all run the generic, slow builtins. This is a hypothesis to +confirm in the CPU profile: look for generic `ArrayPrototypeSplice` and +`Runtime_ArrayIndexOf` frames. + +**F7, unbatched callbacks: Confirmed.** + +- `updateFocusPath` runs inside the `runPostMutation` microtask, without + `batch` or `runWithOwner`. +- Every signal write in `onFocus`, `onBlur` or `onFocusChanged` (for example + Portal-style reactive text colours) runs + `runUpdates(..., false)` → `completeUpdates(false)`. That flushes its + effects immediately, one write at a time. + +**F8, two reactive flushes: Partly.** `setFocusPath` (fm:279) and +`Config.setActiveElement` (fm:221, 630-631) each go through +`runWithOwner` → `runUpdates` → `completeUpdates`. + +- `focusPath` has observers only when the announcer is used + (`announcer/index.ts:15`). Otherwise it is an empty pass, which still costs + a closure and an `Effects` array. +- `activeElement` always has at least one observer: Solid's own render effect + (render.ts:76-83), plus app effects. The demo pages read `activeElement`. + +### Grid, Virtual and VirtualGrid + +**G1, spread re-runs: Partly.** From the compiled output (babel-preset-solid, +universal): + +- **Virtual.** + + ```js + _$spread(_el$, _$mergeProps(props, keyHandlers, { get wrap(){…}, get selected(){…}, get cursor(){ return cursor(); }, "forwardFocus": …, … }), true) + ``` + + - `keyHandlers` (Virtual.tsx:583-606) and the `@once` props are static. + `ref` is evaluated outside the effect. + - So a `cursor` change re-runs `spreadExpression`'s single render effect + (universal.js:208-216). It walks about 22 props (measured expandos: + `each`, `displaySize`, `bufferSize`, `scroll`, `wrap`, `cursor`, …), + re-evaluates every getter, and writes only `cursor`. + - It **does not** reallocate handler closures. + - Measured: 1 `cursor` write per press. + +- **VirtualGrid** is the same: `cursor` is written on every press + (VirtualGrid.tsx:102), even within a row. +- **Grid** is the exception, and reallocates. + `onUp`, `onDown`, `onLeft`, `onRight` and `onFocus` are compiled as + **getters** that call `chainFunctions(props.onX, () => moveFocus(...))` + (Grid.tsx:129-133; there is no `@once`). + - The spread re-runs when `scrollY()` or `height` changes, which is every + vertical move. + - Each re-run allocates 5 rest arrays, 5 arrow closures (plus 5 wrappers + and 5 arrays when the app passes handlers), and writes 5 new handler + expandos. + +**G2, per-press slice allocation: Partly.** + +- Virtual.tsx:427-435 runs on every press: + - the `setCursor(c => …)` closure; + - `computeSlice` returns a new `SliceState` (Virtual.tsx:347-355); + - `setSlice(newState)`. +- The `items().slice()` array is allocated only when `start` changes + (Virtual.tsx:338-345). +- Because `setSlice` always gets a new object, `List` re-runs even when the + window does not move: + - `new Array(n)`, `new Map()` and `new Uint8Array(…)` + (`@solid-primitives/list` index.js:30, 45-46); + - a new `mapped` array, which re-runs the `insert` effect: + `normalizeIncomingArray` allocates a new array, and `reconcileArrays` + calls `getNextSibling` and makes an O(L) comparison pass. +- VirtualGrid allocates the slice only on a row change (VirtualGrid.tsx:103-105). + +**G3, `List` diff cost: Confirmed, with corrections.** + +- `@solid-primitives/list` is _unkeyed_. A one-step window shift **recycles** + nodes: L-1 items match by value and keep their nodes, and the leaving item's + node takes the new value through `batch(changeBoth)` (list index.js:98). + **No `ElementNode` is created per shift** (measured: `render` 2× and both + are early returns for already-rendered nodes). +- The diff allocates `temp`, a `Map`, a `Uint8Array`, and **one `[j]` array + per unmatched item** (index.js:49; L of them on a shift). +- Then the rotation `[n0..nL-1] → [n1..nL-1, n0]` goes through + `reconcileArrays` (universal.js:114-170). It allocates a `Map`, then calls + `replaceNode(n1, n0)` → `insertNode` + `removeNode`, then + `insertNode(n0, after)`. +- `insertChild(node, before)` (en:930-957) does: + - `node.parent.removeChild(node)`: `indexOf` and `splice`; + - `spliceItem(children, node, 1)`: **another `indexOf`, which misses after + a full scan**; + - `spliceItem(children, before, 0, node)`: `indexOf`, `splice`, and a rest + array. + + That is **3 `indexOf`s**, not 2. + +- `removeChild` does not clear `node.parent`. So re-inserting `n0` pays one + more full-scan miss. +- `getNextSibling` (solidOpts.ts:69-76) is `indexOf`, called at least once per + reconcile (universal.js:120). +- Measured per shift: `insertChild` 2, `removeChild` 3. + +**G4, at least two flex passes: Confirmed (measured: 2).** + +1. Pass 1: `removeChild` and `render(true)` queue the view, and + `runPostMutation` phase 2 runs layout (en:117-124). +2. Pass 2: Virtual's own microtask calls `elm.updateLayout()` + (Virtual.tsx:451-452). VirtualGrid does the same (VirtualGrid.tsx:118-120). + +Each pass writes every child's `x`: 8 children × 2 = 16 accessor writes, +mostly unchanged values. Text tiles can add a third, in-frame pass (§6). + +### States and styles + +**S1, no unchanged check: Confirmed.** en:1269-1276: + +```ts +set states(states: NodeStates) { + this._states = this._states ? this._states.merge(states) : new States(this._stateChanged.bind(this), states); + if (this.rendered) { this._stateChanged(); } +``` + +**S2, recompute and re-apply: Confirmed.** + +- `Object.assign(this, newStyles)` (en:1500) runs every key through its + setter. +- Animated keys call `animateProp` even when the value is unchanged. That + retargets to the same value, resets `progress` to 0, and requests frames. +- So adding a second state while `$focus` is active restarts the `scale` + transition. + +**S3, quadratic multi-state merge: Confirmed.** en:1486-1489: + +```ts +newStyles = sortedStates.reduce((acc, state) => { + const styles = this[state]; + return styles ? { ...acc, ...styles } : acc; +``` + +A `slice().sort()` with a closure is added when `stateOrder` is set +(en:1473-1483). With 1 state and a prior undo, it allocates +`{ ...stylesToUndo, ...newStyles }` (en:1466-1468). + +**S4, undo allocations: Confirmed.** + +- `stylesToUndo = {}` and a `forEach` closure (en:1439-1453); +- `_undoStyles = Object.keys(...)` (en:1493), and `= []` (en:1459, 1502); +- the `theme` getter allocates `{}` once per node (en:1221-1224). + +**S5, `keyExists` uses `in`: Confirmed.** core/utils.ts:69-79. + +- On nodes without state styles (Rows, Columns, wrappers), `in` misses after + walking the instance, `ElementNode.prototype` and `Object.prototype`. +- It runs only when `_undoStyles` is empty, which is once per `_stateChanged`. + +**S6, `forwardStates` overwrites: Confirmed.** + +- en:1419-1425 assigns `c.states = this.states.slice()`. +- `merge` with an array does `this.length = 0; this.push(...newStates)` + (states.ts:69-71), which replaces the child's own states. +- Each child then runs a full `_stateChanged` with no change detection (S1). + +**S7, `parseAndAssignShaderProps`: Confirmed.** en:175-204. Per call it +allocates: + +- the `borderSideMap` literal (en:183-188); +- `Object.entries` with its pairs (en:194); +- a `forEach` closure; +- one template key per entry (en:202). + +That is **11 allocations** for the 4-key `$focus` border and **7** for the +2-key base border. On v2 each key is then a facade setter, and `border-w` +allocates a `toVec4` array (see §4.4 for the stray `border` field). + +**S8, gradients: Confirmed.** + +- `linearGradient` and `radialGradient` use `createRawShaderAccessor` + (en:1808-1818): `this.shader = [key, value]`, which allocates an array. +- Then `renderer.createShader(...shaderProps)` (en:985-991) creates a **new + `ShaderNode`** on every set: a values object, a facade and a slot lookup. + +**S9, `setTimeout` per prop: Confirmed.** en:1045-1048. Every animated prop +write on a node that has `onAnimation.stopped` schedules a timer plus a +closure. + +### Layout (`flex.ts` and `flexLayout.ts`) + +**L1, allocations per pass: Confirmed** in both files. Per pass: + +| Allocation | `flex.ts` | `flexLayout.ts` | +| ---------------------------- | ---------- | --------------- | +| index array plus growth | :25 | :56 | +| 7 `Float32Array`s | :98-104 | :137-143 | +| `doCrossAlign` closure | :179-202 | :259 / :279 | +| `preFlex${dim}` template key | :247, :268 | :326, :347 | + +On V8, typed arrays up to 64 bytes are on-heap; with 17 or more children they +move to off-heap backing stores. + +**L2, unconditional writes: Confirmed.** Every child's `x`/`y` is assigned +through the accessor: + +- `flex.ts` :237, :254, …; +- `flexLayout.ts`, in the same places. + +`_sendToLightningAnimatable` then: + +- either writes directly, and v2's `setF` returns early on an equal value + (rv2 `Node.ts:116-123`); +- or, on a child with `transition` covering `x`/`y`, calls `animateProp` and + **restarts a transition to the same value**. + +**L3, production `console.warn`: Confirmed.** `flex.ts:160-162`. +`flexLayout.ts` has none. + +**L4, two implementations: Partly. This one matters for the benchmark plan.** + +- elementNode.ts:22-24 chooses with `import.meta.env?.VITE_USE_NEW_FLEX`. +- `solid-demo-app-1.7/.env` sets `VITE_USE_NEW_FLEX=true`. So **the demo app, + the compatibility oracle, runs `flexLayout.ts`.** +- The vitest suite runs `flex.ts`: `solid-1.7/.env` has no such variable. + `tests/contract-flex.test.tsx:9` only logs the variable. +- So does `bench/`, as of this read: its root is `bench/`, it has no `.env`, + and `bench/vite.config.ts` defines no such variable. +- The A/B/C bench numbers and the demo's `#/benchmark` therefore exercise + different layout code. + +**L5, `$focus` width/height does not reflow: Confirmed.** + +- The `w`/`h` setters and `_stateChanged` never call `updateLayout` or + `addToLayoutQueue` (en:887-901, 993-1032, 1405-1505). + +### Nodes + +**N1, `ElementNode` size: Confirmed.** The constructor (en:779-825) assigns +**27 own properties**: + +- `_type`, `rendered`, `lng`, `children`; +- 23 underscore fields, so 24 counting `_type`. `_calcWidth`, `_calcHeight` + and `_fontWeight` are among them, though the interface does not declare + them. + +It also allocates the 11-key `lng` bag (`w`, `h`, `x`, `y`, `alpha`, `color`, +`shader`, `clipping`, `text`, `ignoreParentAlpha`, `placeholderColor`) and +the `children` array. That is **3 heap objects per construction**. The bag +becomes garbage at render, when it is replaced by the handle (en:1705), and +`_rendererProps` keeps it in dev only. + +Measured own keys after a few presses, in the probe (`isDev`, which adds +`_rendererProps`): + +| Node | Own keys | Expandos (prod) | +| ------------ | -------- | --------------- | +| tile | 31 | 3 | +| Row | 46 | 18 | +| Column | 47 | 19 | +| Virtual view | — | 21 | + +The Virtual view's expandos include `each`, the whole items array, which the +spread writes to the node. + +**N2, unknown names written to the v2 handle: Confirmed.** See §4.4. + +**N3, child-list cost: Confirmed.** + +- `insertChild` and `removeChild` use `spliceItem` (`indexOf` + `splice` + + a rest array) (en:930-969; core/utils.ts:81-92). +- `cleanChildren` in the universal renderer + (`while ((removed = getFirstChild(parent))) removeNode(...)`, + universal.js:171-176) removes index 0 each time. Each removal shifts the + array, so clearing n children is O(n²). Each removal also adds to the + layout queue and enqueues a delete. + +**N4, class fields: Refuted for `ElementNode`.** See §4.5. + +--- + +## 4. The specific checks + +### 4.1 `schedulePostMutation` and v2 `reprocessUpdates` + +How v2 behaves: + +- `reprocessUpdates(cb)` (rv2 `RendererCore.ts:503-510`) **stores one + callback; the last one wins**. It sets `frameRequested` and schedules the + loop. +- `update()` (rv2 `RendererCore.ts:535-590`) runs, per walk: + `drainPreloads`/`drainForced` → `scene.run` (which zeroes `nodes.writes`) → + `textEvents.flush()` → `cb = postUpdate; postUpdate = null; cb()`. +- It loops while `writesDuringPass > 0 || postUpdate !== null`, up to + 3 walks. `writes` counts every `markDirty` since the walk began, including + the callback's own. + +Per press, as measured by the probe with v2 semantics emulated: + +- **`runPostMutation` runs exactly twice.** + 1. **The microtask** at the end of the keydown task. It does all the work: + the delete flush, layout (0 passes for a Row press, 2 for a Virtual + shift), and focus (`updateFocusPath`, states, styles). + 2. **The frame callback.** It finds `postMutationQueued` already false and + every queue empty, so it is a **no-op**. It writes nothing, so the walk + is not repeated (`updateIterations` = 1). +- Its only effect is `frameRequested = true`. That is redundant when the press + already wrote to the store. When the focus change wrote nothing, it forces a + walk and a draw that v2 would otherwise skip. +- **When the frame callback does real work:** when `schedulePostMutation` is + first called _during_ a frame. A text `loaded` listener (`_layoutOnLoad`, + en:1140-1145) is the case. Then: + 1. the listener also calls `parent.updateLayout()` synchronously, which + writes and so forces a re-walk; + 2. the callback lays out the parents that the first pass queued; + 3. the microtask queued alongside runs after the frame, as a no-op. + + So text changes in flex containers cost 2 or 3 walks. That is consistent + with the brief's text section. + +- **Extra registrations happen** whenever the microtask run re-enters + `schedulePostMutation`: `updateLayout` → `addToLayoutQueue(parent)`, or a + deferred `setFocus`. Each one adds one more no-op microtask and one more + `reprocessUpdates` call. + +### 4.2 The infinite loop in `findFirstFocusableChildIdx` + +hn:37-53, exactly: + +```ts +function findFirstFocusableChildIdx(el, from = 0, delta = 1): number { + for (let i = from; ; i += delta) { + if (!idxInArray(i, el.children)) { + if (el.wrap) { + i = (i + el.children.length) % el.children.length; + } else break; + } + if (!el.children[i]?.skipFocus) { + return i; + } + } + return -1; +} +``` + +**The loop.** With `el.wrap` truthy and every child `skipFocus`: + +- the `for` has no condition; +- out-of-range indices wrap back into range, so `break` is never reached; +- `return i` is never reached either. + +It spins forever. The `ArrowRight` keydown task never returns, so the TV +hangs. + +**How it is reached:** + +- `moveSelection` (hn:194), on every arrow press of a `wrap` Row, Column or + Virtual (`wrap={effectiveWrap()}`); +- `navigableForwardFocus` (hn:114), on `setFocus` of such a container; +- `spatialForwardFocus` (hn:282). + +**A related edge case:** `wrap` with **zero** children computes `(i + 0) % 0`, +which is `NaN`. `children[NaN]?.skipFocus` is `undefined`, so the function +returns `NaN`, not -1. It does not hang. `selectChild(el, NaN)` then sets +`selected = -1` and returns false. + +### 4.3 `insertChild(before)` and draw order + +Solid's `insertChild` reorders only its own `children` array (en:947-956). It +reaches the renderer only through the `parent` setter (en:880-885), which +assigns `this.lng.parent = p.lng`. v2's `parent` setter (rv2 `Node.ts:468-488`) +does this: + +```ts +if (old === next) { return; } // same parent: nothing moves +if (old !== NULL) { s.unlink(id); ... } +if (next !== NULL) { s.appendChild(next, id); } // appended at the end, zIndex-sorted +``` + +So the renderer is never told about `before`: + +- **A move within the same parent never reorders renderer siblings.** This + covers `For` and `List` reorders, and the Virtual rotation `n0 → end`. +- **A node inserted before an anchor is appended at the end.** This covers + `` toggling a node in front of a sibling, and a not-yet-rendered node + created through `render()` (en:1544, `props.parent = parent.lng`). + +**Does draw order make this matter?** Yes. + +- In v2, sibling order **is** z-order (spec §5.3: "The list order is the draw + order"). `zIndex` only sorts stably at attach time and when it changes. +- Flex positions come from Solid's `children`, so the layout stays right. But + overlapping siblings with the same `zIndex` draw in the wrong order. +- Example: after a few Virtual shifts the renderer order is arbitrary relative + to the visual order. A focused `Thumbnail` (`zIndex: 2` like its neighbours, + `scale: 1.1`, border `align: 'outside'`) then draws _under_ the neighbour on + one side. +- Example: a `` overlay inserted before a sibling draws on top of it. + +**Renderer API.** There is no public `insertBefore`. `NodeStore` has a +**private** `insertAfter(parent, child, after)` (rv2 `NodeStore.ts:506-509`), +which `appendChild` and `setZIndex` use (:498, :583). A public `insertBefore` +built on it would be inside the brief's allowed integration surface. + +### 4.4 Unknown names written to the v2 handle (spec §13.4) + +**Paths that write to `this.lng`, the handle, after render:** + +| Path | Writes | Unknown names that can reach a `` handle (`Node`) | +| ------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `LightningRendererNumberProps` accessors (en:225-253, 1772-1781) | `_sendToLightningAnimatable` → `this.lng[name] = value` (en:1030-1031) or `animateProp(name)` | `fontSize`, `lineHeight` (they are `TextNode` accessors only) | +| `LightningRendererNonAnimatingProps` accessors (en:258-289, 1783-1792) | `this.lng[key] = v` | `contain`, `forceLoad`, `fontStyle`, `letterSpacing`, `maxHeight`, `maxLines`, `maxWidth`, `offsetY`, `overflowSuffix`, `text`, `textAlign`, `verticalAlign`, `wordBreak` (`TextNode`-only accessors, rv2 `TextNode.ts`) | +| `set fontWeight` (en:903-915), `set fontFamily` (en:921-924) | `this.lng.fontFamily = …` | `fontFamily` | +| `replaceText` (solidOpts.ts:20-26) | `parent.text = parent.getText()` | `text`, when a string child sits directly in a `` (the `insertNode` guard at :43-46 does not apply to `replaceText`) | +| `set src`, `set shader`, `_writeShaderTarget`, the `parent` setter, `render()` `child.lng.parent` | known names | none | +| Virtual, VirtualGrid, Marquee: `lng[axis]`, `lng.y`, `lng.x` | known names | none | + +**Getter-only names in the non-animating list:** `absX`, `absY` and +`destroyed` are getter-only on the v2 `Node` (rv2 `Node.ts:233, 876, 886`). +Writing them on a rendered node **throws a TypeError**, because ES modules are +strict. That is a bug, but only if an app sets them. + +**How app code reaches the unknown names on a ``:** + +- reactive JSX props, for example `maxWidth={…}` on a view; +- state blocks such as `$focus: { fontSize }` applied to a view; +- style objects that mix text props into a view's style. + +Before render the same names sit in the creation bag, and `applyNodeProps` +ignores them (rv2 `applyProps.ts:153-155`). So only post-render writes add +fields. A non-renderer key cannot reach the handle through `setProperty`: +that writes to the `ElementNode` (solidOpts.ts:27-29). + +**The shader facade.** This is not the node handle, but the same hidden-class +concern applies. + +- `parseAndAssignShaderProps` writes `props[actualPrefix] = obj` (en:193): the + name `border`, or `shadow`. +- The v2 facade has no such prop. Its props are `border-w`, `border-color`, …, + and `shadow-*` (rv2 `Box.ts:73-100`). +- So every `ShaderNode` facade grows an own `border` or `shadow` data field. + +### 4.5 Class-field emit + +Transforms of `src/core/elementNode.ts`, `nodeTypes.ts` and `states.ts` are in +`.../scratchpad/classfields/*.js`: + +- **modern:** rolldown 1.1.5 `transformSync`, target `chrome64`, + `assumptions: { setPublicClassFields: true, noDocumentAll: true }`, as in + the demo's `rolldownOptions.transform`; +- **legacy:** that output, then Babel `preset-env` 8.0.2 with targets + `chrome 38` and the demo's `legacy()` assumptions. + +**`ElementNode` has no class fields.** Its members are declared on the merged +`interface ElementNode` (en:309-775). The class body starts with the +constructor. + +- In every variant (esnext, modern, legacy) the constructor is the same + **27 plain `this.x = …` assignments**. +- There are **no `defineProperty` calls, no `_defineProperty` and no + `__publicField`**. +- Legacy wraps the class in `_createClass(function ElementNode(name){…})`, and + defines the prototype accessors once, at module load. +- The demo's comment in its `vite.config.js` ("ElementNode alone has ~70 + fields") is inaccurate for current Solid. + +**`TextNode` has 3 class fields** (nodeTypes.ts:10-17): `_type = 'text'`, +`parent = undefined`, and `text: string`. One `TextNode` is created per JSX +text child. Its emit depends on the tsconfig: + +- With the assumption applied: `this._type = "text"; this.parent = undefined; +this.text = void 0; this.text = text;`. The redundant `void 0` comes from + `useDefineForClassFields`, which defaults to true for `target: ESNext` in + `solid-1.7/tsconfig.json`. +- **When rolldown resolves `solid-1.7/tsconfig.json`**, which it does when + given the real file path, the tsconfig wins over + `assumptions.setPublicClassFields`. The output is then **three + `_defineProperty(this, …)` helper calls per `TextNode`**, in the modern + bundle and in the legacy one (verified: same source, basename versus full + path versus `tsconfig: false`). +- Whether Vite 8's `vite:oxc` plugin resolves the tsconfig this way for + `@solidtv/source` files was **not verified**: the demo app was not built. + Grep the built demo bundle for `_defineProperty(this, "_type"`. +- Setting `"useDefineForClassFields": false` in `solid-1.7/tsconfig.json` + would make the output plain assignments either way. It does not affect + `ElementNode`. + +**`States`** has `private onChange` (states.ts:9). That emits +`this.onChange = void 0` after `super()`, or `_defineProperty` under the same +tsconfig condition. + +In legacy, `class States extends Array` becomes `_wrapNativeSuper(Array)`. +On Chrome 38 (no `Reflect.construct`), every construction then goes through: + +- `_construct` → `new (Array.bind.apply(Array, [null, …]))()`; +- `setPrototypeOf(instance, States.prototype)`; +- the `_super` closure, `_args`, `[].concat` and `_toConsumableArray`. + +`Object.entries` needs a polyfill on Chrome below 54. + +Chrome below 51 has no `Symbol.species`, so `splice` there makes plain +arrays. On Chrome 51-63, which also gets the legacy bundle, the species path +runs and costs about 10 allocations plus `setPrototypeOf` per blur. + +**Legacy assumptions that could pay off on the hot path.** The demo's +`legacy()` assumptions do not include `setSpreadProperties`, +`iterableIsArray` or `skipForOfIteratorClosing`. Without them: + +- object spread compiles to `_objectSpread` with `_defineProperty` per key + (the transition merge on every press, and `combineStyles`); +- `for…of` compiles to `_createForOfIteratorHelper` (`keyExists` on every + `_stateChanged`). + +That is a demo build-config option, not a Solid change. + +### 4.6 Field counts + +- `ElementNode` own fields at construction: **27**, of which 24 start with + `_`. It also allocates the 11-key `lng` bag and a `children` array. +- Expandos added at runtime, measured: tile **+3** (`transition`, `$focus`, + `item`), Row **+18**, Column **+19**, Virtual view **+21** (§3, N1). +- V8 hazard: own-property additions through _keyed_ stores, which is what + `setProperty` does, normalise an object to dictionary mode once its + out-of-object fields exceed `max(12, in-object count)`. For `ElementNode` + that threshold is about 27 or more. The heavy containers are under it today. + Worth checking with `%HasFastProperties` on a deep page. + +### 4.7 Handler storage and lookups + +- `onUp`, `onDown`, `onLeft`, `onRight`, `onEnter`, `onFocus`, `onBlur`, + `onFocusChanged`, `onSelectedChanged` and the custom `on` handlers are + **per-instance own properties**, written by `setProperty` → `node[name] = value`. +- `onLayout` is the only accessor (en:1349-1360). `onRender`, `onCreate` and + `onRemove` are plain properties too. +- Dispatch lookups are `elm[eventHandlerKey]` and `elm[captureEvent]`. Their + keys are template strings **built per key event** (fm:307, 339-340), shared + across the elements of the walk. +- `updateFocusPath` uses static names (`onFocus`, `onBlur`, `onFocusChanged`), + but on varied hidden classes. +- `emit()` builds `` `on${…}` `` per call (en:1098). It is not on the key path. + +--- + +## 5. A Virtual window shift + +The case is a VirtualRow with `displaySize` 6, `bufferSize` 2 (8 children) +and Thumbnail tiles, pressing ArrowRight when `computeSlice` moves `start`. +The steps are in order. + +1. **Keydown dispatch** runs as in §2, A1-6. `onRight` is + `handleNavigation('right')`, with no wrapper. The per-press transition is + allocated and unused (R1). +2. **`selectChild`** → `child.setFocus()`, which schedules + `runPostMutation` twice. Then Virtual's `onSelectedChanged` + (Virtual.tsx:402-476): + - the `setCursor` updater closure; + - `computeSlice` → `SliceState` and `items().slice()`; + - `setSlice`. + + These are signal writes inside the handler's `runWithOwner`. The `List` + memo runs synchronously; the effects wait until the handler returns. The + handler also does `queueMicrotask(() => {…})` (Virtual.tsx:451): 1 closure. + +3. **The handler returns.** Effects then run: + - the **spread effect** re-runs over about 22 props and writes `cursor` + (G1); + - the **`insert` effect** reconciles the rotation (G3). + + Allocations: `normalizeIncomingArray`, a `Map`, `splice` results, rest + arrays, `[j]` arrays ×8, `temp`, a `Map` and a `Uint8Array` in the list. + + Calls: `insertNode` ×2 → `insertChild`; `removeNode` ×1 → + `removeChild` ×3 in total; `render(true)` ×2, both early returns that + add to the layout queue; `enqueueDelete` ×3; the recycled tile's + `item()` setter runs its reactive props. + +4. **Microtask 1, `runPostMutation`:** + - delete flush: nothing is destroyed; + - **flex pass 1** over 8 children, with `[...layoutQueue]`, 7 typed + arrays, the index array and the closure; + - the focus phase as in §2 B (about 38 allocations). +5. **Microtask 2, Virtual's own:** + - **flex pass 2**, which is redundant; + - `computeSize` returns the cached value, or else the `style?.focus` path + (R3); + - `this.lng.x = …` directly; + - `this.animate({ [axis]: target }, { ...this.animationSettings, duration })` + (Virtual.tsx:465-471), with `performance.now()`. That is **2 objects and + a new `Animation` every shift**, about 12 objects plus a Promise. Unlike + `animateProp`, it never reuses the controller. +6. **The frame.** The `reprocessUpdates` callback is a no-op, and there is + 1 walk. If tiles contain text whose content changed on the recycled node, + layout, `loaded` and `_layoutOnLoad` can add a third flex pass and a second + walk (§6). + +**Total:** roughly 150 framework allocations per shift. + +- **2 flex passes**, each with about 20 property reads per child, and 16 + accessor `x` writes; +- 3 `indexOf`-based list operations, plus `getNextSibling` scans; +- 1 new `Animation`; +- no `ElementNode` or renderer-node creation. + +A press _within_ the window still costs, on top of the plain-Row press: + +- a `SliceState`; +- the `setCursor` closure; +- the `List` diff: `temp`, a `Map`, a `Uint8Array(0)` and a `splice` result; +- `normalizeIncomingArray`, and `reconcileArrays` with one `getNextSibling` + scan; +- the spread re-run. + +That is about 10 more allocations and about 3·L more loop iterations than a +plain Row press. + +--- + +## 6. Text leads (the pointer from Layout) + +- `flex.ts:32-34` and `flexLayout.ts:64-66` return early, without layout, when + a text child has `text` but no `width` and no `height`. **Confirmed.** +- `_layoutOnLoad` (en:1140-1145) is registered at render when the parent + requires layout and the text lacks `maxWidth` or `maxHeight` (en:1639-1643), + or for `autosize` (en:1726-1728). + - On every `loaded` it calls `schedulePostMutation()` **and** + `this.parent!.updateLayout()` synchronously, so up to 2 flex passes per + load. + - It is **never removed** (there is no `off`). + - **Confirmed.** +- `getText` re-concatenates on every insert, remove and replace + (solidOpts.ts:25, 45, 60; en:1147-1156). **Confirmed.** + +--- + +## 7. What the survey missed on the key-press path + +1. **keyup doubles the dispatch work, for nothing.** It repeats the closure, + `runWithOwner`, `Effects`, `keyIdentities`, `performance.now()` and + 2 strings. It runs a full capture walk _and_ a full bubble walk, because + nothing handles `onRelease`, and allocates a result object. That is + about 8 allocations and about 5·D keyed misses per press (fm:556-566, + 644-652). +2. **Solid's own render effect on `activeElement`** (render.ts:76-83) runs on + every focus change: `cleanNode` and a re-subscribe. +3. **`Config.setActiveElement` costs about 6 allocations per change** under + `useFocusManager`: an arrow closure, `runWithOwner`'s `Effects`, and + `writeSignal`'s `runUpdates` closure, `Updates` array and `runEffects` + closure (fm:630-631; sj:550, 687-717, 850-866). `_signalWrapper` adds a + closure and an `Effects` array for `setFocusPath` (fm:279). +4. **v2 `animateProp` allocates a Promise each time it restarts a finished + animation** (rv2 `Animation.ts:440-451`, cleared at :453-457 and :626). + That is up to 3 per Row press: `x`, `scale` in, `scale` out. Solid never + reads it on the transition path. +5. **Changing direction recreates the `x` controller.** `animateProp` reuses + a controller only when given the identical settings object (rv2 + `Node.ts:942-956`). `handleNavigation` makes `transition.x` alternate + between `defaultTransitionBack.x` and `defaultTransitionForward.x`. So + every Left↔Right change pays `stop()`, a new `Animation` (about 12 objects, + 4 of them typed arrays) and a slot object. +6. **The `border-w` facade write always allocates and always repacks.** v2 + `vec4Prop.resolve` → `toVec4` returns a new array, and object values + always store and mark (rv2 `Box.ts:41-44`, `ShaderRegistry.ts:1003-1016`). + So each `$focus` apply or undo with a border allocates and marks + `DIRTY_SHADER` even when the width is unchanged. The next visit rebuilds + the params key string. +7. **`$focus` undo restores only the keys the base style has, a behaviour + bug.** `border-gap` and `border-align` written by `$focus` are not reset, + because the base `border` object lacks them. After the first focus and + blur, an unfocused tile keeps `gap: 4`. That is invisible with + `width: 0`, but visible with a non-zero base border (en:1438-1459 with + en:175-204). Pin it with a test before the rewrite. +8. **The Virtual transition merge is dead work** (R1, §5). +9. **Virtual animates the row with `this.animate(...)` per shift, never with + `animateProp`.** That is a new controller plus a settings spread each time + (Virtual.tsx:465-471). +10. **The `States` array-subclass methods probably run V8's generic + builtins** (F6). Confirm it in the profile. +11. **Megamorphic misses through the prototype chain.** `withScrolling` reads + about 25 properties per press, and several more are misses in + `selectChild`, `moveSelection` and the dispatch walks: `throttleInput`, + `skipFocus`, `plinko`, `forwardFocus`, `onFocus`, `onBlur`, + `onFocusChanged`, `scrollIndex`, `centerScroll`, `onScrolled`, … + `ElementNode.prototype` holds about 60 accessors, so each miss walks it. +12. **The bench and the demo use different flex code** (L4). +13. **`removeChild` leaves `node.parent` set.** The next `insertChild` of that + node then pays a full `indexOf` miss in `node.parent.removeChild(node)` + (en:936-937, 959-969). +14. **`'reprocessUpdates' in renderer.stage`** is checked on every + `schedulePostMutation` call, through the `stage` getter (en:96). + +--- + +## 8. Bugs found + +1. **Infinite loop.** `primitives/utils/handleNavigation.ts:42-51`, with + `wrap` and every child `skipFocus` (§4.2). Reached from `moveSelection`, + `navigableForwardFocus` and `spatialForwardFocus`. +2. **`style?.focus` should be `$focus`.** + - `primitives/utils/withScrolling.ts:127` is latent on v2: `scale` always + reads `scaleX`. + - `primitives/Virtual.tsx:104` is live. `factorScale` never sees the + `$focus` scale, and the `style` getter allocates `{}` when there is no + style. +3. **Draw order diverges from Solid's child order.** It happens after any + `insertChild(node, before)` or same-parent move (en:930-957 with rv2 + `Node.ts:468-488`). Overlapping siblings with equal `zIndex` draw out of + order, which hits Virtual rows with a scaled `$focus` and `` before + an anchor. There is no public renderer `insertBefore`. +4. **Text-only names written to a `` handle after render** add own + fields to the v2 `Node` handle (§4.4; en:225-289, 903-924, 1030, + 1789; solidOpts.ts:25). This violates the spec §13.4 invariant whenever an + app sets them. +5. **Getter-only renderer props in the forwarded list.** `absX`, `absY` and + `destroyed` are in `LightningRendererNonAnimatingProps` (en:259-260, 267). + Writing them on a rendered node throws a TypeError on v2. +6. **`$focus` undo leaves shader sub-props set** that the base style does not + name, for example `border-gap` and `border-align` (§7, item 7). +7. **`findFirstFocusableChildIdx` returns `NaN`, not -1,** when `wrap` is set + and there are no children (hn:45). This is benign today. +8. **Measurement validity, not a `src` bug.** The bench runs `flex.ts`; the + demo runs `flexLayout.ts` (`solid-demo-app-1.7/.env`, + `VITE_USE_NEW_FLEX=true`). + +--- + +## 9. Likely top costs per key press + +These are estimates from code reading and the probe counts, for the coordinator +to check against CPU profiles. Solid framework only. + +### ArrowRight within a Row + +1. **State styles on focus change.** Two `_stateChanged` calls (en:1405-1505) + do: + - `Object.assign` through accessors; + - 2 shader-prop parses, about 18 allocations with non-internalised keyed + stores into the facade; + - v2 facade setters, `toVec4` and `DIRTY_SHADER` marks; + - 2 `animateProp` calls with Promise restarts; + - the species construction on `remove` (4 allocations, generic `splice`); + - the undo bookkeeping. + + This is about 30 of the about 56 framework allocations. + +2. **Reactive work per focus change.** It includes: + - `Config.setActiveElement` and `setFocusPath`, which are 2 + `runWithOwner`/`runUpdates` passes (about 9 allocations); + - Solid's own `activeElement` effect; + - **every app effect on `activeElement`**; + - unbatched signal writes in `onFocus`, `onBlur` and `onFocusChanged`, + each flushing on its own. In the demo, Portal-style reactive text colours + each flush separately. +3. **Key dispatch, doubled by keyup.** Two `runWithOwner` passes, + 2 `keyIdentities` arrays, 4 template strings, and capture walks over the + full path on both events plus a full bubble walk on keyup. That is about + 32 keyed megamorphic misses for D = 4, linear in page depth. +4. **`updateFocusPath`.** The D-ancestor walk with `states.has` on an + `Array` subclass (probably the generic `indexOf`), 3 handler lookups per + element, the O(D²) diff, the fresh `fp` array, and the add/remove + bookkeeping on the ancestors. Down/Up also runs `_stateChanged` on 2 Rows. +5. **`scrollRow`/`withScrolling` plus the `x` write.** About 25 property + reads, many of them prototype-chain misses; `_sendToLightningAnimatable`'s + transition lookups and `in` check; `animateProp`, which on a change of + direction makes a new `Animation` with typed arrays. +6. **The `handleNavigation` transition merge.** 1 object per press, or 2 + `_objectSpread` calls with `defineProperty` per key on the legacy bundle. +7. **Hidden-class and megamorphic overhead** on every `ElementNode` property + access. Containers carry 18-21 expandos in varied orders; handlers and + state blocks are expandos read with computed keys. +8. **Allocation pressure overall:** about 56 framework allocations plus about + 15 renderer allocations per press in the modern bundle, about 80 more in + legacy. The GC cost is amortised, but it shows as dropped frames on TVs. +9. **`schedulePostMutation` double registration.** The microtask plus + `reprocessUpdates`: the frame run is a no-op that still forces a frame. + Small per press. +10. **Renderer side, for the first frame:** one full walk of the visible tree, + shader repacks for 2 tiles (the params key string), then about 15 + animation frames, each with a walk and a draw. + +### VirtualRow or VirtualGrid press that moves the window + +The Row costs above, plus, in about this order: + +1. 2 flex passes, each with 7 typed arrays, the index array, the closure, + about 20 property reads per child and an accessor write per child. +2. `List` diff and reconcile: a `Map`, a `Uint8Array`, a `[j]` array per item, + 3 `indexOf`s per move, `getNextSibling` scans and `splice` results. +3. The full spread re-run on `cursor`. +4. A new `Animation` from `this.animate` per shift. +5. `SliceState`, the `setCursor` closure and the `slice` array. + +Node creation is **not** on this path: `List` recycles nodes. + +--- + +## 10. Uncertain, or not verified here + +- Timings: none were taken, per the shared rules. The probe counts calls. +- The V8 generic-builtin behaviour of the `States` `Array` subclass + (`indexOf`, `push`, `splice`) is inferred from V8's fast-path conditions. + Confirm it in a CPU profile. +- Whether the demo's modern bundle emits `_defineProperty` for `TextNode` and + `States` depends on Vite 8 resolving `solid-1.7/tsconfig.json` for source + files. Not built (§4.5). +- Allocation counts are upper bounds; V8 escape analysis may remove the + short-lived result objects and closures in optimised code. +- The probe ran on the DOM renderer, which has no `animateProp`. So `animate` + and `animateProp` reuse on v2, Promise restarts and facade writes come from + code reading of `renderer-v2-solid`, not from measurement. diff --git a/docs/perf/text-flex-alternatives.md b/docs/perf/text-flex-alternatives.md new file mode 100644 index 00000000..f27c4652 --- /dev/null +++ b/docs/perf/text-flex-alternatives.md @@ -0,0 +1,763 @@ +# Text measurement and flex layout: alternatives review + +Draft section for the Checkpoint 1 design spec +(`docs/superpowers/specs/-solid-1.7-design.md`), written 2026-10-03. +It answers the brief's "Text measurement and flex layout" section: how it +works today, alternatives 1 to 9, and a recommendation. + +Code read: `solid-1.7` at `517094d` (solid 1.6.4 + the renderer-v2 lockstep +patch, arm B/C), `renderer-v2-solid` at `faf4b9f`, and renderer 1.9.3 (arm A, +`bench/.arms/renderer-a`) for comparison. Line numbers are at those commits. + +**All numbers are indicative.** They come from short runs on a shared +14-core Apple M4 Pro (48 GB; load average 3 to 5 while other agents ran), +Node 24.13.0, and Playwright 1.56 headless Chromium with SwiftShader. No CPU +throttling. Chromium's `performance.now()` resolution there is 100 µs (I +measured it), so the per-press millisecond figures from the browser are +averaged over many presses and remain coarse. The structural counts are +exact: walks, `loaded` events, flex passes and layouts. The coordinator's +throttled benchmark suite should confirm the CPU figures. + +## Summary + +- **Today, a text change inside a flex container costs two scene walks per + frame.** The text is laid out in walk 1. Its `loaded` event runs Solid's + flex between the walks, and the flex writes force walk 2. +- **Flex runs once per `loaded` event, not once per container.** In a + details-panel scenario (title, description, metadata row with badges), + one press ran **12 flex passes over 4 containers**: the panel 4 times and + the metadata row 4 times. +- **Text under a culled ancestor is never laid out, so its flex container + waits.** The ancestor may be out of bounds or have world alpha 0. In a + Row of 20 flex tiles, 11 tiles (22 texts) are never laid out until they + scroll into the bounds margin. Arm A gates text layout the same way. +- **A synchronous `TextNode.measure()` fixes this.** It lays the text out + into the same `LayoutCache` that the walk reads. I prototyped it in + scratch copies: about 60 lines in the renderer and 45 in Solid. Solid + calls it in its post-mutation pass, before flex. + - Details panel: **1 walk instead of 2**, **0 `loaded` events instead of + 6**, **5 flex passes instead of 12**, and **0 layouts in the walk**, + because the walk reuses the measured layouts. + - Final positions are identical. + - Ordering the layout queue by depth would bring this to 1 flex pass per + affected container. +- **Cheaper text measurement inside the renderer.** Both changes stay within + the brief's "text measurement" boundary: + - A cache keyed by the text string, with the other props compared field + by field: **0.02 µs instead of 0.36 to 0.71 µs per lookup, and no + allocation instead of 0.9 to 1.1 kB.** + - Typed-array advance and kerning tables for the line breaker: **3.2× + faster for a title and 2.3× faster for a description.** Lines and widths + are bit-identical in 17,100 cases. +- **Rejected:** + - A separate width-only fast path, because the walk would then lay the + text out a second time. + - Size estimates before the font description loads, because they are + 13% to 26% wrong. + - Flex inside the renderer walk, which touches `ScenePass` (out of + bounds). It goes to `renderer-proposals.md`. + - Yoga, Taffy and css-layout: wasm (Chrome 57+), 80 kB gzip for asm.js, + or different semantics. + +--- + +## 1. How it works today, verified + +### 1.1 The brief's claims + +| # | Claim (brief) | Verdict | Evidence and corrected description | +| --- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| a | `flex.ts` (~l.32) gives up on the whole container pass when a text child has text but no width/height | **Confirmed** | `src/core/flex.ts:32-34`, `src/core/flexLayout.ts:64-66`: `if (isElementText(c) && c.text && !(c.width \|\| c.height)) return false`. The pass returns before any write and does not propagate up. `width` is `maxWidth \|\| w` (`elementNode.ts:887-901`), so text with a `maxWidth` (`contain`) never bails. **Extra finding:** the bail is tested _before_ `flexItem === false` (`flex.ts:36`, `flexLayout.ts:68`), so an unsized text with `flexItem={false}` blocks the whole container. Both implementations behave the same; the demo app uses `flexLayout.ts` (`solid-demo-app/.env`: `VITE_USE_NEW_FLEX=true`), while the tests and the default build use `flex.ts` (`elementNode.ts:22-24`). | +| b | `_layoutOnLoad` listens for `loaded`, schedules the post-mutation pass and calls `parent.updateLayout()` synchronously: two flex passes per load? | **Partly** | `elementNode.ts:1140-1145`. The listener is registered at render when the parent requires layout and the text lacks `maxWidth` or `maxHeight` (`:1639-1643`; also `:1726-1728` for `autosize`). `schedulePostMutation()` (`:93-100`) adds **nothing** to `layoutQueue`, so it does not cause a second pass of the same container. Each load runs **one synchronous pass of the parent**. If the parent's size changed, `updateLayout` queues the grandparent (`:1387-1389`), and the post-mutation pass runs it, and so on up the tree. **The real multiplier is per text:** a container with _k_ texts that relaid gets _k_ synchronous passes in one frame. Measured: per details-panel press, panel ×4, metadata row ×4, badges ×2-4, for 12 passes (§1.2). | +| c | The listener is never removed | **Confirmed** | No `off(` anywhere in `src/core` (only the DOM renderer's own `once`). The listener lives as long as the node. It fires on **every** relayout of that text, whether or not the size changed: `TextNodes.ts:107-112` queues `loaded` whenever a layout is made and a listener exists. It also fires if the parent later stops requiring layout. | +| d | Text children are re-concatenated (`getText`) on every insert and update | **Confirmed**, cheap | `elementNode.ts:1147-1156`; called from `solidOpts.ts:20-26` (`replaceText`), `:43-46` (`insertNode`), `:58-61` (`removeNode`) and `render()` (`elementNode.ts:1591`). A single child returns its string without allocating; _n_ children build one new string per update, which is O(n²) at mount. In practice n is 2-3 (`{votes} reviews`). The cost is tens of ns. The only consequence worth noting: each update makes a fresh string object, whose hash a text-keyed cache must compute once (0.11 µs instead of 0.02 µs, §2.4). | +| e | v2 lays text out inside the scene pass, during the node's visit, once the font description is there; the atlas is not needed | **Confirmed** | `ScenePass.ts:350-364`: `DIRTY_LAYOUT` is handled first in the visit, before the transform and before the node's own culling. `TextNodes.ts:83-90` waits for `font.font` (the description); atlas readiness gates only drawing (`:115-123`). | +| f | `loaded {type:'text', dimensions}` is queued and delivered between walks; Solid's flex writes re-run the walk (up to 3) | **Confirmed** | Queued in `TextNodes.ts:107-112` only when a listener exists; the payload allocates 2 objects. Delivered at `RendererCore.ts:572` (`textEvents.flush()`), then the `reprocessUpdates` callback at `:574-578`. The walk repeats while `writesDuringPass > 0 \|\| postUpdate !== null`, up to 3 walks (`:580-584`). Writes are counted by `markDirty` (`NodeStore.ts:472-492`). The in-walk layout size uses `applySizeInVisit`, which does not count (`NodeStore.ts:573-581`). | +| g | A text whose size changes in a flex container costs a walk, the layout, the event, a flex pass and a second walk | **Confirmed, refined** | The second walk happens **only when the flex pass writes**. Setters ignore equal values (`Node.ts:116-123`). If a relayout keeps its size, the event and the flex pass still run, but the frame has one walk: the handler's `reprocessUpdates(cb)` is consumed in the same iteration. A third walk needs a layout in walk 2, for example flex writing `width` on a text child (`flexGrow`, `minWidth`), which becomes `maxWidth` and a relayout. Sequence and counts: §1.2. | +| h | Layouts are cached in an LRU (`textLayoutCacheSize`, default 250), keyed by a string `layoutKey` builds on each lookup | **Confirmed** | Default 250: `RendererCore.ts:65`. Shared by every node, keyed by content. The LRU is a `Map` with delete and re-set on every hit (`TextLayout.ts:957-966`), trimmed on insert and at idle `maintain` (`Renderer.ts:617`). `layoutKey` (`TextLayout.ts:991-1017`) concatenates the font id and 10 props, text last. "Per lookup" means per relayout of a stale node in its visit (`TextNodes.ts:93-99`), **not per frame**. It costs 0.36 µs for a title and 0.71 µs for a description, plus 0.9-1.1 kB of garbage: the cons-string chain and its flattening (§2.4). | +| i | After creation, `w`/`h` on a text node map to `maxWidth`/`maxHeight` | **Confirmed** | `TextNode.ts:136-147`. In `createTextNode`'s props, `w` and `h` are the size before the first layout (`applyTextProps`, `:474-479`, `setSize` `:377-384`). For Solid, a flex write of `width` on a text child (`flexGrow`, `minWidth`) sets `maxWidth`, which triggers a relayout and possibly wrapping. | +| j | Is text the walk does not visit (culled, hidden, alpha 0) ever laid out? Solid's flex waits for it | **Confirmed, with a nuance**; it waits, usually not forever | See §1.3. | + +### 1.2 A text change in a flex container on v2, traced and measured + +Here is the sequence for one key press that changes texts in nested flex +containers. The scenario is shaped like the demo app's `ContentBlock`: a +flex column panel with a title, a description (`contain="width"`, +`maxLines={3}`) and a flex row of metadata, which holds two texts and +2-3 badges, each a flex view with a text. + +1. **Key handler.** + - Solid effects run `replaceText`, then `parent.text = getText()`, then + the renderer's `text` setter. + - The setter marks the node stale (`DIRTY_LAYOUT`) and schedules a frame. + - No Solid layout is queued for a text change. Only new nodes (here, new + badges) queue their parent from `render()` (`elementNode.ts:1523-1525`). +2. **Microtask.** `runPostMutation` runs the queued containers. A new badge + bails because its text has no size yet. +3. **rAF frame, `RendererCore.update()`**, iteration 1: + 1. Walk 1 lays out every visited stale text and queues one `loaded` per + text (6 here). + 2. `textEvents.flush()` runs Solid's handler per text: + `schedulePostMutation()`, which calls `reprocessUpdates(runPostMutation)` + and `queueMicrotask`, then a synchronous `parent.updateLayout()`. That + is a flex pass, and it writes x, y and the container size. + 3. The `postUpdate` callback, `runPostMutation`, runs ancestors whose size + changed. +4. **Iteration 2.** `writesDuringPass > 0`, so walk 2 runs. The stream is + rewound and every visible node is visited and emitted again, glyphs + included. No new layouts, so the loop stops. +5. **After the rAF callback.** The microtask `runPostMutation` queued in + step 3 runs. It is a no-op, a second run of the same pass. The same + double scheduling happens on every `schedulePostMutation` (focus changes + too): one run is consumed by the renderer callback, the other by the + microtask. + +Measured with Solid on the real renderer v2 (WebGL, SDF Lato), counters +wrapped around `renderer.update`, `textEvents.queue` and +`ElementNode.prototype.updateLayout`. Median of 60 presses: + +| Scenario | Walks in the frame | `loaded` | Flex passes (bails) | Layouts in the walk | Frame `update()` (desktop, mean) | +| --------------------------------------------- | ------------------ | -------- | ------------------- | ------------------- | -------------------------------- | +| S1 details panel press (5-6 texts change) | **2** | 6 | **12** (2) | 6 | 0.13-0.21 ms | +| S2 Row of 20 flex tiles (2 texts each), mount | **2** | 18 | **40** (20) | 18 of 40 | about 0.33 ms | + +These are the flex passes for one S1 press, in order: +`badge, meta, panel, panel, panel, meta, meta, badge, meta, panel` +(and 12 on the next press). Only 4 containers changed. + +The re-walk costs roughly a whole frame's walk and emission. v2 rewinds the +stream and re-emits every visible quad and glyph (`RendererCore.ts:567-569`). +HANDOFF's host frame times give the scale: 0.05 to 0.34 ms per drawn frame +on a laptop for stress-tv tiers 1-4. A text-heavy details page sits at the +upper end, and a TV is much slower. + +### 1.3 Text the walk does not visit + +- **The text node's own culling does not stop its layout.** + - Layout runs first in its visit (`ScenePass.ts:350-364`), before its own + bounds and alpha are derived. + - So a text that is itself out of bounds or alpha 0, under a visible + parent, is laid out. Marquee's `hidden` texts are an example. +- **A text under a culled ancestor is not visited at all.** + - Culled means out of bounds including the bounds margin, or world alpha 0 + (`ScenePass.ts:558-562`, and `:272-274` where children are not pushed). + - Its `DIRTY_LAYOUT` stays pending, so there is no layout and no `loaded`. + - Solid's flex for its container bails and leaves the children where they + were. + - `forceLoad` is the only escape: `TextNodes.drainForced`, `:133-148`, + lays the text out before every walk. + - Spec §6 step 5 states the rule ("lay out first if their font is ready + and their parent is visible"). +- **Arm A is the same.** In renderer 1.9.3, `CoreTextNode.allowTextGeneration` + (`CoreTextNode.ts:122-131`) requires the parent's `worldAlpha > 0` and the + parent in bounds, unless `forceLoad`. So this is not a v2 regression. +- **Measured (S2):** tiles 9-19 of the 20-tile Row sit beyond the margin. + - Their 22 texts are never laid out. + - `tile19` keeps height 10, the row's, where a laid-out tile is 77.12. + - In S3, a flex container under an alpha-0 view, and one at x = 3000, both + keep their sibling square at x = 0 through a text change: no `loaded`, + no flex pass. + - When they are shown: 2 `loaded`, 2 flex passes, 2 walks. The final + position is x = 425.44, the same in every arm. +- **Does it wait forever?** Only when the app makes visibility depend on + that size. For example: + - a container revealed from `onLayout` or `onEvent.loaded` once a child + text has a size; + - a container whose in-bounds position comes from a flex pass that waits + on its own text. + + Otherwise it waits until the ancestor is visited. On the key-press path + that means the frame that scrolls a tile into the margin pays the second + walk. + +### 1.4 Related findings + +- **`flexItem={false}` text blocks the container.** Bail before the + `flexItem` test, `flex.ts:32` vs `:36` (and the same in `flexLayout.ts`). + It is a bug candidate, and fixing it changes layout results only for that + case. +- **`contain` plus `maxLines={1}` sets `maxHeight` from `lineHeight || fontSize`** + (`elementNode.ts:1618-1621`). + - A multiplier `lineHeight` (≤ 3, for example 1.2) becomes + `maxHeight = 1.2`. + - The `height` getter then reports 1.2 (`maxHeight || h`), and a flex + column stacks the next sibling 1.2 px below. + - It predates 1.7 and is the same in arm A's semantics. It needs a test + before it is fixed, because it is a layout-result change. +- **Flex pass allocations confirmed.** Per pass: an index array, 7 + `Float32Array`s and the `doCrossAlign` closure. That is about 2.1 kB of JS + heap per pass, plus off-heap backing stores above 16 children (§2.5). + `flex.ts:160-162` still has a production `console.warn`. +- **Text color and alpha never reach layout.** On the renderer side only the + layout props call `relayout` (`TextNode.ts:108-112` and the setters); color + goes through `setC` and raises `DIRTY_COLOR` only. Solid's state styles + that change only color or alpha queue no layout. +- **The DOM renderer measures asynchronously.** + - `scheduleUpdateDOMTextMeasurement` (`domRenderer.ts:1204-1231`) runs on + `setTimeout`, or on `document.fonts.ready`. + - It emits `loaded` only the first time or when the size changed + (`:1143-1153`). + - Its stage has no `reprocessUpdates` (optional in `domRendererTypes.ts:31`), + so Solid uses only the microtask there. + +--- + +## 2. Alternatives reviewed + +Per-op costs measured in Node, on the renderer's own compiled text code (a +scratch copy of `renderer-v2-solid`), with the demo app's +`Lato-Regular.msdf.json` (123 glyphs, 1,427 kerning pairs, fractional +advances). The corpus has 25 titles of 20-40 characters and 25 synthesized +descriptions of 200-400 characters, laid out at `maxWidth` 900 with +`maxLines` 3. Medians of 7 rounds. + +Allocations come from V8's sampling heap profiler at a 1-byte interval, +collected objects included: the method of the renderer's +`test/allocations.ts`. I subtracted the harness's 16 B. + +| Operation (desktop, Node 24) | µs/op | Bytes/op | +| ----------------------------------------------------------------- | --------------- | -------------------------------------------------- | +| `layoutText` title, 30 px, 1 line, no `maxWidth` | 1.37-1.56 | about 1,460 | +| `layoutText` description, 24 px, `maxWidth` 900, `maxLines` 3 | 13.4-14.8 | about 12,600 | +| `mapTextLayout` only (lines and size, no glyph runs), title | 0.60-0.63 | n/a | +| `mapTextLayout` only, description | 6.5-7.0 | n/a | +| `layoutKey` + `LayoutCache.get` (hit), title | 0.36-0.39 | about 850-900 | +| `layoutKey` + `LayoutCache.get` (hit), description | 0.71-0.78 | about 1,120 | +| `layoutKey` string build alone, description | 0.045 | 40 (cons strings; flattening happens in `Map.get`) | +| Text-keyed `Map` + field compare (hit), title or description | **0.018-0.020** | **0** | +| Same, with a freshly built text string (hash not cached yet) | 0.11 | 0 (the bench builds the string) | +| `sdfFont.measureText`, whole title | 0.52-0.55 | 0 | +| Typed-array advance + kerning measure, whole title | **0.07-0.15** | **0** | +| Width-only `fastSize` (w and h, no glyph runs), title | 0.15 | 0 | +| `measure` on a cache miss (key + get + `layoutText` + set), title | 2.5 | about 2,500 (includes the bench's unique string) | +| Chromium: prototype `TextNode.measure()`, miss / hit, title | 2.1 / 0.6 | n/a | + +### 2.1 Alternative 1: the status quo (event-driven) + +These are the figures of §1.2: + +- 2 walks on every frame where a text in a flex container changes size; +- one `loaded` event per relaid text, with a payload of 2 objects; +- one synchronous flex pass of the parent per event (12 passes for 4 + containers in S1); +- flex containers under culled ancestors left unlaid; +- the post-mutation pass scheduled twice per schedule. + +It fails the brief's target for a text change in a flex container: one walk +per frame and one flex pass per affected container. **Rejected.** + +### 2.2 Alternative 2: synchronous measurement in the renderer (prototyped) + +**Renderer side.** About 60 lines, in a scratch copy only; `ScenePass` is +untouched: + +```ts +// TextNode (handle accessor surface): a method, no handle field. +measure(): boolean { + return this.id === NULL ? false : this.renderer.textNodes.measure(this.id); +} + +// TextNodes (text measurement; shares layoutText's cache and loaded queue). +measure(id: number): boolean { + const s = this.nodes; + const t = s.texts[id] as TextState; + const font = this.fonts.get(t.fontFamily); + if (font === undefined || font.font === null) return false; // no description yet + if (t.stale === false && t.layout !== null && t.font === font) return true; // nothing due + t.stale = false; + t.font = font; + const key = layoutKey(font.id, t); + let layout = this.cache.get(key) ?? null; + if (layout === null) { + layout = layoutText(t, font.font, this.baselineMode); + this.cache.set(key, layout); + } + t.layout = layout; + s.applySize(id, layout.width, layout.height); // DIRTY_LOCAL | DIRTY_SHADER, composed by the next walk + s.markDirty(id, DIRTY_LAYOUT); // the visit still places the block and derives readiness + const node = s.handles[id] as EventEmitter; + if (node.hasListener('loaded') === true) { + this.loadedEvents.queue(node, 'loaded', { + type: 'text', + dimensions: { w: layout.width, h: layout.height }, + }); + } + return true; +} +``` + +**The walk reuses the layout without any change to the walk.** +`TextNodes.layoutText`, the visit hook, already skips the layout when the +text is not stale and the font is the same (`TextNodes.ts:93`). So the visit +only places the block and derives readiness. Measured: **0 layouts in the +walk** after a measure. + +**Solid side.** About 45 lines, behind a flag: + +- `render()` calls `measure()` instead of registering `_layoutOnLoad`. + - If `measure()` returns false (no description yet), a one-shot `loaded` + listener re-queues the parent once. +- A `text` write on a measured text queues its flex parent. +- `updateLayout()` measures the due text children before `calculateFlex`. + +Measured with Solid on the real renderer, same harness and scenarios as +§1.2: + +| Scenario | Arm | Walks | `loaded` | Flex passes (bails) | Layouts: measure / walk | Final positions | +| --------------------------- | ---- | ----- | -------- | ------------------- | ----------------------- | --------------------------------------- | +| S1 details panel press | now | 2 | 6 | 12 (2) | 0 / 6 | reference | +| S1 details panel press | sync | **1** | **0** | **5** (0) | 6 / **0** | **identical** | +| S2 Row of 20 tiles, mount | now | 2 | 18 | 40 (20) | 0 / 18 (22 never) | tiles 9-19 unlaid | +| S2 Row of 20 tiles, mount | sync | **1** | **0** | **21** (0) | 40 / **0** | all 20 laid out | +| S3 culled container, change | now | n/a | 0 | 0 | 0 | stale until shown, then 2 walks | +| S3 culled container, change | sync | n/a | 0 | 2 | 2 / 0 | correct while culled; 1 walk when shown | + +**CPU.** Per S1 press, three runs each, desktop, means of 55 presses: + +| Arm | Frame `update()` | Microtask (Solid post-mutation) | Total | +| ---- | ------------------ | ------------------------------- | ------------ | +| now | 0.135-0.211 ms | 0.144-0.164 ms | 0.28-0.38 ms | +| sync | **0.055-0.085 ms** | 0.204-0.224 ms | 0.27-0.30 ms | + +- The frame loses the second walk, the 6 handlers and 7 flex passes. +- The microtask gains the 6 layouts, which move out of the frame. +- On this small scene (about 20 nodes) the net is within noise to about + −20%. The walk saved grows with visible nodes and glyphs; the layouts moved + do not. +- At S2 mount the sync arm lays out 22 more texts: the offscreen tiles. + `measure()` costs 2.1 µs per title on a miss in Chromium. + +The 5 flex passes in sync S1 are `panel, badge, badge, meta, panel`. The +panel ran twice because the queue ran it before the metadata row whose size +then changed. Processing the queue deepest first gives 4, one per affected +container (§2.5). + +**Boundaries.** + +- `TextNode.ts` is node and text-node accessors; `TextNodes.measure`, + `LayoutCache` and the `loaded` queue are text measurement and `loaded` + delivery for text. Both are in bounds. +- No handle field: state stays in `TextState`. +- Setters still only store and mark. +- Sizes go through `applySize`, as CLAUDE.md requires for any size written + outside the visit. + +**Verdict: adopt.** It is the core of the recommendation. + +### 2.3 Alternative 3: a width-only fast path for single-line text + +- **Prototype.** Per-font `Float64Array` advances indexed by code unit + (`Float64Array` because Lato's advances are fractional), kerning in a + `Map` or an open-addressed `Int32Array`/`Float64Array` hash keyed by + `second * K + first`, and `letterSpacing`. +- **Parity.** w and h are bit-identical to `layoutText` for unwrapped text + in 360 of 360 cases: titles, kerning pairs, digits, curly quotes, missing + glyphs (fallback), ZWSP and invisible characters, astral characters, runs + of spaces; 6 variants of size, `letterSpacing` and `lineHeight`. +- **With `maxWidth` set,** the 1.10 breaker measures word by word + (`wrapLine`). A whole-line sum then differs in 42 of 59 cases by up to + 3.4e-13 px, from summation order. So a width-only path is valid only for + `maxWidth === 0`, or it must replicate the word-by-word sum. +- **Speed:** 0.15 µs against 1.4 µs for the full layout of a title (9×). +- **Why reject it as a separate path:** + - Every measured text that is also drawn would pay the fast path _and_ + the full layout in the walk. + - It adds a second width function to keep in parity with the pinned 1.10 + breaker. + - It covers only single-line text. +- **Keep instead: the same tables inside the existing breaker.** + - `mapTextLayout` takes its width function as a parameter. Plugging the + typed-array measure into it gave **bit-identical lines and widths in + 17,100 cases**: 25 titles, 10 edge strings and 60 descriptions, × 4 + font sizes × 3 `letterSpacing` values × 5 `maxWidth`/`maxLines` pairs + × 3 `wordBreak` modes. + - Line breaking: **0.63 → 0.20 µs for a title (3.2×), 7.0 → 3.1 µs for a + description (2.3×).** + - This speeds up both `measure()` and the walk's layout with one source of + truth. In bounds: line breaking and measurement in `TextLayout.ts`. + - Build the tables lazily per `SdfFont` from the description. That is + read access. Building them in `parseSdfFont` changes `sdfFont.ts` + beyond read access, so that would need the user's call. +- **A related option, lazy glyph runs.** + - `mapTextLayout` is 43% to 45% of `layoutText`; glyph runs are the rest. + - `measure()` could store lines and size and build glyph runs on first + draw. + - That halves the cost of text measured but never drawn: the offscreen + tiles that eager measuring now lays out. + - Defer it until a profile shows offscreen measuring. + +**Verdict:** reject the separate width-only path. Adopt the typed-array +tables in the breaker (a follow-up commit). Keep lazy glyph runs in reserve. + +### 2.4 Alternative 4: cheaper caching + +- **Keys that build no string per lookup.** + - `layoutKey` builds a 21-part cons string; `Map.get` flattens and hashes + it. + - That costs 0.36 µs (title) and 0.71 µs (description), plus 0.9-1.1 kB of + garbage. + - The prototype uses a per-font-record `Map` keyed by the node's own text + string, with a chain of entries comparing the other 10 props field by + field and an LRU by use stamp. Each string object caches its own hash. + - It costs **0.018 µs and 0 B per hit**, or 0.11 µs for a newly built text + string, whose hash is computed once. + - Correctness: there is no hash of the props, so no collisions. The text + is compared by `Map` equality and the props by `===`. + - It must keep `LayoutCache`'s contract: bounded to + `textLayoutCacheSize`, least recently used out first, trimmed at idle. + Its tests change with it. + - It is worth one focused renderer commit. The gain per relayout is small + in µs, but it removes about 1 kB of garbage per text change (priority 4 + in the brief). +- **A per-font map of text to width.** + - `LayoutCache` already shares whole layouts by content across nodes. + - A separate width map adds nothing once `measure()` fills the shared + cache. Not needed. +- **Measurements shared across nodes; virtual lists remount the same titles.** + - Already true: the cache is keyed by content, not by node. + - The risk is capacity. With eager measuring (§2.2), offscreen tiles fill + the cache too. + - A browse page with 7 rows × 20 tiles × 2 texts is 280 entries, above the + default of 250. + - Memory: about 1.5 kB per title layout and about 12.6 kB per description. + - Measure the hit rate in the benchmark suite's VirtualRow text scenario + before changing the default. + +**Verdict:** adopt the text-keyed cache. No separate width map. Revisit the +cache size with data. + +### 2.5 Alternative 5: dirty-tracked layout in Solid + +- **Re-run flex only on containers whose children changed size, propagated + up the tree.** + - Today `loaded` drives it, with one pass per text: S1 runs the panel and + the metadata row 4× each. + - With `measure()`, a text change queues its parent once (`Set`). + - The queue must run **deepest first**, children before parents. Then a + parent whose child's size changed is not run before that child. + - Measured order `panel, badge, badge, meta, panel` would become + `badge, badge, meta, panel`. + - Propagation upward already happens only when a pass changed the + container's size (`updateLayout`'s return, `elementNode.ts:1387-1389`). +- **Skip the relayout when the measured size did not change.** + - With `measure()`, compare `w` and `h` before and after, and queue the + parent only on change. + - Today the event fires and flex runs even when the size is the same + (§1.1 c, g). +- **Never let a text color or alpha change reach layout.** Already true + (§1.4). +- **Cost of a flex pass**, as a scale for what fewer passes save: + - Plain mock nodes in Node: 1.4-1.5 µs for a row of 20 tiles; 0.29-0.36 µs + for a tile with 2 texts; about 2.1 kB of JS heap per pass in both + implementations. + - The real stack in Chromium, with `ElementNode` accessors and v2 setters, + no writes: **7.3-12.3 µs** for the 20-tile row and **1.2-1.4 µs** for a + tile. + - Accessors and setters cost 5-8× the algorithm itself. + - In S1, going from 12 passes to 4 saves about 8 passes (about 10-15 µs + desktop) and about 17 kB of garbage per press. + +**Verdict:** adopt the depth-ordered queue and the unchanged-size skip. The +`Float32Array` and closure allocations belong to the flex rewrite (the +brief's "Layout" lead), outside this section. + +### 2.6 Alternative 6: not waiting on text that cannot affect layout + +- **Text with a fixed width and `contain`.** + - Solid already registers no listener when both `maxWidth` and + `maxHeight` are known (`elementNode.ts:1640`). + - Flex does not bail when `width` (`maxWidth`) is known. + - A multi-line `contain="width"` text still needs its height in a column, + so it rightly waits. +- **`flexItem={false}`.** Fix the order in `flex.ts` and `flexLayout.ts`: + skip the child before the text bail, and do not measure it or listen for + it. This changes results only where it unblocks a container that is + blocked today. Pin it with a test. +- **Containers whose size and positions do not depend on that child.** + - For example, the last child of a `flexBoundary="fixed"` row with + `flexStart`. + - The gain is marginal and needs per-mode dependency rules. Not + recommended: with synchronous measuring nothing waits anyway. + +**Verdict:** adopt the `flexItem` fix (a bug fix, recorded in +`MIGRATION-1.7.md`). Nothing else. + +### 2.7 Alternative 7: before fonts load + +- **Today (both arms):** hold. + - Text waits for the font's description; flex bails; the first walk after + the description arrives lays the text out and the `loaded` path runs. + - `loadFonts` resolves only once the atlas is uploaded + (`FontRegistry.ts:324-326`). The description, about 141 kB of JSON for + Lato, lands first (`:246-247`). +- **Estimation.** + - Average advance × length is off by **−12.6% to +25.8%** (median +21%) + on the corpus with Lato's own average advance. + - With a font-agnostic 0.5 em it is off by −16.5% to +20.2%. + - Without the description only the font-agnostic guess is available. + - Every correction moves siblings visibly. If they have `transition` set, + the correction animates, and each correction is one more flex pass and + one more walk. +- **Recommendation: hold.** + - `measure()` returns false until the description is there. + - Solid then falls back once to a one-shot `loaded` listener (prototyped), + the old path but only for the first layout. + - Apps preload with `loadFonts` at startup, so the window is the first + screen only. + +**Verdict:** hold, as today. Reject estimation. + +### 2.8 Alternative 8: flex inside the renderer's walk (on paper) + +- **What it would buy.** Text size is known in the visit; no event, no + re-walk, no Solid pass. +- **Why not for 1.7:** + 1. It changes `ScenePass`, which is out of bounds, and the `NodeStore` + layout (flex props per node in new typed arrays), also out of bounds. + 2. Flex with content-sized containers needs a bottom-up measure and a + top-down placement. That breaks the renderer's "one scene pass per + frame" invariant: either two walks or a separate pre-pass. A pre-pass + over dirty containers before the walk is what Solid's post-mutation + pass plus `measure()` already is, without moving flex into the + renderer. + 3. Solid's flex semantics would have to move into the renderer, along + with every behaviour of today's flex: + - `flexBoundary`, `flexCrossBoundary`, `flexItem`, `flexOrder` and + `preFlexwidth`/`preFlexheight`; + - `_calcHeight` and `_containsFlexGrow`; + - two implementations; + - `onLayout` callbacks and Row/Column scroll-on-layout. These are user + code, so they would have to run between walks anyway, which is again + an event and a re-walk. + 4. The DOM renderer would need the same engine. +- **Gain over Alternative 2 plus a depth-ordered queue:** none on the walk + count (one walk in both). Only Solid's per-pass accessor overhead would + shrink, and the flex rewrite can address that inside Solid. + +**Verdict:** reject for 1.7. File it in `renderer-proposals.md` as "layout +inside the scene pass", with the evidence above. Prerequisite: the measured +cost of Solid's flex after its rewrite. + +### 2.9 Alternative 9: third-party layout engines + +| Engine | Format | Size (min / gzip, bundlephobia) | Chrome 38 / 47 | Notes | +| ----------------------------- | ------------------------------------------------------------------------------------------------ | ------------------------------------------ | ------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | +| `yoga-layout` 3.2.1 | wasm embedded in an ES module; `loadYoga()` is async (`yoga-layout/load` for no top-level await) | 127 kB / 52 kB | **No.** WebAssembly needs Chrome 57. | asm.js dropped in 3.0 | +| `yoga-layout-prebuilt` 1.10.0 | asm.js (emscripten), CommonJS | 365 kB / 80 kB | Runs as plain JS. Chrome 38/47 do not compile asm.js ahead of time. | Unmaintained since 2022. Yoga 1.x semantics. Larger than all of renderer v2 (165 kB / 52 kB). | +| `taffy-layout` 3.0.0 | Rust → wasm + JS glue | 29 kB / 7 kB JS + **598 kB / 213 kB wasm** | **No** (wasm) | | +| `stretch-layout` 0.3.2 | Rust → wasm | about 182 kB unpacked | **No** (wasm) | Unmaintained since 2022 | +| `css-layout` 1.1.1 | pure ES5 JS (Facebook, 2015) | 9.9 kB / 3.2 kB | Yes | No `gap`. Defaults differ (column direction, stretch alignment), so results would differ from Solid's. Unmaintained. | + +- **Interop cost per node (estimated, not measured).** + - A wasm engine mirrors the `ElementNode` tree in its own nodes (create, + insert, remove, free). + - Each layout pass crosses the JS↔wasm boundary about 15-25 times per + node: one call per style prop (Solid's flex reads about 6-12), 4 reads + back (x, y, w, h), and for text a measure callback from wasm back into + JS. + - At embind-call costs that is roughly microseconds per node on desktop, + against Solid's 0.07 µs per child on plain objects and 0.4-0.6 µs per + child on the real stack. +- **Every option also changes layout results**, which is app-facing: Solid's + `flexBoundary` and the content-sizing rules are not CSS. + +**Verdict: reject**, for size (the asm.js build), browser floor (wasm) and +semantics (all of them). + +--- + +## 3. Recommendation + +### 3.1 What to implement in 1.7 + +1. **Renderer, commit 1: `TextNode.measure(): boolean`.** + - It lays the text out now when its layout is stale, into the shared + `LayoutCache`. + - It sizes the node with `applySize` and leaves `DIRTY_LAYOUT` for the + visit to place the block. + - It queues `loaded` for real listeners only (apps, Marquee). + - It returns false while the font's description is missing. + - It needs no `ScenePass` change. + - It also updates `publicApi.test.ts`, `docs/upgrade-1.x-to-2.0.md`, + and the text unit tests: measure then walk reuses the layout; no + description returns false; `loaded` still reaches listeners. +2. **Renderer, commit 2: text-keyed `LayoutCache`.** It replaces the + per-lookup `layoutKey` string with a per-font `Map` keyed by text plus a + field compare, under the same size and LRU contract and its tests. +3. **Renderer, commit 3 (optional, after measuring): typed-array advance and + kerning tables** for `mapTextLayout`'s width function, built lazily per + font. They must stay bit-identical; the pinned 1.10 tests and the + 17,100-case check guard that. +4. **Solid: measure in the post-mutation pass, before flex.** + - **No persistent `loaded` listener.** + - A one-shot fallback while the description is missing. + - Writes to layout-affecting text props queue the flex parent: `text`, + `fontFamily`/`fontWeight`, `fontSize`, `lineHeight`, `letterSpacing`, + `maxWidth`/`width`, `maxHeight`/`height`, `maxLines`, `wordBreak` and + `overflowSuffix`. +5. **Solid: a depth-ordered layout queue.** + - Children run before parents. + - Propagate up only when a container's size changed. + - Skip queueing when the measured size is unchanged. +6. **Solid: the `flexItem={false}` fix** in `flex.ts` and `flexLayout.ts`, or + in the one implementation the flex rewrite keeps. +7. **Before fonts: hold**, as today. + +### 3.2 Expected effect + +| Metric (per text change in a flex container) | Today (arm B) | 1.7, measured with the prototype | 1.7 with items 5 and 6 | +| -------------------------------------------- | ------------------------------------------ | -------------------------------------------- | ------------------------------------ | +| Walks per frame | 2 (3 if flex resizes a text) | **1** | 1 | +| `loaded` events (no app listener) | 1 per relaid text | **0** | 0 | +| Flex passes | 1 per relaid text, plus ancestors (S1: 12) | 1 per queued container, plus re-runs (S1: 5) | **1 per affected container** (S1: 4) | +| Layouts in the walk | 1 per relaid text | **0**: done in `measure()`, reused | 0 | +| Cache lookup per relayout | 0.36-0.71 µs and about 1 kB of garbage | same | **0.02 µs and 0 B** (commit 2) | +| Flex containers under culled ancestors | unlaid until visited | laid out at mount or change | same | + +This meets the brief's starting target: "one walk per frame and one flex +pass per affected container". + +### 3.3 Renderer changes and boundaries + +- All three commits are inside "the surface Solid touches" (`TextNode.ts` + accessors) and "text measurement" (`TextNodes`' measure and `loaded` + queue; `LayoutCache` and `layoutKey`; read access to the font + description). +- None touches `ScenePass`, `NodeStore`'s layout, `TextEmitter`, the atlas, + shaders or textures. +- `renderer-proposals.md` items: + - (a) Layout inside the scene pass (§2.8), rejected for 1.7. + - (b) If lazy glyph runs (§2.3) turn out to need anything outside + `TextLayout.ts` or `TextNodes.ts`, it goes there too. + - (c) If building the tables in `parseSdfFont` is preferred over the lazy + build, the `sdfFont.ts` change needs the user's decision, because it is + beyond read access. + +### 3.4 What the DOM renderer must mirror + +- `DOMText.measure(): boolean`, synchronous. + - It calls `updateDOMTextSize(this, false)` (a `getBoundingClientRect` + measurement) when `document.fonts` reports the font loaded, and returns + true. + - Otherwise it returns false and keeps today's async path, which emits + `loaded` for the one-shot fallback. +- Add `measure?(): boolean` to `IRendererTextNode` in `domRendererTypes.ts`. +- **Under jsdom, sizes are 0, as today.** The text-flex results must be + tested on the real renderer: Vitest browser mode with WebGL + (`vitest.webgl.config.ts`, already set up in this worktree by another + agent). + +### 3.5 Behaviour changes that need the user's approval at Checkpoint 1 + +1. **Eager layout of flex text under culled ancestors.** + - Arm B leaves flex containers unlaid until they are visited (S2: + tiles 9-19; S3). + - With `measure()` they are laid out at mount or change. + - Visible results are identical: in S1 the final positions match; in S3 + the square ends at x = 425.44 in both arms. + - Results for never-visited containers differ, and a container now has + its size before it is shown. This removes the forever case of §1.3. + - Cost: + - about 2 µs desktop per extra title layout at mount (S2: 22 extra + layouts); + - more `LayoutCache` pressure; + - text for hidden `KeepAlive` pages is laid out while hidden. + - The alternative, keeping laziness, would need a visibility read from + the renderer and keeps the second walk on scroll. +2. **The `flexItem={false}` fix** unblocks containers that are blocked + today. +3. **Flex results arrive one step earlier.** They are computed in the + microtask before the frame instead of between walks. Positions within + the frame are the same, and `onLayout` runs before the frame, as it + already does for layouts without text. + +### 3.6 Risks + +- **Parity with 1.10 line breaking.** + - `measure()` calls the same `layoutText` with the same `TextState` + props, so lines are identical by construction. The pinned text-layout + tests do not change with commit 1. + - Commit 2 changes only how a layout is found. Commit 3 changes the width + function: it must stay bit-identical, and the pinned tests plus the + 17,100-case check guard it. +- **Missed invalidations.** If a layout-affecting write bypasses Solid's + setters, the walk relays the text and Solid's flex is not re-run. Examples: + - a raw `el.lng.fontSize = …` write; + - a renderer animation of `fontSize`; + - a font reloaded under the same name. + + Today the `loaded` listener catches these. Mitigation: route every + layout-affecting text prop through `ElementNode` setters (they already + are), document raw `lng` writes as layout-blind (already true for + non-text props), and keep a **dev-only** listener that warns when a + layout made in the walk changes the size of a measured text. It stays off + the production path, in line with the brief's preference for dev-only + shims. + +- **Flex writing a text's `width`** (`flexGrow`/`minWidth` on a text child) + sets `maxWidth`, which makes the text stale; measuring and flexing again + can loop. It is bounded by `runPostMutation`'s queue loop and + `_containsFlexGrow`. Test it explicitly. +- **Cache pressure from eager measuring**, against the default of 250. + Measure the hit rate in the VirtualRow and browse scenarios before + raising it. The memory cost is about 1.5 kB per title and about 12.6 kB + per description. +- **Re-entrancy.** + - A `measure()` inside a `loaded` listener or a `reprocessUpdates` + callback (between walks) goes through `applySize`. That counts as a + write and costs a re-walk, which is correct. + - Inside a walk it would also count; nothing calls it there. +- **`loaded` semantics for apps** are kept: `measure()` queues `loaded` for + listeners, delivered between the walks of the next frame. Marquee's + `onEvent.loaded` keeps working. +- **The DOM renderer** is synchronous `getBoundingClientRect` per measured + text. That forces a browser reflow per text, which is acceptable for the + DOM mode and the tests, but slower than today's batched `setTimeout` on + a DOM-rendered app. + +### 3.7 Tests to add (Phase 1 and the implementation) + +All on the real renderer (Vitest browser mode with WebGL), asserting +behaviour rather than internals: + +- final positions of the S1 and S2 shapes after fonts load, matching arm B + for the visible content; +- walks per frame equal to 1 for a text change in a flex container + (`renderer.updateIterations`); +- `loaded` still reaching an `onEvent` listener after a text change; +- the `flexItem={false}` text case; +- a font whose description arrives after mount (the one-shot fallback); +- a flex write to a text's `width`. + +--- + +## Appendix: method and reproduction + +The scratch prototypes live in this session's scratchpad. They are **not +committed**, and nothing under `src/` in any repository was changed. + +- **`textflex/renderer-proto`.** `git archive HEAD` of `renderer-v2-solid`, + then `pnpm install` and `pnpm build`. The prototype adds `TextNodes.measure` + and `TextNode.measure` plus three counters (+62 lines). +- **`textflex/solid-proto`.** `git archive HEAD` of `solid-1.7`, with + `node_modules` symlinked. The prototype is behind + `Config.syncTextMeasure` (+46 lines in `elementNode.ts`). + - `vitest.trace.config.ts` aliases `@solidtv/renderer` to the scratch + renderer build. + - `trace/textflex.test.tsx` holds scenarios S1-S3 and S5. + - Run: + `TRACE_MODE=baseline|measure npx vitest run --config vitest.trace.config.ts` +- **`textflex/bench`.** + - `text-micro.mjs` (`node --expose-gc text-micro.mjs [--alloc]`): layout, + cache keys, width paths, unwrapped parity. + - `fastmeasure-parity.mjs`: the typed-array measure through + `mapTextLayout`, 17,100 cases. + - `maplayout-micro.mjs`: line breaking against the full layout. + - `flex-micro.mjs`: Solid's `flex.ts` and `flexLayout.ts` bundled with a + stub `utils`, on mock nodes. + - `estimate.mjs`: the Alternative 7 estimate error. + - `alloc-probe.mjs`: allocation sanity checks. +- **Allocation method.** V8 sampling heap profiler at a 1-byte interval, + collected objects included, the inspector session's frames excluded (as + in the renderer's `test/allocations.ts`), after a 2,000-call warm-up. The + harness's own boxing (16 B) is subtracted. diff --git a/docs/superpowers/plans/2026-10-03-solid-1.7-phase-2.md b/docs/superpowers/plans/2026-10-03-solid-1.7-phase-2.md new file mode 100644 index 00000000..7803b24b --- /dev/null +++ b/docs/superpowers/plans/2026-10-03-solid-1.7-phase-2.md @@ -0,0 +1,209 @@ +# Solid 1.7 Phase 2 Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Rewrite the hot paths of `@solidtv/solid` for less CPU and fewer allocations per key press, per state change and per text layout on renderer v2, keeping every Phase 1 contract test green. + +**Architecture:** The approved design is `docs/superpowers/specs/2026-10-03-solid-1.7-design.md` (sections 3, 4, 4a, 5). Work is split into independent workstreams, each in its own git worktree and branch off `1.7`, merged back by the coordinator. Renderer changes live in their own renderer worktree off `v2-solid-integration`. Each task is test-first: write or un-skip the failing test, make it pass, measure, commit. + +**Tech Stack:** TypeScript, SolidJS universal renderer, `@solidtv/renderer` v2 (WebGL, SDF text), Vitest (jsdom and browser mode), the bench harness (`npm run bench`, Playwright Chromium). + +**How this plan is written.** It spans eight subsystems. Each task pins the files, interfaces, the tests that define done (most are already written in Phase 1: the `it.skip('BUG: …')` tests to turn on, and the contract tests that must stay green), the acceptance numbers and the measurement. It does not pre-write the implementation: the implementer reads the code being changed, and the contract tests decide correctness. + +## Global Constraints + +- Approved at Checkpoint 1 (2026-10-03): design sections 3 and 4 (renderer R1-R4, R5 only with a measured win), 5.1 batch the focus phase, 5.2 eager text layout under culled ancestors, 5.3 keep `flexLayout.ts` only, 5.4 keep "a `$focus` size change does not reflow its flex parent", 5.5 option (a): `useHold` is the hold contract, 5.6 Solid absorbs `stage.shManager`, `renderEngine` and `fontEngines` with a warning that they were removed in renderer 2.0, 5.8 fix B1-B21, demo app build sets terser `reduce_funcs: false`. +- Targets (design section 6) are guidance, not gates: "achieve the best possible with reasonable effort". +- No other app-facing break. Do not change focus or handler semantics or ordering beyond 5.1. Do not change flex layout results beyond the approved bug fixes B5-B12 and 5.3. +- Renderer changes: only the surface Solid touches and text measurement (brief, Hard boundaries). Each renderer commit: one focused change, `pnpm test` green (allocation-budget and text-layout tests included), `npx tsc --noEmit -p tsconfig.dist.json` and `-p tsconfig.vitest.json` clean, `src/publicApi.test.ts` and `docs/upgrade-1.x-to-2.0.md` updated, renderer `CLAUDE.md` invariants respected (setters store and mark only; no per-node handle fields; no per-frame allocation). +- The DOM renderer (`src/core/dom-renderer`) mirrors every integration-API change. +- Every commit in `solid-1.7` keeps `npx vitest run`, `pnpm tsc` and `pnpm lint` (0 errors) green; `pnpm test:webgl` green for layout and text work. Commit messages end with `Co-Authored-By: Claude Opus 5.5 `. +- Hot-path code style (Solid, same as the renderer's): no allocation per press, per state change or per layout in the steady state (no closures, arrays, objects or template strings); `for` loops; read a property once into a local; explicit comparisons; no `delete`. +- Chrome 47 floor for shipped code: no `Proxy`, `Reflect`, `Object.values`/`entries`/`fromEntries`, `padStart`, `Promise.finally`, `flat`, `globalThis`. Class fields compile with `useDefineForClassFields` off; prefer constructor assignment. +- Measurement during Phase 2 is guidance: one run at 6x (`--runs 1`). Allocation and count modes are deterministic and are the primary evidence; time is rough. The final n ≥ 3 series is the coordinator's, at Checkpoint 2. +- Log every measured change in `docs/perf/log.md`: what changed, scenario(s), before (arm B) and after (arm C), kept or dropped. + +## Worktrees and merge order + +| Stream | Worktree / branch | Owns | +| ------ | -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| R | `../renderer-v2-text` / `v2-solid-text` (off `v2-solid-integration`) | renderer R1-R4 (`src/core/text/*`, `TextNode.ts`, `Node.ts`, `NodeStore` tree ops, public API, docs) | +| F | `../solid-1.7-focus` / `1.7-focus` | `src/core/focusManager.ts`, `src/core/states.ts`, `src/core/activeElement.ts` | +| S | `../solid-1.7-styles` / `1.7-styles` | `_stateChanged`, `set states`, `set style`/`theme`, shader accessors and `effects` in `elementNode.ts`; a new `src/core/stylePlan.ts` | +| L | `../solid-1.7-layout` / `1.7-layout` | `src/core/flexLayout.ts`, `src/core/flex.ts` (deleted), the layout queue and post-mutation scheduler in `elementNode.ts` | +| N | `../solid-1.7-nodes` / `1.7-nodes` | prop accessors, `insertChild`/`removeChild`, `fontWeight`/`fontFamily`, forwarded-name lists in `elementNode.ts`; `src/solidOpts.ts`; `src/core/nodeTypes.ts` | +| P | `../solid-1.7-prims` / `1.7-prims` | `src/primitives/**` | +| M | `../solid-1.7-misc` / `1.7-misc` | `package.json` exports, `src/core/lightningInit.ts`, `src/render.ts`, docs | +| B | `solid-1.7` itself (bench only) | `bench/**` page-creation scenarios, demo per-route timing | +| T | `../solid-1.7-text` / `1.7-text` (after R and L merge) | text measurement in Solid and the DOM renderer | +| D | `../solid-demo-app-1.7` (Phase 3, after the rest) | the demo app port | + +Merge order into `1.7`: B, M, F, S, P, N, L, then R into `v2-solid-integration` and T, then D. The coordinator merges, resolves conflicts in `elementNode.ts` (streams own disjoint functions), and runs the full checks after each merge. + +--- + +### Task B1: Page-creation baseline scenarios + +**Files:** Create `bench/src/scenarios/nav/page.tsx`; modify `bench/src/scenarios/nav/index.ts`; modify `bench/demo/check-routes.mjs` (or a new `bench/demo/route-times.mjs`). + +**Interfaces:** Consumes the `Scenario` contract (`bench/src/scenario.ts`, with `opKind`). Produces scenario ids `page-mount` and `page-swap`, and `node bench/demo/route-times.mjs --arms A,B,C`. + +- [ ] `page-mount`: a Browse-like page (a Column of 7 Rows × 20 Posters from `poster.tsx`'s tile, titles, `$focus`, border; about 600 nodes). Even ops unmount, odd ops mount; `opKind(i)` returns `'destroy'`/`'create'`. Warmup 10, measured 20. +- [ ] `page-swap`: one op replaces the page with a second page of the same shape and different strings (route change shape). Warmup 10, measured 20. +- [ ] Verify both render on arms A and C (screenshot), no console errors, cycle returns to start. +- [ ] Route timing: for every route the demo's route checker visits, time navigation (hash change) to the renderer's `idle` with nothing pending, 3 visits per route per arm, report median per route and the sum. +- [ ] Run once at 6x on A, B, C (`npm run bench -- --scenarios page-mount,page-swap --runs 1 --modes time,alloc`) and the route timing; add the numbers to `docs/perf/results/2026-10-03/summary.md` (regenerate) and `docs/perf/log.md`. +- [ ] Commit. + +### Task M1: Package exports, renderer-break absorption, docs + +**Files:** `package.json`, `src/core/lightningInit.ts` or `src/render.ts`, `tests/publicApi.test.ts` (un-skip), a new `tests/compat-renderer2.test.ts`, `docs/` (a build note). + +- [ ] Un-skip `publicApi.test.ts`'s two BUG tests (`./focusManager` exported; `./shaders` target exists). Run: fail. +- [ ] B21: add `"./focusManager"` to `exports` (source `./src/core/focusManager.ts`, types and default under `dist/src/core/`); point `./shaders` at `./src/core/shaders.ts` / `dist/src/core/shaders.*`. Tests pass. `pnpm build` then check the `dist` files exist. +- [ ] 5.6: in `createRenderer` (or `startLightningRenderer`), before constructing the renderer, drop `renderEngine` and `fontEngines` from the options with a one-time `console.warn('[solid] Config.rendererOptions. was removed in @solidtv/renderer 2.0 and is ignored')`; after constructing it, define `shManager` on `renderer.stage` (which is the renderer) as a getter returning the renderer, warning once `'[solid] renderer.stage.shManager was removed in @solidtv/renderer 2.0: use renderer.registerShaderType'`. Not on the DOM renderer path if it has its own. Tests: the warnings fire once; `renderer.stage.shManager.registerShaderType(name, type)` registers the type; options passed to the renderer contain neither key. +- [ ] Docs: `docs/` page on building for TVs gets the terser `reduce_funcs: false` note with the measured numbers (design section 1). +- [ ] Record B21 and 5.6 in `MIGRATION-1.7.md`. Commit. + +### Task F1: Key dispatch without per-event allocation + +**Files:** `src/core/focusManager.ts`; tests `tests/contract-keys.test.tsx` (must stay green), new `tests/focusManagerAlloc.test.ts` if useful. + +**Interfaces:** No public change. + +- [ ] Un-skip in `contract-keys.test.tsx`: B3 (`a key release right after a handled press still reaches onRelease`) and B4 (`a null value removes the keys mapped to that name`). Run: both fail. +- [ ] Fix B3: the per-element throttle applies to keydown only (as `Config.throttleInput` already does). Fix B4: `{ Name: null }` removes every key mapped to `Name`, defaults included. +- [ ] Interned handler names: when the key map is set (and once per unmapped `e.key`, cached), build `{ on, onCapture, onRelease, onCaptureRelease }` strings; dispatch reads them, never builds strings per event. +- [ ] No per-event allocation in dispatch: one reused listener (no closure per event), no `keyIdentities` array (locals), a reused result record, `_pendingHistoryKey` built only when `Config.focusHistoryDebug` is on. +- [ ] Skip walks that cannot find a handler: Solid's `setProperty` in `src/solidOpts.ts` sets module flags the first time a prop name starting with `onCapture` or ending in `Release` is assigned (a cheap `charCodeAt`/`endsWith` check at prop-set time). With no capture handler anywhere, skip the capture walk; with no release handler, skip the keyup bubble walk. Order and semantics unchanged. +- [ ] All of `contract-keys` and `contract-focus` green. Measure `rows-lr-noshift`, `rows-lr-auto`, `virtual-row` (time, alloc, 1 run, arms B,C). Expected: framework bytes per press fall by the dispatch's share (about 0.4 KiB on keydown plus keyup). Log. Commit (one commit per bullet group is fine). + +### Task F2: Focus change and `States` + +**Files:** `src/core/focusManager.ts` (`setActiveElementCore`, `updateFocusPath`), `src/core/states.ts`, `src/core/elementNode.ts` (only `runPostMutation`'s focus phase call site, coordinated with L); tests `contract-focus`, `contract-states`. + +- [ ] Un-skip `contract-states` B2 (`toggle("focus") while "$focus" is on`). Fails. Fix: `toggle`/`remove` accept the bare name for a `$`-prefixed entry, as `has` does. +- [ ] `States`: `static get [Symbol.species]() { return Array; }`; `remove` shifts in place (no `splice`); `has` without allocation (already). Keep `States extends Array` and every method's behaviour (pinned). Record 2.5 in `MIGRATION-1.7.md` (`Array` methods return plain arrays). +- [ ] `updateFocusPath`: generation-stamped diff (a module counter; each ancestor of the new leaf gets `_focusGen = gen`; old-path nodes whose stamp differs lost focus) in O(depth); two reused path buffers; `focusPath()` publishes a copy (the signal value must be a fresh array per change, pinned by tests that hold it). Callback order identical (pinned in `contract-focus.test.tsx`). +- [ ] 5.1: run the focus phase (callbacks, `setFocusPath`, `Config.setActiveElement`) inside one `batch`. Add a test: two signals written in `onFocus` and `onFocusChanged` drive one effect, which runs once per focus change (fails today: twice), and runs after the last callback. Update the contract test that pinned "callbacks run before activeElement / focusPath publish" only if its observable order changes (it should not). +- [ ] Measure `rows-lr-noshift`, `thumbnail-focus`, `portal-focus-text`, `navdrawer-toggle` (time, alloc). Log. Commit. + +### Task S1: Compiled style plans and diffed state application + +**Files:** Create `src/core/stylePlan.ts`; modify `src/core/elementNode.ts` (`_stateChanged`, `set states`, `set style`, `set theme`, `shaderAccessor`, `effects`, `parseAndAssignShaderProps`); tests `contract-states`, `contract-styles`, new `tests/stylePlan.test.ts`. + +**Interfaces:** Produces `compileStyle(style: Styles): StylePlan` (cached in a `WeakMap`; returns `null`-free plan with, per `$state` key, a flat `keys: string[]` and `values: unknown[]`, border/shadow/radius pre-expanded to shader keys) and a per-node `_applied: Record | undefined` (allocated once on the first state application). + +- [ ] Un-skip / add: B18 (`$focus` undo resets `border-gap` and `border-align` that the base style does not name: after focus then blur, the node's shader props equal a never-focused node's). Fails today. +- [ ] `set states` with an unchanged value is a no-op (no `_stateChanged`). +- [ ] `_stateChanged`: resolve the target value per key from the compiled plan (active states in `stateOrder` precedence; undo falls back to `theme[key]`, then `style[key]`, then `undefined`, exactly the pinned table), write only keys whose value `!==` the last applied one; apply `transition` before the other keys (pinned). Getter styles and inline literals: compile per apply without caching (results identical, pinned). +- [ ] Shader props: `border`/`shadow` objects from a static style parse once (cached by object identity); facade writes only for changed sub-props; B18 fix. +- [ ] `forwardStates`: same semantics (overwrite), no `slice` per change. +- [ ] Gradients (`linearGradient`/`radialGradient` raw accessors): reuse the node's shader when the type is unchanged and update its props instead of creating a shader per set. +- [ ] `onAnimation.stopped`: keep the `setTimeout` (pinned) but only when a `stopped` listener exists (already) — no change unless measured. +- [ ] All contract tests green. Measure `thumbnail-focus`, `navdrawer-toggle`, `rows-lr-noshift`, `portal-focus-text` (time, alloc). Target: framework bytes per press → 0 for a static-style `$focus`. Log. Commit. + +### Task L1: One flex engine, allocation-free, write-only-changed, bug fixes + +**Files:** `src/core/flexLayout.ts`; delete `src/core/flex.ts` and the `VITE_USE_NEW_FLEX` switch in `elementNode.ts`; tests `contract-flex.test.tsx` (its `flex.ts` half becomes the record of what changed), `tests/flex*.spec.ts`/`.test.tsx`, `tests/webgl/flex-text.test.tsx`. + +- [ ] Un-skip the flex BUG tests: B5 (`flexItem={false}` unsized text no longer blocks), B6 (center with padding), B7 (cross-axis center/flexEnd with padding), B8 (`flexGrow` does not ratchet), B9 (wrap without height sets `y`), B10 (`wrap-reverse`). Fail. +- [ ] Fix each in `flexLayout.ts`. Delete `flex.ts`; convert `contract-flex.test.tsx`'s table to run once on the single engine, keeping the `flex.ts`-only expectations as comments listing what changed for default-build apps (5.3); update `tests/flex.spec.ts` etc. that import `flex.ts` to the single engine. +- [ ] No allocation per pass: module-level scratch typed arrays grown on demand (`Float32Array` → `Float64Array` if results must match the current float rounding: check against the pinned numbers), no closure, no index array (children walked by index, `flexOrder` sorted into a reused buffer only when some child has `flexOrder`). +- [ ] Write only what changed (`x`, `y`, `width`, `height` compared before writing). Remove the production `console.warn`. +- [ ] B11, B12 in `elementNode.ts`'s text `render` path: `contain` subtracts the margins from the `ElementNode`, and `maxLines={1}` resolves a multiplier `lineHeight` (≤ 3) as `lineHeight * fontSize`. +- [ ] `pnpm test:webgl` green (positions unchanged except the approved fixes; update pins only for B5-B12 cases, each commented). +- [ ] Measure `text-details-panel`, `text-flex-mount-*`, `virtual-row`, `virtual-grid` (alloc, count). Target: flex-pass allocations 0. Log. Commit per fix group. + +### Task L2: Layout queue and post-mutation scheduling + +**Files:** `src/core/elementNode.ts` (`schedulePostMutation`, `runPostMutation`, `addToLayoutQueue`, `updateLayout`, `_layoutOnLoad`); tests: new `tests/layoutQueue.test.tsx`, contract tests. + +**Interfaces:** Produces `queueLayout(node: ElementNode): void` (replaces `addToLayoutQueue`; T1 calls it for text changes) and the guarantee: within one `runPostMutation`, containers are laid out deepest first, each at most once unless a child's size changed after its pass. + +- [ ] Test: a press that changes texts in a 3-level nested flex (DOM renderer with mocked measurements, as `contract-text` does) runs exactly one flex pass per affected container; fails today. +- [ ] `schedulePostMutation` registers the microtask only (no `reprocessUpdates` registration) except when T1's one-shot text fallback asks for it (expose `schedulePostMutationInFrame()` for T1). +- [ ] Depth-ordered queue without per-run allocation (no `[...layoutQueue]` copy): bucket by depth computed once per queued node (walk up), process deepest first; a container whose size changed queues its parent. +- [ ] `_layoutOnLoad`'s `loaded` handler calls `queueLayout(parent)` instead of `parent.updateLayout()` synchronously, and skips when the size is unchanged (until T1 replaces it). +- [ ] All tests green, `test:webgl` green. Measure `text-details-panel`, `text-flex-mount-*` (count: flex passes 7 → ≤ 5 before T1). Log. Commit. + +### Task N1: Monomorphic prop accessors and renderer-handle hygiene + +**Files:** `src/core/elementNode.ts` (the accessor loops at the bottom, `_sendToLightningAnimatable`, forwarded-name lists, `fontWeight`/`fontFamily`), `src/solidOpts.ts`; tests: contract tests, new `tests/handleFields.test.ts`. + +- [ ] B20 test (WebGL, `tests/webgl/`): writing `fontSize`, `lineHeight`, `maxWidth`, `text`, `contain` and `fontWeight` on a rendered `` adds no own property to its renderer handle (`Object.keys(el.lng)` unchanged); writing `absX`/`absY`/`destroyed` does not throw. Fails today. +- [ ] Route text-only props written to a non-text node to the `ElementNode` (not the handle); drop `absX`, `absY`, `destroyed` from the forwarded setter list (getters stay). +- [ ] B17: `fontWeight` and `fontFamily` resolve the family the same in either JSX order (un-skip the contract-text BUG test). +- [ ] 3.6.6: one accessor per forwarded prop with a constant property name (`get x() { return this.lng.x }`), generated without a shared `this.lng[key]` body — either written out or created per key with `new Function` **only if** the app CSP allows it (prefer written out; measure bundle size). `_sendToLightningAnimatable` split so the common no-transition write is a direct store. +- [ ] Measure first in isolation: build C with only this change; `rows-lr-auto`, `virtual-row`, `portal-focus-text`, `text-virtual-row` (time 1 run, alloc). Keep it only if time or allocations drop beyond the noise; record bundle-size delta (`gzip -9` of `bench/dist/C/assets/framework.js`). Log. Commit. + +### Task N2: Child list and draw order + +**Files:** `src/core/elementNode.ts` (`insertChild`, `removeChild`), `src/solidOpts.ts` (`cleanChildren`, `getNextSibling`), DOM renderer `insertBefore`; depends on R4. + +- [ ] B19 test (WebGL): `` inserted before an anchor and a `` reorder leave the renderer's sibling order equal to `children` (read through the renderer's public children list). Fails today. +- [ ] `insertChild(node, before)` calls the renderer's `insertBefore` (R4) when both are rendered; `removeChild` and `cleanChildren` scan from the end and are O(n); `removeChild` marks the node `_detached` (keeping `parent`, as 1.6; N3) so a re-insert does not pay a full miss. +- [ ] Commit after R4 is merged. + +### Task R1: Renderer `TextNode.measure()` (in `../renderer-v2-text`) + +**Files:** `src/core/text/TextNodes.ts`, `src/core/nodes/TextNode.ts`, `src/core/text/*.test.ts`, `src/publicApi.test.ts`, `docs/upgrade-1.x-to-2.0.md`. + +**Interfaces:** Produces `TextNode.measure(): boolean` — lays the text out now when its layout is stale (into the shared `LayoutCache`), sizes the node through `applySize` (raising `DIRTY_LOCAL | DIRTY_SHADER`), leaves `DIRTY_LAYOUT` for the visit to place the block, queues `loaded` only for a node with a listener, returns `false` while the font's description is missing, `true` otherwise. After `measure()` the next walk performs no layout for that node. + +- [ ] Tests (vitest, the renderer's fakes): measure then walk reuses the layout (0 layouts in the walk); no description → `false` and no size change; `loaded` still reaches a listener; `w`/`h` read the measured size right after `measure()`; allocation-budget tests unchanged. +- [ ] Implement (prototype in `docs/perf/text-flex-alternatives.md` section 2.2). One commit; publicApi and upgrade guide updated. + +### Task R2: Text-keyed `LayoutCache` + +- [ ] Replace the per-lookup `layoutKey` string with a per-font-record `Map` keyed by the text string and a chain of entries compared field by field on the other layout props; same capacity (`textLayoutCacheSize`), LRU by use stamp, trimmed at idle maintenance; its tests updated. Micro-benchmark before/after in the commit message (expected 0.36-0.71 µs and ~1 kB → 0.02 µs and 0 B per hit). One commit. + +### Task R3: Typed-array advance and kerning tables in the line breaker + +- [ ] Build per-`SdfFont` advance (`Float64Array` by code unit) and kerning tables lazily from the description (read access); `mapTextLayout`'s width function uses them. Pinned text-layout tests unchanged; the 17,100-case parity check (`docs/perf/text-flex-alternatives.md`, `fastmeasure-parity.mjs` in the scratchpad) bit-identical. Commit only with a measured gain. + +### Task R4: Public `insertBefore` + +- [ ] `Node.insertBefore(child: Node, before: Node | null): void` places `child` under this node before `before` (append when `null`; a same-parent move reorders), through `NodeStore`'s existing tree links (a public method next to `appendChild`; no new typed arrays). Tests: order of `children` after inserts and moves; draw order follows (scene pass emits in sibling order). One commit. + +### Task T1: Text measurement in Solid (after R1 and L2 are merged) + +**Files:** `src/core/elementNode.ts` (text `render`, `_layoutOnLoad`, text-prop setters), `src/core/dom-renderer/domRenderer.ts` and `domRendererTypes.ts` (`measure`), tests `tests/webgl/flex-text.test.tsx` (+ new cases), `tests/contract-text.test.tsx`. + +- [ ] Tests (WebGL): walks per drawn frame = 1 for a text change in a flex container (`renderer.updateIterations` or the scene pass counter); `loaded` still reaches an `onEvent` listener; a font loaded after mount (one-shot fallback); a flex write to a text's `width` terminates; final positions equal the pinned ones. +- [ ] `render()` calls `measure()` instead of registering `_layoutOnLoad`; `false` → one-shot `loaded` listener that re-queues the parent once (via `schedulePostMutationInFrame`). Writes to layout-affecting text props (`text`, `fontFamily`, `fontWeight`, `fontSize`, `lineHeight`, `letterSpacing`, `maxWidth`/`width`, `maxHeight`/`height`, `maxLines`, `wordBreak`, `overflowSuffix`) queue the flex parent; `updateLayout` measures due text children before the pass; unchanged measured size → no queue. Dev-only warning listener when a walk's layout changes a measured text's size. +- [ ] DOM renderer `measure()` synchronous (`getBoundingClientRect` when the font is loaded, else `false`). +- [ ] Measure `text-details-panel`, `text-flex-mount-*`, `text-virtual-row` (count, time, alloc). Targets: walks 1, flex passes 4 / 21, `loaded` heard 0. Log. Commit. + +### Task P1: Row, Column, Grid + +**Files:** `src/primitives/utils/handleNavigation.ts`, `src/primitives/utils/withScrolling.ts`, `src/primitives/Row.tsx`, `Column.tsx`, `Grid.tsx`; tests `contract-row-column`, `contract-grid`. + +- [ ] Turn the B1 `it.todo` into a test with a timeout guard (a `wrap` Row whose children all `skipFocus`: a press returns without hanging and focus stays); fails (hangs) today. Fix `findFirstFocusableChildIdx` (bounded loop; `-1` with no children, not `NaN`). +- [ ] No transition object per press: cache the merged forward/backward transitions per base `transition` object in a `WeakMap`, so `animateProp` gets the same settings object for the same direction (controller reuse). +- [ ] `withScrolling`: read each input once into locals; `$focus` instead of `style?.focus` (latent on v2); no `{}` from the `style` getter. +- [ ] Grid: handlers created once, not per vertical move. +- [ ] Contract tests green. Measure `rows-lr-auto`, `rows-ud-auto`, `rows-lr-always` (time, alloc). Log. Commit. + +### Task P2: Virtual, VirtualGrid, Lazy + +**Files:** `src/primitives/Virtual.tsx`, `VirtualGrid.tsx`, `Lazy.tsx`; tests `contract-virtual*`, `contract-lazy`. + +- [ ] Un-skip B13 (Virtual `scroll="none"`/`"center"` move the window), B14 (`$focus` scale seen by Virtual's scroll math: pin the new offsets), B15 (VirtualGrid: autofocus with `selected`, `selected` back to row 0, Down past the end), B16 (Lazy small buffer loses presses). Fail. Fix each. +- [ ] Split the spread so a `cursor`/`focusedIndex` change re-runs only the props that depend on it; reuse the `SliceState`; one flex pass per window shift. +- [ ] Contract tests green (update pinned offsets only for the approved B13/B14 changes, commented). Measure `virtual-row`, `virtual-grid`, `text-virtual-row` (time, alloc, count: flex passes ≤ 1). Log. Commit. + +### Task D1: Port the demo app (Phase 3, after the merges) + +**Files:** `../solid-demo-app-1.7`: `vite.config.js` (terser `reduce_funcs: false`), `src/pages/App.tsx` and `KeyHandling.tsx` (hold handlers to `useHold`, drop `KeyHoldMap`), anything else `MIGRATION-1.7.md` lists, nothing more. + +- [ ] Every route renders and navigates on arm C (`node bench/demo/check-routes.mjs`); text-heavy screens lay out as on arm B (positions compared for Text, TextPoster, Entity, Flex pages). +- [ ] Run `#/benchmark` and the full suite across A, B, C (the coordinator's Checkpoint 2 series). Commit in the demo worktree. + +--- + +## Self-review + +- Spec coverage: design 3.1 → F1; 3.2 → F2; 3.3 → S1; 3.4 → L1; 3.5 and the queue → L2; 3.6.1-3.6.2, 3.6.6 → N1; 3.6.3-3.6.4 → N2 + R4; 3.6.5 (class fields) → F2 (`States`) and N1 (`TextNode` in `nodeTypes.ts`); 3.7 → P1, P2; section 4 R1-R4 → R1-R4 (R5 only if measured); 4a → R1-R3, L1, L2, T1; 5.1 → F2; 5.2 → T1; 5.3 → L1; 5.4 → kept (no task); 5.5 → D1 (and the contract stays as pinned); 5.6 → M1; 5.8 B1-B21 → P1 (B1), F2 (B2), F1 (B3, B4), L1 (B5-B12), P2 (B13-B16), N1 (B17, B20), S1 (B18), N2 (B19), M1 (B21); demo terser → D1; page creation baseline → B1. +- Placeholders: none; each task names its tests and acceptance. +- Interfaces: `queueLayout`, `schedulePostMutationInFrame` (L2 → T1), `TextNode.measure()` (R1 → T1), `Node.insertBefore` (R4 → N2), `compileStyle` (S1). diff --git a/docs/superpowers/specs/2026-10-03-solid-1.7-design.md b/docs/superpowers/specs/2026-10-03-solid-1.7-design.md new file mode 100644 index 00000000..07ddd131 --- /dev/null +++ b/docs/superpowers/specs/2026-10-03-solid-1.7-design.md @@ -0,0 +1,655 @@ +# SolidTV 1.7 design: CPU per key press on renderer v2 + +Date: 2026-10-03 +Status: **draft for Checkpoint 1**, for the user's review. Nothing here is +implemented yet. Phase 2 starts only after approval. +Brief: [2026-10-03-solid-1.7-rewrite-brief.md](2026-10-03-solid-1.7-rewrite-brief.md) + +This spec proposes how to rewrite the hot paths of `@solidtv/solid` for 1.7. +It covers the architecture, the renderer integration and text-measurement +changes, the text and flex alternatives review, every app-facing change that +needs approval, and numeric targets per scenario. + +The evidence is in `docs/perf/`: + +- [README.md](../../perf/README.md): the benchmark harness and its method. +- [results/](../../perf/results/): the arm A and arm B numbers, raw and + summarised. +- [survey-verification.md](../../perf/survey-verification.md): every lead from + the brief's survey checked against the code, with a full trace of one key + press. +- [text-flex-alternatives.md](../../perf/text-flex-alternatives.md): the text + and flex alternatives review, with prototypes. + +## 1. Summary + +- **The lockstep port (arm B) costs more per key press than what ships today + (arm A).** Renderer v2 makes frames cheaper (the demo's render pass: 89 → + 33 ms per run), but keydown-to-frame CPU on navigation presses is 1.25x to + 2.1x arm A's (6x throttle), and the demo app's `#/benchmark` press mean goes + from 0.64 to 0.93 ms. Solid's code is the same in both arms, so the + difference is how Solid drives renderer v2 (section 2.5). +- **Solid's own work per key press is small but allocates every time:** about + 1.9 KiB of framework allocations and 0.8 KiB of reactivity per Row press, + 15 KiB per NavDrawer toggle, 12 KiB per details-panel press. The target is + zero framework allocations in the steady state. +- **Text in flex costs two walks per frame** on every text scenario, and flex + runs once per relaid text (7 passes per details-panel press, 42 per 20-tile + mount). The proposed synchronous text measurement (section 4a) brings this + to one walk and one pass per affected container. +- **The demo app's production build makes renderer v2 allocate per visited + node per frame (confirmed).** Terser (the demo's settings: compress on) + inlines the renderer's single-use world-transform helper into the walk as + an IIFE (`!function(s, id, parent){…}(…)` inside `ScenePass.visit`). With + `compress: { reduce_funcs: false }` the IIFE is gone and the renderer's + allocations per press drop from 56.7 to 3.4 KiB (rows-ud-auto) and from + 67.7 to 8.6 KiB (virtual-grid). The fix is one line in an app's build + (proposed for the demo app in Phase 3, and for the docs), and a renderer + proposal so no bundler can do it (`renderer-proposals.md`, P3). +- **B's extra press cost is in the tail, not the typical op:** the median + press is about equal on A and B; the profiles put the difference in Solid's + reads of renderer v2 props through megamorphic accessors (top cost 2) and + in `animateProp` restarts. + +## 2. Baseline numbers (arms A and B) + +Method: [docs/perf/README.md](../../perf/README.md). Headless Chromium 141 +with the hardware GPU (ANGLE Metal, Apple M4 Pro), 5 µs clock, each scenario +built per arm with the demo app's modern-bundle settings and its flex engine +(`flexLayout.ts`). The generated summary, at 6x CPU throttle (the brief's TV +proxy): [results/2026-10-03/summary.md](../../perf/results/2026-10-03/summary.md); +the profile digest: [profiles.md](../../perf/results/2026-10-03/profiles.md). +The raw per-run JSON is regenerated by `npm run bench` and not committed. + +**Noise floor.** B and C are the same code today, so C/B is the in-session +noise: at 6x it spans 0.74-1.22 on per-op totals. CDP throttling is a duty +cycle (about 0.17 ms running, 0.85 ms suspended), so a sub-millisecond op +reads either unthrottled or one suspension longer; per-run means over 60-90 +ops still carry about ±0.05 ms. Effects under about 25% at 6x are not +results at n = 3; Phase 2 uses n ≥ 5 near the floor, and the pooled per-op +medians below for typical-op comparisons. + +### 2.1 Time per op at 6x (ms, median over 3 runs of the per-run mean) + +`total` = keydown dispatch to the end of the first frame that shows the +result (handler + microtask tail + that frame). `cpu` adds every later frame +until the renderer is idle (transitions). + +| Scenario | What one op is | A total | B total | B/A | C/B (noise) | A cpu | B cpu | B/A cpu | +| -------------------- | ----------------------------------------------- | ------- | ------- | -------- | ----------- | ----- | ----- | ------- | +| rows-lr-noshift | Right/Left in a Row, no scroll | 0.127 | 0.186 | **1.46** | 1.06 | 0.320 | 0.186 | 0.58 | +| rows-lr-auto | Right/Left, row scrolls (`auto`) | 0.162 | 0.203 | 1.25 | 0.94 | 0.499 | 0.338 | 0.68 | +| rows-lr-always | Right/Left, row scrolls (`always`) | 0.110 | 0.182 | **1.65** | 1.11 | 0.374 | 0.333 | 0.89 | +| rows-ud-auto | Down/Up across 10 Rows (`auto`) | 0.168 | 0.241 | 1.44 | 0.89 | 0.649 | 0.476 | 0.73 | +| rows-ud-always | Down/Up across 10 Rows (`always`) | 0.144 | 0.301 | **2.09** | 0.96 | 0.626 | 0.651 | 1.04 | +| thumbnail-focus | `$focus` scale + border + radius, transition | 0.247 | 0.399 | **1.61** | 1.01 | 0.679 | 0.669 | 0.99 | +| portal-focus-text | `onFocusChanged` → reactive text colours | 0.186 | 0.260 | 1.40 | 1.01 | 0.772 | 0.661 | 0.86 | +| navdrawer-toggle | `states` on 10 children, `forwardStates`, width | 0.602 | 0.757 | 1.26 | 0.97 | 1.372 | 1.226 | 0.89 | +| virtual-row | VirtualRow press, window shifts | 0.494 | 0.910 | **1.84** | 0.74 | 0.886 | 1.305 | 1.47 | +| virtual-grid | VirtualGrid Down/Up, 7 tiles in and out | 1.317 | 1.424 | 1.08 | 0.96 | 2.030 | 1.961 | 0.97 | +| poster-mount | mount or unmount 10 Poster tiles | 0.395 | 0.286 | 0.72 | 1.22 | 0.511 | 0.286 | 0.56 | +| poster-swap | replace 10 Poster tiles | 0.632 | 0.503 | 0.79 | 0.90 | 0.807 | 0.503 | 0.62 | +| text-details-panel | press changes 7 texts in nested flex | 0.293 | 0.228 | 0.78 | 1.20 | 0.407 | 0.228 | 0.56 | +| text-flex-mount-same | remount 20 flex text tiles, cached layouts | 1.115 | 1.041 | 0.93 | 1.04 | 1.235 | 1.041 | 0.84 | +| text-flex-mount-new | remount 20 flex text tiles, uncached | 1.289 | 1.231 | 0.96 | 1.09 | 1.461 | 1.231 | 0.84 | +| text-virtual-row | VirtualRow of text tiles, window shifts | 0.655 | 1.007 | **1.54** | 0.87 | 1.529 | 1.424 | 0.93 | + +Reading: on every navigation scenario B's keydown-to-frame time is above A's +by more than the noise floor; on creation and text-mount scenarios B is equal +or cheaper; over the whole press including transitions (`cpu`) B is cheaper +or equal, because v2's frames are cheaper. + +**The typical press versus the mean.** Pooling every op of the 3 runs and +taking the per-op median (which, for ops shorter than the throttler's 0.17 ms +slice, approximates full-speed CPU at the clock's 5 µs resolution), a Row +press is about the same on A and B: 50-75 µs total (rows-lr-noshift 55 vs 50, +rows-lr-auto 70 vs 75, rows-ud-auto 75 vs 80). So B's higher means come from +the tail of expensive ops, which is what drops frames on a TV: the profiles +below put it in the dispatch and navigation code reading renderer v2 props, +and in GC. An unthrottled (1x) series was also run and is **not usable** on +this Mac: an idle page's main thread runs on an efficiency core or at a low +clock, so every op read about 5x slower than at 6x (recorded in +`docs/perf/README.md`). + +### 2.2 Allocations per op (KiB, every allocation sampled, collected objects included) + +| Scenario | A framework | B framework | reactivity | A renderer | B renderer | +| -------------------- | ----------- | ----------- | ---------- | ---------- | -------------- | +| rows-lr-noshift | 1.8 | 1.8 | 0.8 | 2.4 | 0.8 | +| rows-lr-auto | 1.9 | 1.9 | 0.8 | 10.6 | 10.5 | +| rows-ud-auto | 2.4 | 2.4 | 0.8 | 43.2 | 56.7 | +| thumbnail-focus | 2.9 | 2.9 | 0.8 | 14.0 | 8.6 | +| portal-focus-text | 1.9 | 1.9 | 1.8 | 70.9 | 20.6 | +| navdrawer-toggle | 15.3 | 15.3 | 0.8 | 32.7 | 6.0 | +| virtual-row | 8.3 | 8.4 | 2.8 | 15.3 | 10.6 | +| virtual-grid | 11.4 | 12.5 | 5.7 | 30.6 | 67.7 (C: 20.9) | +| poster-swap | 13.4 | 13.5 | 7.5 | 101.3 | 21.1 | +| text-details-panel | 11.9 | 12.1 | 2.1 | 14.0 | 7.8 | +| text-flex-mount-same | 44.6 | 54.7 | 17.9 | 125.5 | 49.6 | +| text-virtual-row | 9.9 | 10.0 | 2.9 | 56.8 | 26.1 | + +The framework column is what this rewrite owns. Its largest sites: the flex +pass's typed arrays and closure (`calculateFlex`: 9.7 KiB per details-panel +press, 28.9 KiB per 20-tile mount), `_stateChanged`'s merge and undo objects, +the `States` species construction on every `remove` (`States`/`_super`), and +`propagateKeyPress`/`keyIdentities` on every key event. The renderer column +for B is dominated by the inlined IIFE in `visit` (section 1) and, in +`thumbnail-focus` and `virtual-grid`, by per-frame params blocks for animated +shader props (a known open renderer risk, by design). + +### 2.3 Counts per op (instrumented build) + +| Scenario | flex passes | node writes | shader writes | animations | walks per drawn frame (B) | `loaded` text emitted / heard (B) | +| ------------------ | ----------- | ----------- | ------------- | ---------- | ------------------------- | --------------------------------- | +| rows-lr-\* | 0 | 2 | 0 | 1 | 1.00 | 0 / 0 | +| thumbnail-focus | 0 | 0 | 6.2 | 2 | 1.00 | 0 / 0 | +| navdrawer-toggle | 0 | 25 | 2 | 2 | 1.00 | 0 / 0 | +| virtual-row | 1.9 | 26.1 | 0 | 3 | 1.00 | 0 / 0 | +| virtual-grid | 2.0 | 179 | 6 | 2.3 | 1.00 | 0 / 0 | +| text-details-panel | **7.0** | 54.4 | 0 | 0 | **2.00** | 5 / 5 | +| text-flex-mount-\* | **42.0** | 91 | 0 | 0 | **2.00** | 20 / 20 | +| text-virtual-row | 4.2 | 29.7 | 0 | 1 | 1.03 | 1.9 / 1.9 | + +A Row press writes 2 props to the renderer and starts 1 animation: the cost +of a press is the framework work around those writes, not the writes. Text +layout: 7 layouts per details-panel press, all cache hits; the time from the +press to the final layout is 6.7 ms on B against 16.7 ms on A (one frame +either way; v1 frames start later). Layout-cache hit rate is 1.00 in the warm +scenarios and 0.00 in `text-flex-mount-new` by design. + +### 2.4 The demo app (`#/benchmark`, 6x, n = 3 per arm, synthetic TMDB data) + +| Metric (median [min-max]) | A | B | C | +| ------------------------------ | ----------------- | ---------------- | ---------------- | +| press mean (ms) | 0.64 [0.59-1.03] | 0.93 [0.78-1.17] | 0.87 [0.75-1.02] | +| handler total (ms, 32 presses) | 11.7 [8.6-11.8] | 13.2 [11.9-15.1] | 11.2 [10.8-13.4] | +| update total (ms) | 42.7 [38.1-60.6] | 53.0 [50.9-63.7] | 55.1 [46.0-56.9] | +| render total (ms) | 89.5 [85.5-114.2] | 33.4 [26.2-47.4] | 30.0 [28.4-31.9] | +| upload total (ms) | 14.2 | 13.4 | 13.3 | +| initial render (ms) | 577 | 571 | 561 | + +Same direction as the suite: v2 draws for about a third of 1.9's render CPU, +and the press itself got more expensive. + +### 2.5 Where the time and allocations go: the top 10 costs per press + +From CPU profiles at 6x (inclusive µs per op on arm B, one run per arm: +[profiles.md](../../perf/results/2026-10-03/profiles.md)), the allocation +profiles above, and the code trace in +[survey-verification.md](../../perf/survey-verification.md). Ranked by their +share across the navigation scenarios. Framework-owned unless marked. + +| # | Cost | Size on B (6x, per op) | Addressed by | +| --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------------------------------- | +| 1 | **Focus-path change**: `updateFocusPath` walks every ancestor and calls `States.add`/`remove` on each (an `Array` subclass: species construction on `splice`, generic builtins), each triggering `_stateChanged` | 190-500 µs; the largest framework bucket in 8 of the 10 profiled navigation scenarios | 3.2, 3.3 | +| 2 | **Row/Column/Virtual navigation and scroll math** reading renderer props through `ElementNode`'s generated accessors: one shared `this.lng[key]` body for every prop (megamorphic), into v2's prototype accessors over typed arrays | 85-290 µs on B against 28-220 µs on A for the same Solid code: most of B's regression | 3.6.6 (new) | +| 3 | **Key dispatch** apart from the handlers: capture and bubble walks over the whole path, `keyIdentities` and handler-name strings per event, all of it again on keyup | 70-160 µs; about 0.4 KiB | 3.1 | +| 4 | **State-style application** (`_stateChanged`): recompute, merge and `Object.assign` every key through its setter | 44-300 µs (NavDrawer 298, Thumbnail 190); 15 KiB per NavDrawer toggle | 3.3 | +| 5 | **Shader-prop writes** for `border`/`borderRadius`: a parse into `border-*` keys per write (about 11 allocations), then a v2 facade write that allocates a vec4 and repacks even when unchanged | 80-320 µs (setter time, approximate) | 3.3 | +| 6 | **Flex passes**: typed arrays and a closure per pass, every child's `x`/`y` written, one pass per relaid text | 100-480 µs where it runs; 9.7 KiB per details-panel press, 28.9 KiB per 20-tile mount | 3.4, 4a | +| 7 | **The second walk per text change** in a flex container (renderer work Solid causes) | walk 136-700 µs in the text scenarios, done twice | 4a | +| 8 | **Renderer allocation from the build** (renderer, app build setting): the inlined IIFE in `visit` | up to 68 KiB per press; 56.7 → 3.4 KiB (rows-ud-auto) and 67.7 → 8.6 (virtual-grid) with `reduce_funcs: false` | demo build, P3 | +| 9 | **`animateProp` restarts**: a Promise per restart, and a new `Animation` whenever the settings object changes (direction changes in Row scroll) | 11-82 µs on B against 1-34 on A | 3.7.1 (stable settings objects) | +| 10 | **Reactive passes per focus change**: `setFocusPath` and `Config.setActiveElement` each run `runUpdates`, and every signal write in a focus callback flushes on its own | 0.8-7.5 KiB of reactivity allocations per op; one flush per write in `portal-focus-text` | 3.2.4 (5.1) | + +Off the press path but on every press that ends in idle: **renderer v2's +idle maintenance** calls `gl.getError()`, a GPU sync, costing 0.6-0.9 ms per +idle transition on B against about 0.18 ms on A (renderer, P4). + +## 3. Architecture + +The rewrite keeps every public name and the compatibility contract pinned by +the Phase 1 tests (section 6). It changes how the work is done, not what it +does. Every item below is measured before and after with the harness and +logged in `docs/perf/log.md`; an item that does not beat the noise floor or +remove allocations is dropped. + +### 3.1 Key dispatch (`focusManager.ts`) + +Today, per key event (keydown **and** keyup): a closure plus `runWithOwner`, a +`keyIdentities` array, 2 to 4 template-string handler names, a result object +per bubble pass, a `_pendingHistoryKey` object even with history off, and a +capture walk over the whole focus path. The keyup repeats all of it, plus a +full bubble walk for `onRelease` handlers that almost no app has. + +Proposed: + +1. **Interned handler names.** One table per mapped key name, built when the + key map is set: `{ on, onCapture, onRelease, onCaptureRelease }`. Unmapped + keys fall back to a small cache keyed by `e.key`. +2. **Skip walks that cannot find a handler.** Solid's `setProperty` + (`solidOpts.ts`) sees every prop name once, when it is set. It raises + module flags the first time a name starting with `onCapture` or ending with + `Release` is set on any node. With no capture handler anywhere, the capture + walk is skipped; with no release handler anywhere, the keyup bubble walk is + skipped. Semantics are unchanged: a walk that could find a handler still + runs, in the same order. +3. **No per-event allocation.** One reused bound listener instead of a + closure per event, no `keyIdentities` array (two locals), a reused result + record, and the history record built only when `Config.focusHistoryDebug` + is on. +4. Unchanged: handlers keep `this` bound to the node, `true` stops + propagation, the capture → bubble → `onKeyPress` order, and `runWithOwner` + (it is what makes a key handler's signal writes flush once, after the + handler). + +### 3.2 Focus change (`updateFocusPath`) + +Today: a walk of every ancestor to the root, `states.has` on an `Array` +subclass per ancestor, an O(depth²) `indexOf` diff against the previous path, +a fresh path array, one `States` species construction per blur (`splice` on +an `Array` subclass builds a new `States`), and every `onFocus`, `onBlur` and +`onFocusChanged` callback outside any batch, so each signal write in a callback +flushes on its own. Then two more reactive passes: `setFocusPath` and +`Config.setActiveElement`. + +Proposed: + +1. **Generation-stamped diff.** Each focus change takes a new generation + number; the walk up from the new leaf stamps each ancestor; the old path's + nodes without the new stamp are the ones that lost focus. O(depth), no + `indexOf`. +2. **Two path arrays, swapped.** `focusPath()` still returns a fresh array to + readers that hold on to it: the signal gets a copy only when something + reads `focusPath` (a cheap `slice` of a handful of nodes), and the internal + diff uses the reused buffers. +3. **`States` without species allocation.** `static get [Symbol.species]()` + returns `Array`, and `remove` shifts in place instead of `splice`. `has` + keeps matching `focus` against `$focus`. +4. **One reactive flush per focus change (needs approval, section 5.1).** Run + the focus phase (the callbacks, `setFocusPath`, `Config.setActiveElement`) + inside one `batch`. The callbacks run in exactly today's order; what + changes is that effects triggered by their signal writes run once, after + the last callback, instead of after each write. + +### 3.3 States and style application (`_stateChanged`, `states.ts`) + +Today every state change recomputes every active state's block, merges them +with object spread (quadratic for several states), builds an undo object and +closures, and `Object.assign`s every key through its setter, changed or not. +A `border` value is re-parsed into `border-*` keys on every apply (about 11 +allocations per border write), and each facade write in renderer v2 allocates +a vec4 and repacks the shader params even when the value is unchanged. + +Proposed, a **compiled style plan**: + +1. When a style object is first applied, compile it once into a plan, cached + in a `WeakMap` keyed by the object: for each `$state` block, a flat list of + (key, value) entries with `border`/`shadow`/`borderRadius` already expanded + into their shader keys. Static module-level styles (the common case) + compile once per app. +2. Each node keeps, in one lazily allocated record, the values it last applied + per key. A state change resolves the target value for each key that any + active or previously active state touches (in `stateOrder` precedence, then + undo falling back to `theme`, then `style`, exactly as today) and writes + only the keys whose value is not `===` the last applied value. +3. `set states` with an unchanged value does nothing. +4. Slower path, same results: inline literals (re-created every render) and + styles with getters (`get color()`) are not cached; they are compiled per + apply, and getters are read at the same moments as today (pinned by + `contract-styles.test.tsx`). +5. `forwardStates` keeps its semantics (it overwrites the children's states, + pinned), without the `slice` per change. + +### 3.4 Flex layout (`flex.ts`, `flexLayout.ts`) + +Today: two implementations (the default build runs `flex.ts`; the demo app +sets `VITE_USE_NEW_FLEX=true` and runs `flexLayout.ts`), an index array, 7 +`Float32Array`s and a closure per pass, every child's `x`/`y` written even when +unchanged, a production `console.warn`, and a pass that bails out whenever a +text child has no size yet. + +Proposed: + +1. **One implementation** (needs approval, section 5.3): keep `flexLayout.ts` + (it is what the demo app runs, and the only one that supports array + `padding`, per-side padding and the `margin` array), fixed where the Phase + 1 tests found it wrong, and delete `flex.ts` and the env switch. +2. **No allocation per pass:** module-level scratch typed arrays grown on + demand, no closure, children walked by index. +3. **Write only what changed:** compare before writing `x`, `y`, `w`, `h`, so + a relayout that moves nothing writes nothing (and starts no transition). +4. **Dirty-tracked, depth-ordered queue:** a container is queued when a + child's size changes; the queue runs deepest first; a container propagates + to its parent only when its own size changed. Target: one flex pass per + affected container. +5. **Text sizes before flex** (section 4): flex never bails on a text whose + font description is loaded. +6. Unchanged (needs approval to change, section 5.4): a `$focus` change to a + flex child's width or height does not reflow its parent. + +### 3.5 Post-mutation scheduling + +Today every `schedulePostMutation` registers both `reprocessUpdates(run)` and +`queueMicrotask(run)`. The microtask run does the work; the in-frame run is a +no-op that still requests a frame. Proposed: the microtask only, plus +`reprocessUpdates` only for the one-shot text fallback while a font +description is missing (section 4). The three phases (delete flush, layout, +focus) keep their order. + +### 3.6 Nodes (`elementNode.ts`, `solidOpts.ts`) + +1. **Never write unknown names to the v2 handle.** Today text-only props + written to a rendered `` (`fontSize`, `lineHeight`, `maxWidth`, + `text`, `contain`, `fontFamily` through the `fontWeight` setter) become own + fields of the renderer handle, and the shader facade grows `border` and + `shadow` fields. These are routed to the `ElementNode` instead (bug fix, + no visible change). +2. `absX`, `absY` and `destroyed` leave the forwarded setter list (they are + getter-only on v2, and writing them throws today). +3. **Child list:** `insertChild(before)` and `removeChild` scan from the end + (Solid appends and removes at the tail most often), and `cleanChildren` + becomes O(n). +4. **Draw order** (bug): Solid's `insertChild(node, before)` and same-parent + moves never reorder renderer siblings, and v2 draws in sibling order. With + a renderer `insertBefore` (section 4), Solid keeps the renderer's sibling + order equal to `children`. This matters for overlapping siblings of equal + `zIndex`: a scaled `$focus` tile in a Virtual row, or a `` before an + anchor. +5. `ElementNode` keeps one fixed shape at construction (already true: it has + no class fields and 27 own assignments). `TextNode` and `States` have class + fields that compile to `_defineProperty` calls under the solid tsconfig's + ESNext target; they become constructor assignments. +6. **Monomorphic prop accessors** (top cost 2). Today every forwarded prop's + getter and setter is the same function body (`this.lng[key]`, + `this.lng[name] = value`) created in a loop, so one feedback vector sees + every prop name: the access is megamorphic, and into v2's prototype + accessors it is also a call V8 does not inline (a returned double is + boxed). Proposed: one accessor per prop with a constant property name + (written out, or generated once at module load from a small table), and + the scroll and flex code reads each prop once into a local. Measured in + Phase 2 against the generated-loop version on arms B and C; kept only if + it beats the noise floor. + +### 3.7 Primitives + +1. **Row and Column** (`handleNavigation.ts`, `withScrolling.ts`): no + transition object per press (the merged forward and backward transitions + are cached per base transition), the scroll reads its inputs once into + locals, and the infinite loop with `wrap` and every child `skipFocus` is + fixed (bug). +2. **Virtual and VirtualGrid:** the spread is split so a `cursor` or + `focusedIndex` change re-runs only the props that depend on it; the + per-press `SliceState` is reused; `style?.focus` becomes `$focus` (bug: the + focus scale was never seen); a window shift costs one flex pass. +3. **Grid:** its 5 handlers stop being re-created on vertical moves. + +### 3.8 What stays as it is + +- The universal-renderer exports and the compiler contract. +- `runWithOwner` around key handlers. +- The undo rule (theme, then style; JSX props are not restored). +- `forwardStates` overwriting children's states. +- Text before fonts load: layout holds until the font description arrives + (estimates are 13% to 26% off; rejected). + +## 4. Renderer integration and text measurement + +All renderer changes stay inside the brief's boundaries (the surface Solid +touches, and text measurement). Each is one focused commit in +`renderer-v2-solid`, with a measured gain from a Solid benchmark, `pnpm test` +green, and updates to `publicApi.test.ts` and `docs/upgrade-1.x-to-2.0.md`. +The DOM renderer (`src/core/dom-renderer`) gets the same API, so the jsdom +suite stays meaningful. + +| # | Renderer change | Boundary | Why | DOM renderer mirror | +| --- | ----------------------------------------------------------- | -------------------------------- | -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | +| R1 | `TextNode.measure(): boolean` | text measurement; node accessors | lays the text out now into the shared `LayoutCache`, so Solid's flex runs before the walk: 1 walk, not 2 | `DOMText.measure()`: synchronous `getBoundingClientRect` when the font is loaded | +| R2 | Text-keyed `LayoutCache` (no `layoutKey` string per lookup) | text measurement | 0.02 µs and 0 B per hit, against 0.36-0.71 µs and about 1 kB | n/a | +| R3 | Typed-array advance and kerning tables in the line breaker | text measurement | 3.2× (title) and 2.3× (description) faster breaking, bit-identical in 17,100 cases | n/a | +| R4 | Public `insertBefore(node, before)` on the node API | node accessors | keeps draw order equal to Solid's child order (bug fix) | DOM `insertBefore` | +| R5 | (if it measures faster) a post-creation bulk-set API | node accessors | apply a compiled style plan in one call instead of one setter per key | a loop of setters | + +R5 is evaluated, not assumed: v2 setters already only store and mark, so a +bulk call saves only the per-call dispatch. It ships only with a measured win. + +Proposals outside the boundaries go to `docs/superpowers/specs/renderer-proposals.md` +(not implemented): layout inside the scene pass (rejected for 1.7, see the +review), and the two known open risks this brief's workloads hit, which are +measured and reported but not fixed: every glyph re-uploaded each drawn frame, +and a params block allocated per frame for animated shader props or sizes. + +## 4a. Text measurement and flex: alternatives and recommendation + +The full review, with method, prototypes and numbers, is +[text-flex-alternatives.md](../../perf/text-flex-alternatives.md). Summary: + +**How it works today (verified on arm B, real WebGL).** A text change inside a +flex container costs **two scene walks** in its frame: walk 1 lays the text +out and queues `loaded`; Solid's handler runs a flex pass between the walks; +the flex writes force walk 2, which re-emits every visible quad and glyph. +Flex runs **once per relaid text**, not once per container: one press of the +details-panel shape ran 12 flex passes over 4 containers. Text under a culled +ancestor (out of bounds or alpha 0) is never laid out, so its flex container +stays unlaid until it scrolls into the bounds margin (arm A gates text layout +the same way). The `loaded` listener is never removed and fires on every +relayout even when the size is unchanged. + +| # | Alternative | Verdict | Evidence | +| --- | ----------------------------------------------------------------- | -------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| 1 | Status quo, event-driven | Rejected | 2 walks per text change, 1 flex pass per relaid text (12 for 4 containers), containers under culled ancestors unlaid | +| 2 | Synchronous `TextNode.measure()` filling the walk's `LayoutCache` | **Adopt** (prototyped: ~60 renderer + ~45 Solid lines) | details panel: walks 2 → **1**, `loaded` 6 → **0**, flex passes 12 → 5 (4 with item 5), layouts in the walk 6 → 0, **identical final positions** | +| 3 | Width-only fast path for single-line text | Reject as a separate path; adopt its tables inside the breaker | a measured text that is also drawn would be laid out twice; the typed-array advance and kerning tables inside `mapTextLayout` are 3.2× (title) and 2.3× (description) faster, bit-identical in 17,100 cases | +| 4 | Cheaper cache keys | **Adopt** a text-keyed cache | 0.02 µs and 0 B per hit against 0.36-0.71 µs and ~1 kB of garbage for the `layoutKey` string; the cache is already shared across nodes by content | +| 5 | Dirty-tracked flex in Solid | **Adopt** a depth-ordered queue and an unchanged-size skip | one pass per affected container; a 20-tile row pass costs 7-12 µs desktop on the real stack and ~2.1 kB of heap | +| 6 | Not waiting on text that cannot affect layout | Adopt the `flexItem={false}` fix only | today an unsized `flexItem={false}` text blocks its whole container (bug) | +| 7 | Estimate sizes before fonts load | Rejected: hold, as today | average-advance estimates are 13-26% off; every correction moves siblings visibly | +| 8 | Flex inside the renderer's walk | Rejected for 1.7 (paper only); `renderer-proposals.md` | touches `ScenePass` and `NodeStore` (out of bounds), breaks one-pass-per-frame for content-sized containers, and gains nothing over 2 + 5 on walk count | +| 9 | Yoga, Taffy, css-layout | Rejected | yoga 3 and taffy are wasm (Chrome 57+); the asm.js yoga build is 365/80 kB min/gzip and unmaintained; css-layout has no `gap` and different semantics | + +**Recommendation: 2 + 3 (tables in the breaker) + 4 + 5 + 6, and hold before +fonts.** Expected per text change in a flex container: **1 walk, 0 `loaded` +events (when the app has no listener), 1 flex pass per affected container, 0 +layouts in the walk**, a cache hit at 0.02 µs and 0 B. Solid measures in its +post-mutation pass, before flex, with no persistent `loaded` listener and a +one-shot fallback while a font's description is missing; writes to a +layout-affecting text prop queue the flex parent. The DOM renderer gets a +synchronous `measure()` (`getBoundingClientRect` when the font is loaded). +Line breaking stays identical to 1.10 by construction: `measure()` calls the +same `layoutText`. + +Risks: a layout-affecting write that bypasses Solid's setters (a raw +`el.lng.fontSize`, a renderer animation of `fontSize`) leaves flex stale, so a +dev-only warning listener is proposed; flex writing a text's `width` can loop +measure → flex (bounded, needs a test); eager measuring adds pressure on the +250-entry layout cache (a browse page of 7 rows × 20 tiles × 2 texts is 280 +layouts), measured by the `text-flex-mount-new` and `text-virtual-row` +scenarios before the default changes. + +## 5. Changes that need the user's approval + +Nothing below is implemented. Each item lists what changes for apps, the +demo-app files it touches, and the expected gain (measured before and after in +Phase 2; an item whose gain does not beat the noise floor is dropped). Approved +items go into `MIGRATION-1.7.md` with their measured numbers. + +### 5.1 One reactive flush per focus change (timing of effects) + +- **What changes:** the focus phase runs inside one `batch`. `onFocus`, + `onBlur` and `onFocusChanged` still run in today's exact order, and memos + read inside them are still current (Solid recomputes a stale memo on read). + What moves: an effect (`createEffect`, a JSX binding) triggered by a signal + written in one of these callbacks runs after the last callback of the change + instead of right after the write. Same microtask, before the frame, so + nothing visible changes; code that writes a signal in `onFocus` and then + reads a node prop that an effect sets from it, in the same callback chain, + would see the old value. +- **Demo app:** every `onFocus`/`onFocusChanged` that sets a signal + (`Portal.tsx`'s tiles, the NavDrawer). Key handlers are unaffected: they + already run inside `runWithOwner`, which batches. +- **Expected gain:** today each signal write in a callback flushes on its own, + plus two more passes for `setFocusPath` and `Config.setActiveElement`. The + `portal-focus-text` scenario measures it. + +### 5.2 Eager layout of text under culled ancestors + +- **What changes:** with `measure()` (section 4a), a flex container's text is + laid out at mount or on change even when an ancestor is out of bounds or at + alpha 0, so the container has its size before it is shown. Visible results + are identical; a container that was never visited is now laid out (today it + stays unlaid, and an app that reveals content once a text has its size could + wait forever). +- **Cost:** about 2 µs desktop per extra title at mount (a 20-tile row lays + out 20 more texts), more pressure on the 250-entry layout cache, and text + in hidden `KeepAlive` pages is laid out while hidden. The alternative keeps + laziness and the second walk when such a container scrolls into view. + +### 5.3 One flex engine + +- **What changes:** keep `flexLayout.ts` (what the demo app runs through + `VITE_USE_NEW_FLEX=true`, and the only engine with array `padding`, + per-side padding and the `margin` array); delete `flex.ts` and the switch. + Apps on the default build (`flex.ts`) see different results only where the + two differ today (pinned in `contract-flex.test.tsx`): cross-axis padding, + array padding (`flex.ts` produced `NaN` positions), the `margin` array, + `flexWrap` with padding, `wrap-reverse` (wrong in both), and a production + `console.warn` on `flexGrow` with no free space. +- **Fixes folded in** (5.8, layout results): `flexLayout.ts` offsets + cross-axis `center`/`flexEnd` by `paddingTop` against the full size (a + centred badge text sits 10 px low and overflows); `justifyContent: center` + with padding is off-centre by the padding (both engines). +- **Gain:** one engine to measure and keep allocation-free; bundle size + (`flex.ts` is about 330 lines). +- **Alternative:** keep both, and rewrite both. Twice the work, and the + default-build engine stays the one the demo app does not exercise. + +### 5.4 A `$focus` width or height change does not reflow its flex parent + +Today it does not (confirmed, pinned). **Proposed: keep it.** Reflowing would +add a flex pass to every focus change that touches a size, and change layout +results for apps that rely on the focused tile overlapping its neighbours. +Say if you want an opt-in. + +### 5.5 The hold contract in the brief does not exist + +The brief's contract lists `onHold` handlers and +`useFocusManager(keyMap, { userKeyHoldMap, holdThreshold })`. Both were removed +in 1.5.1 (commit `78f5fde`, #49) in favour of `useHold`; arms A and B have +neither. The second argument of `useFocusManager` is now a key-event source; +an object without `addEventListener` is ignored. The demo app still passes +them (`App.tsx:5, 32-38`, `KeyHandling.tsx:49`), imports `KeyHoldMap` from +`@solidtv/solid/focusManager` (an export that does not exist and a type that +was removed), and so its EnterHold and BackHold never fire on 1.6.4. +**Decision needed:** (a) the contract is today's behaviour (`useHold`), and +Phase 3 ports the demo's hold handlers to `useHold`; or (b) restore +`onHold` and the options object. Recommended: (a). + +### 5.6 Absorbing renderer breaks in Solid + +The brief asks Solid to absorb a renderer break where a few lines can. +Proposed, off the hot path: + +- `renderer.stage.shManager` keeps working: Solid defines it on the renderer + object at `createRenderer` as a getter returning the renderer (which has + `registerShaderType` and `createShader`), with a dev-only deprecation + warning. The renderer object is one per app, not a node handle. Hits + `src/index.tsx:213` in the demo app. +- `renderEngine` and `fontEngines` in `Config.rendererOptions` are dropped by + Solid before it builds the renderer, with a dev warning. The imports of + `@solidtv/renderer/webgl` and `/canvas` cannot be absorbed: they fail at + module resolution. + +### 5.7 Kept as today (no approval needed, listed so it is explicit) + +- The undo rule: for each key the last state application wrote, undo writes + `theme[key]`, else `style[key]`, else `undefined`; JSX values are never + restored. +- `forwardStates` overwrites the children's own states. +- A reactive `states` string or array replaces the list, dropping a `$focus` + the focus manager added. +- `onSelectedChanged` fires twice on an autofocus mount (Row, Column, + VirtualGrid, Grid with `selected`). Fixing it changes callback counts; say + if you want it fixed. +- VirtualGrid's `onSelectedChanged` is called as `(idx, grid, active, +lastIdx)`, not the brief's `(idx, col, elm)`. +- `states.slice()` and other `Array` methods on `states` return a plain + `Array` instead of a `States` (a side effect of 3.2.3; nothing in Solid or + the demo app relies on it). + +### 5.8 Bug fixes that change behaviour + +Found while pinning the contract; each has a skipped correct-behaviour test. +**Recommended: fix all**, and record each in `MIGRATION-1.7.md`. The ones +marked **layout** change flex or scroll results, which the brief says to ask +about. + +| # | Bug | Where | Kind | +| --- | ----------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------- | ---------- | +| B1 | `wrap` with every child `skipFocus` loops forever | `handleNavigation.ts:42-51` | hang | +| B2 | `states.toggle('focus')` does nothing while `$focus` is on (`has` accepts the bare name, `remove` does not) | `states.ts:60-61, 94` | states | +| B3 | per-element `throttleInput` also drops key releases, so `useHold` on a throttled node waits for its timer | `focusManager.ts:285, 312, 350` | keys | +| B4 | `{ Left: null }` in a key map does not remove the default keys | `focusManager.ts:42` | keys | +| B5 | an unsized text with `flexItem={false}` blocks its whole flex container | `flex.ts:32`, `flexLayout.ts:64` | **layout** | +| B6 | `justifyContent: center` with padding is off-centre by the padding | `flexLayout.ts:360-363` (both engines) | **layout** | +| B7 | cross-axis `center`/`flexEnd` add `paddingTop` against the full size | `flexLayout.ts:266-277` | **layout** | +| B8 | `flexGrow` ratchets: the grown size becomes the next pass's base, so it never shrinks back | `flexLayout.ts:155, 199` | **layout** | +| B9 | a wrapping container with no height never sets `y`, so wrapped lines overlap | `flexLayout.ts:258` | **layout** | +| B10 | `wrap-reverse` does not wrap (`flexLayout.ts`) or stacks to negative `y` (`flex.ts`) | `flexLayout.ts:297` | **layout** | +| B11 | `contain` subtracts `marginRight`/`marginBottom` read from the renderer props, where margins never are (always 0) | `elementNode.ts:1612, 1617` | **layout** | +| B12 | `maxLines={1}` with a multiplier `lineHeight` (1.2) sets `maxHeight` to 1.2 px | `elementNode.ts:1618-1621` | **layout** | +| B13 | Virtual with `scroll="none"` or `"center"` never moves its window: items past the first screen are unreachable | `Virtual.tsx:329-334` | **scroll** | +| B14 | Virtual reads `style?.focus` instead of `$focus`, so its scroll math never sees the focus scale | `Virtual.tsx:104` | **scroll** | +| B15 | VirtualGrid: autofocus with `selected` focuses the wrong item; `selected` back to row 0 leaves `y`; Down past the end corrupts `selected` | `VirtualGrid.tsx:63, 74, 145, 210` | nav | +| B16 | LazyRow/LazyColumn with a small `buffer` lose every other press | `Lazy.tsx:157-165` | nav | +| B17 | `fontWeight` before `fontFamily` in JSX drops the weight from the family name | `elementNode.ts:903-924` | text | +| B18 | `$focus` undo leaves shader sub-props the base style does not name (`border-gap`, `border-align`) | `elementNode.ts:1438-1459, 175-204` | visual | +| B19 | draw order diverges from child order after `insertChild(node, before)` or a same-parent move (v2 draws in sibling order) | `elementNode.ts:930-957` | visual | +| B20 | text-only props written to a rendered `` become fields of the v2 handle; `absX`/`absY`/`destroyed` writes throw on v2 | `elementNode.ts:225-289, 903-924` | internal | +| B21 | `./focusManager` is missing from `package.json` `exports`; `./shaders` points at deleted files | `package.json` | packaging | + +## 6. Proposed numeric targets per scenario + +Against arm B, at 6x, n ≥ 3 runs (n ≥ 5 for an effect near the noise floor), +each beating C/B's spread. "total" is the 6x mean of keydown to the end of +the frame that shows the result. Framework bytes are the `framework` column +of the allocation mode (reactivity and user code do not count). The brief's +starting targets are confirmed, with numbers, and extended: + +| Target | Scenarios | Metric | B today | Target | +| -------------------------------------- | ---------------------------------------------------------- | ---------------------------------- | ---------------------- | -------------------------------------------------------- | +| Key press within a Row (no list shift) | rows-lr-noshift, portal-focus-text | total | 0.186, 0.260 ms | **≥ 2x less** (≤ 0.093, 0.130), and not above arm A | +| | | framework bytes per op | 1.8, 1.9 KiB | **0** in the steady state | +| `$focus` apply and undo | thumbnail-focus | total | 0.399 ms | **≥ 2x less** (≤ 0.200) | +| | | framework bytes per op | 2.9 KiB | **0** | +| Row and Column scroll | rows-lr-auto, rows-lr-always, rows-ud-auto, rows-ud-always | total | 0.18-0.30 ms | **≥ 1.5x less**, not above arm A | +| Virtual window shift | virtual-row, virtual-grid, text-virtual-row | total | 0.910, 1.424, 1.007 ms | **≥ 1.5x less** (≤ 0.61, 0.95, 0.67) | +| | | flex passes per press | 1.9, 2.0, 4.2 | **≤ 1** (text-virtual-row: 1 per changed tile + the row) | +| State toggle with `forwardStates` | navdrawer-toggle | total; framework bytes per op | 0.757 ms; 15.3 KiB | **≥ 1.5x less**; **≤ 1 KiB** | +| Text change in a flex container | text-details-panel | walks per drawn frame | 2.00 | **1** | +| | | flex passes per press | 7 | **4** (one per affected container) | +| | | `loaded` heard (no app listener) | 5 | **0** | +| | | total | 0.228 ms | no regression | +| Text mount in flex | text-flex-mount-same, -new | walks per drawn frame; flex passes | 2.00; 42 | **1; 21** (20 tiles + the row) | +| Node creation | poster-mount, poster-swap, text-flex-mount-\* | total; framework bytes per op | see 2.1, 2.2 | **no regression** against B | +| Bundle size | framework chunk (bench build) | bytes | 95.6 kB / 20.8 kB gzip | **≤ B**, minified sizes measured in Phase 2 | + +Allocation targets are deterministic (one run suffices); time targets need +n ≥ 3. The demo app's `#/benchmark` press mean (B: 0.93 ms) should fall at +least to arm A's 0.64 ms. + +## 7. The contract tests (Phase 1) + +All pass on arm B (the lockstep port, `HEAD` of `1.7` before any rewrite). +They are behavioural: they assert handler order, callback arguments and final +node props and positions, never private fields. Totals for `npx vitest run`: +**661 passed, 23 skipped, 1 todo** (229 before Phase 1), green in 5 shuffled +file orders. A skipped test is a bug written with the correct behaviour +(`it.skip('BUG: …')`); the fix turns it on. + +| File | Tests (skipped) | Pins | +| ----------------------------------------------------------------------------- | --------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `contract-keys.test.tsx` | 25 (3) | `this` = node; `true` stops, `false`/`undefined` bubble; capture root→leaf, then per node `on` then `onKeyPress`; arguments of each; release handlers; custom key-map names; hold through `useHold`; per-element `throttleInput` | +| `contract-focus.test.tsx` | 34 | the exact `onFocus` / `onBlur` / `onFocusChanged` order for sibling, cousin, parent↔child moves; the focus state on the path; `activeElement` as signal and call; `focusPath`; `setFocus`; `forwardFocus` (number, function); `skipFocus`; `autofocus` | +| `contract-states.test.tsx` | 39 (1) | `states` as string, array, object and reactive; `$` and bare keys; `add/remove/toggle/has/is`; `$state` blocks and the undo rule (table in section 5.7); `stateOrder`; `forwardStates` | +| `contract-styles.test.tsx` | 35 | static, inline and spread styles; `combineStyles`; getters; explicit props override `style`; `transition` as `true`, `false`, `{ y: true }`, `{ x: {…} }` and inside a state block | +| `contract-row-column.test.tsx`, `-grid`, `-virtual`, `-virtual-grid`, `-lazy` | 64 (5), 1 todo | Row/Column navigation, `wrap`, `plinko`, `selected`, `skipFocus`; every `scroll` mode and `centerScroll` with pinned offsets; `onSelectedChanged` arguments; Grid; VirtualRow/Column/Grid windows press by press; LazyRow/Column; `onEndReached`, `throttleInput`, `bufferSize`, `displaySize`, `eagerLoad` | +| `contract-flex.test.tsx` | 134 table + JSX (part of 190, 12 skipped with text) | 67 flex cases run on **both** `flex.ts` and `flexLayout.ts` (results and every child's box), the differences between them, auto-size, nested flex, `onLayout`, relayout triggers, `$focus` size not reflowing | +| `contract-text.test.tsx` | (with flex) | concatenated text children; text props reaching the renderer (`contain`, `maxLines`, `maxWidth`, `textAlign`, `lineHeight`, `letterSpacing`, `overflowSuffix`, `wordBreak`); `Config.fontSettings`; `autosize`; text in flex on the DOM renderer | +| `tests/webgl/flex-text.test.tsx` (`pnpm test:webgl`) | 14 | flex with text children on the **real** renderer v2 (WebGL, SDF): final positions after fonts load, text changes, `contain`, `flexItem={false}`, nested containers, text before its font, a row hidden at alpha 0. Same results on both flex engines | +| `contract-nodes.test.tsx` | 25 | data props; `el.lng`; `animate().start().waitUntilStopped()`; writes from handlers; `getChildById`; `.rendered`; `destroy()`; `onCreate`/`onDestroy` promises; `onEvent`, `onAnimation`; child order with ``/`` inserts | +| `publicApi.test.ts` | 20 (2) | the runtime export list of every entry point (97, 64, 16 and 2 names) and the jsx-locator plugin; the 11 universal-renderer functions the compiler imports; `package.json` `exports` | +| `contract-types.tsx` (run by `pnpm tsc`) | type-level | `ElementNode`, `NodeProps`, `NodeStyles`, `TextStyles`, `IntrinsicNodeStyleProps`, `IntrinsicTextNodeStyleProps` and `KeyMap` augmented with `declare module "@solidtv/solid"`; every type-only export name | + +Two test-isolation bugs in existing files were fixed so the suite is stable +(`spatialNavigation` left a document listener behind; `useHold.spec`'s mock +missed an already-loaded module). diff --git a/docs/superpowers/specs/2026-10-04-checkpoint-2-report.md b/docs/superpowers/specs/2026-10-04-checkpoint-2-report.md new file mode 100644 index 00000000..5ddcc0fe --- /dev/null +++ b/docs/superpowers/specs/2026-10-04-checkpoint-2-report.md @@ -0,0 +1,369 @@ +# Solid 1.7 rewrite: Checkpoint 2 report + +Branch `1.7` at `8886583` (plus docs) in `/Users/chris.lorenzo/Code/solid-1.7`, on +`@solidtv/renderer` `v2-solid-integration` at `6392ce4` +(`/Users/chris.lorenzo/Code/renderer-v2-solid`). Nothing was pushed, published, +tagged or released, and the version is still 1.6.4. + +## 1. Where it stands + +- **Phase 2 (the rewrite) and Phase 3 (demo port) are done and merged.** Every + stream got a task review and fix rounds, and the whole branch got a final + review and one fix wave. + - Phase 2 streams: M, F, P, L, N + N3, T1, S and the renderer's R1, R2, R4. + - Phase 3: the demo-app port D1. +- **Gates on `8886583`:** vitest 726 passed, 1 skipped (the documented 5.5 hold + gap). WebGL tests 91/91. `tsc` clean, lint 0 errors. + - Contract tests are unchanged except for the approved bug fixes. Each fix + names its B-id. +- **Results.** Against arm B (the lockstep port on renderer v2), C is faster on + 15 of 18 scenarios. Framework allocation per press is down 72–94 % on every + press scenario. + - The text/flex targets are met: one walk per frame, no `loaded` round trip, + and one flex pass per affected container. + - Most time targets ("≥ 2x / ≥ 1.5x less than B") are **not** met. What is + left per press is mostly renderer frame and reactivity, not Solid's code + (§2). + - Bundle size went **up**, not down (§6). +- **The demo app** (`solid-demo-app-1.7`, branch `solid-1.7`) runs on 1.7 with 5 + small commits, each mapped to a MIGRATION item. + - Its `#/benchmark` press mean: **A 0.52, B 0.57, C 0.48 ms**. C is now below + A. + +## 2. Time per press, A / B / C (6x CPU throttle, n = 3 interleaved runs, median) + +`total` = keydown to the end of the frame that shows it (ms). Series +`docs/perf/results/2026-10-04` (same harness and terser settings as the +baseline; time for all three arms in one interleaved series). + +| Scenario | A | B | C | C/B | C/A | Target (design §6) | Met? | +| -------------------- | ----- | ----- | ----- | ---- | ---- | ------------------ | ------------------ | +| rows-lr-noshift | 0.104 | 0.220 | 0.103 | 0.47 | 0.99 | ≥ 2x less, ≤ A | **yes** | +| portal-focus-text | 0.238 | 0.289 | 0.218 | 0.76 | 0.92 | ≥ 2x less, ≤ A | ≤ A only | +| thumbnail-focus | 0.144 | 0.207 | 0.195 | 0.94 | 1.35 | ≥ 2x less | no | +| rows-lr-always | 0.141 | 0.211 | 0.154 | 0.73 | 1.09 | ≥ 1.5x less, ≤ A | no (1.37x) | +| rows-lr-auto | 0.133 | 0.187 | 0.159 | 0.85 | 1.20 | ≥ 1.5x less, ≤ A | no | +| rows-ud-always | 0.157 | 0.242 | 0.204 | 0.84 | 1.29 | ≥ 1.5x less, ≤ A | no | +| rows-ud-auto | 0.153 | 0.229 | 0.173 | 0.76 | 1.13 | ≥ 1.5x less, ≤ A | no (1.32x) | +| virtual-row | 0.364 | 0.424 | 0.293 | 0.69 | 0.80 | ≥ 1.5x less | near (1.45x) | +| virtual-grid | 0.845 | 0.814 | 0.619 | 0.76 | 0.73 | ≥ 1.5x less | no (1.32x) | +| text-virtual-row | 0.406 | 0.453 | 0.396 | 0.87 | 0.97 | ≥ 1.5x less | no | +| navdrawer-toggle | 0.267 | 0.347 | 0.248 | 0.71 | 0.93 | ≥ 1.5x less | near (1.40x) | +| text-details-panel | 0.293 | 0.201 | 0.254 | 1.26 | 0.87 | no regression | **no** — see below | +| text-flex-mount-same | 1.162 | 0.779 | 0.610 | 0.78 | 0.52 | — | | +| text-flex-mount-new | 1.364 | 1.447 | 1.170 | 0.81 | 0.86 | — | | +| poster-mount | 0.487 | 0.308 | 0.370 | 1.20 | 0.76 | no regression | **no** | +| poster-swap | 0.505 | 0.340 | 0.376 | 1.11 | 0.75 | no regression | **no** | +| page-mount | 5.735 | 4.938 | 4.458 | 0.90 | 0.78 | no regression | yes | +| page-swap | 11.28 | 9.769 | 8.599 | 0.88 | 0.76 | no regression | yes | + +Notes: + +- **text-details-panel:** the timer and the profiler disagree. + - The timer shows C 26 % over B. The text measure moved out of the frame + (C frame 0.086 vs B 0.150) into Solid's microtask (tail 0.113 vs 0.036). + - A CPU profile of one run each counts less inclusive CPU per op on C: about + 336 µs against 459 µs. C has half the post-mutation work outside the flex + pass, and a much smaller renderer frame. + - It is still 13 % under A. A TV run should settle it. +- **poster-mount / poster-swap:** same pattern. The tail grew (0.096 vs 0.034) + because the five texts per poster are measured before the frame. Still + 25 % under A. +- **What is left per press** (thumbnail-focus C profile, µs per op, inclusive, + 6x): + - renderer frame 387; + - `gl.getError()` 474 in idle maintenance (renderer P4); + - reactivity 204; + - Solid's own self time 161. + - Solid's share is now small. The "≥ 2x" targets would need the renderer + proposals (P1 layout in the scene pass, P4 `getError`) and fewer Solid + signals per press. +- **Run-to-run spread** at n = 3 is ±10–30 % on sub-0.25 ms scenarios. A C/B + of 0.85–1.0 there is within noise. + +## 3. Allocation per press (bytes per op, `framework` = Solid's own code) + +A and B are from the 2026-10-03 baseline. C is from this series. Each figure +is one run of the sampling heap profiler with every allocation sampled. + +| Scenario | framework A | framework B | framework C | change vs B | total B | total C | +| ------------------ | ----------- | ----------- | ----------- | ----------- | ------- | ------- | +| thumbnail-focus | 2,969 | 2,960 | **178** | −94 % | 12,637 | 9,919 | +| rows-lr-noshift | 1,843 | 1,846 | **260** | −86 % | 3,532 | 1,803 | +| rows-lr-auto | 1,905 | 1,901 | **285** | −85 % | 13,509 | 11,765 | +| rows-ud-auto | 2,461 | 2,450 | **360** | −85 % | 61,372 | 56,764 | +| portal-focus-text | 1,932 | 1,959 | **310** | −84 % | 24,897 | 24,193 | +| navdrawer-toggle | 15,651 | 15,669 | **1,504** | −90 % | 22,776 | 8,870 | +| text-details-panel | 12,218 | 12,350 | **2,143** | −83 % | 22,466 | 8,359 | +| virtual-row | 8,541 | 8,569 | **2,614** | −69 % | 22,227 | 16,097 | +| virtual-grid | 11,631 | 12,851 | **5,371** | −58 % | 88,195 | 31,276 | +| text-virtual-row | 10,161 | 10,274 | **2,742** | −73 % | 39,900 | 31,237 | +| poster-swap | 13,752 | 13,792 | 8,710 | −37 % | 46,440 | 36,732 | +| page-swap | 227,754 | 212,810 | 164,384 | −23 % | 704,900 | 651,009 | + +Targets: "0 in the steady state" for rows and thumbnail, and ≤ 1 KiB for +navdrawer. Neither is fully met. What remains: + +- **Rows and focus (≈ 180–360 B):** Solid signal writes for the focus path, + `queueMicrotask`, and `buildFocusPath`'s array (`slice`). +- **navdrawer (1.47 KiB):** V8 re-allocates a `States` array's storage each time + the list goes from empty to non-empty and back. +- **Virtual:** mostly the third-party `@solid-primitives/list` (`mapArray`) that + the Virtual primitives use. + +The final fix wave removed the last terser-inlined closures on hot paths. Six +single-use helpers had become a closure per call under terser's default +`reduce_funcs`; the bundle now has none on a per-press path. + +## 4. Text and flex outcome (count mode, B → C, per op) + +| Scenario | flex passes | node writes | walks / drawn frame | `loaded` heard | text layouts | cache hit rate | +| -------------------- | ----------- | ----------- | ------------------- | -------------- | ------------ | -------------- | +| text-details-panel | 7 → **3** | 54.4 → 15 | 2 → **1** | 5 → **0** | 7 → 7 | 1.0 | +| text-flex-mount-same | 42 → **21** | 91 → 82 | 2 → **1** | 20 → **0** | 20 → 40\* | 1.0 | +| text-flex-mount-new | 42 → **21** | 91 → 82 | 2 → **1** | 20 → **0** | 20 → 40\* | 0.0 | +| text-virtual-row | 4.2 → 1.87 | 29.7 → 15.5 | 1.03 → 1 | 1.87 → 0 | 1.87 | 1.0 | +| virtual-row | 1.9 → 0.9 | 26.2 → 15.2 | 1 | 0 | — | — | +| virtual-grid | 2.0 → 1.0 | 179 → 49.9 | 1 | 0 | — | — | + +All text/flex targets are met (details panel target was 4 flex passes: 3). \* The doubled text layouts on mount are approved decision 5.2: the 20 culled +tiles' texts are now laid out at mount (they were deferred until visible). + +**Layout cache under eager layout (your decision, §8.2).** `page-mount` and +`page-swap` lay out every page tile's text (283 strings). Hit rates by +`textLayoutCacheSize` (one run): + +| `textLayoutCacheSize` | page-mount hit rate | page-swap hit rate | Memory if full | +| --------------------- | ------------------- | ------------------ | ----------------------------------------------------- | +| 250 (default) | 0.00 | 0.01 | — | +| 512 | 1.00 | 0.01 | ≈ 0.75 MB if all titles, ≈ 6.3 MB if all descriptions | +| 1024 | 1.00 | 1.00 | ≈ 1.5 MB if all titles, ≈ 12.6 MB if all descriptions | + +## 5. Demo app (Phase 3) + +- **Port: 5 commits on `solid-demo-app-1.7`.** + - terser `reduce_funcs: false`; + - hold handlers moved to `useHold`; + - `Config.fontWeightAlias` for `normal`/`600`; + - the `RoundedRectangle` shader type registered; + - a `holdRequiresRepeat` note in KeyHandling. + - Your own `solid-demo-app` checkout is untouched (its uncommitted + `package.json` and lock file are as you left them), and no TMDB key was read + or copied (fixtures only). +- **Checks.** + - `check-routes`: 53/53 routes render with no errors. + - A held Enter fires `onHold` at ≈ 1000 ms on A, B and C. + - First run (Solid 6552a03): focus paths 52/53 identical B vs C. The 53rd + was a real unapproved change (keys from a removed focused subtree no + longer bubbled), fixed in Solid as N3. + - **Re-run on the final code (8886583):** + - Focus paths: **53/53 identical**. + - Every position difference is one of: + - B6 / B7 (approved centring fixes: complexflex −10 px, image-performance + status −20 px); + - 2.2 eager layout: the hidden debug panel in `LeftNavWrapper`, and the + hero description under ContentBlock's alpha-0 block, are now measured + while hidden — invisible; + - timing read-outs; + - a mount-time race in `#/examples/tmdb` that shows on both arms; + - one new, visible change (next point). + - **`#/flex`, `#/flexsize`, `#/flexgrow` sit 82.5 px higher.** + - Their Row's `onFocus` sets the page Column's `y` from `this.y` at mount. + Text is now sized before the frame, so that read gets the laid-out `y`. + 1.6 read 0, because flex waited for the text's `loaded`. + - The focused row now sits at y 150, where the code intends; on 1.6 it sat + 82.5 px lower. + - Added to MIGRATION (text-sizing entry: "reads right after mount see the + laid-out values"). See §8.9. +- **`#/benchmark`**, median of 3 at 6x, ms: + + | Metric | A | B | C | + | -------------- | ---- | ----- | ---- | + | press mean | 0.52 | 0.57 | 0.48 | + | handler total | 8.63 | 11.39 | 7.33 | + | initial render | 563 | 574 | 567 | + +- **Route creation:** 48 routes, 3 visits each + (`docs/perf/results/routes-2026-10-04.md`). + - C ≈ B on every route. Settle time is dominated by the pages' own animations + and timers. + - `#/grid` reads C/B 1.50, but its visits spread 599–914 ms on B and + 659–950 ms on C. + - `#/examples/tmdb` and `#/entity/people` are slower than A on B and C alike + (renderer v2, pre-existing). + +## 6. Bundle size + +Target: framework chunk ≤ B. **Missed.** + +- **The bench's framework chunk** (Solid + its `@solid-primitives`), minified + and mangled: B 40.8 kB / 14.2 kB gzip, C 66.5 kB / **22.1 kB gzip** + (+7.9 kB gzip). +- **By stream** (gzip of Solid's minified source, no DOM renderer): + + | Stream | Change | What it is | + | ------ | ----------- | ------------------------------------------------------ | + | **S** | **+3.9 kB** | style plans and the B18 base-record / replay machinery | + | N | +1.3 kB | written-out accessors, 3.6.6 | + | T | +1.3 kB | text measuring, font-wait list, DOM parity | + | P | +0.6 kB | | + | F | +0.3 kB | | + | L | +0.3 kB | | + | M | +0.2 kB | | + +- **B18 got expensive.** The brief's B18 was "undo resets `border-gap` and + `border-align`". Getting a blurred node to equal a never-focused one in every + combination took a per-node base record and a replay. Five review rounds plus + two targeted fixes kept surfacing edge cases. This is most of S's + +3.9 kB: §8.4 asks whether that is worth it. + +The renderer is 166.9 / 52.6 kB with R1, R2 and R4, under its CI ceiling of +168 / 53 kB. + +## 7. What MIGRATION-1.7.md says (for app developers) + +`MIGRATION-1.7.md` on `1.7` is complete. It has no placeholders left; its +status line still says "draft until Checkpoint 2". + +- **§1 Renderer 2.0 breaks** (13 rows): + - WebGL + SDF text only; + - `renderEngine`/`fontEngines`/`shManager`/`txMemManager`/`stage.options` + removed; + - unloaded font draws nothing; + - Chrome 47 floor; + - `lng.id` semantics; + - `loaded`/`idle` timing; + - placeholder image order; + - shader registration. +- **§2 Approved changes:** + - 2.1 one reactive flush per focus change (5.1); + - 2.2 eager text layout (5.2); + - 2.3 one flex engine (5.3); + - 2.4 `useHold` (5.5); + - 2.5 `states` Array methods; + - 2.6 renderer breaks absorbed (5.6); + - diffed state writes (a direct write to a key a state names survives an + unrelated state change); + - unchanged `states` is a no-op; + - `$state` blocks read once; + - text sized by Solid before the frame; + - writes or animations on `el.lng` bypass Solid's relayout (dev warning); + - DOM `measure()`/`destroyed`; + - Row/Column transition cache; + - Virtual lays out once per shift; + - a removed element does not lay out its old parent; + - terser `reduce_funcs: false` recommended. +- **§3 Bug fixes that change behaviour:** B1–B21. The largest is B18: border + and shadow undo, with its listed differences from 1.6. + +## 8. Decisions I need from you + +1. **R3 (typed-array line-breaker tables).** + - Gain: title layout 22–26 % faster, description 15–24 %. + - Cost: +1.1 kB / +0.5 kB gzip on the renderer, which puts it 101 B gzip over + the renderer's CI ceiling. + - Kept in the renderer's history (`770c80f`) and reverted. + - Options: raise the ceiling and re-apply; or drop it. +2. **`textLayoutCacheSize` default.** Options: + - keep 250: pages of flex text thrash it under eager layout; + - 512: holds one page; + - 1024: holds two pages, up to ≈ 1.5–12.6 MB. + - My suggestion: 512, plus renderer proposal P6 (a cache sized in bytes, or + scan-resistant). +3. **3.6.6 written-out accessors (+1.3 kB gzip, about 580 source lines).** + - Micro-benchmark: reads 14x and writes 10x faster. + - Scenario A/B at n = 3: text-virtual-row handler −38 %; the others within + noise. + - I kept them. Options: keep; or revert (a large revert now, since S and T + build on them). +4. **B18 scope.** + - What ships: the base-record model. +≈ 3.9 kB gzip of S's code, with the + state-undo differences listed in MIGRATION §3. + - Alternative: narrow B18 back to the brief's text (reset `gap`/`align` + only, 1.6 everywhere else). That is smaller and closer to 1.6, but blur ≠ + never-focused in the combinations MIGRATION lists. + - Tell me if you want the narrow version. + - **Decided: removed** (2026-10-04). B18 is back to 1.6.4 behaviour and a + known bug (`it.skip('BUG: B18 …')`); the rest of S stays. Saved: the + framework chunk 22,106 → 19,802 B gzip (−2.3 kB; §6's +7.9 kB becomes + +5.6 kB), `elementNode.ts` minified+gzip 11,268 → 8,744 B (−2.5 kB, the + review's fix round 1 included). + Framework B/op unchanged within noise (thumbnail-focus 178 → 172, + navdrawer-toggle 1,504 → 1,493, rows-lr-noshift 260 → 260, + portal-focus-text 310 → 306, the median of three runs); thumbnail-focus + shader writes 6.0 → 5.2 per press. Details: `docs/perf/log.md`, "B18 + removed". +5. **A container destroyed in the same run is still laid out.** 1.6.4 does the + same, and its `onLayout` still fires on the destroyed node. A one-line fix + plus test and a MIGRATION entry are drafted. Options: apply as a bug fix, or + leave it as in 1.6. +6. **`Config.fontWeightAlias` default.** Should it gain `normal: ''`? `normal` + today builds a family name nothing loads. The demo had to add it. + Non-breaking. +7. **New bugs found, not fixed** (outside the approved B-list; each would change + visible scrolling): + - **B22:** VirtualRow with an initial `selected` and animations jumps 230 px + on the 1st and 5th press. + - **B23:** VirtualGrid's `applyShift` compensation is a no-op, so content + jumps one row instead of scrolling. 1.6.4 behaves the same. + - **Pre-existing shader bugs:** + - a border on a rounded-only shader is not drawn; + - a border write with `transition: true` is dropped; + - on the DOM renderer, a border written after render is not drawn. + - Fix now as approved bugs, or leave for 1.7.x? +8. **Bundle growth (§6).** Accept +7.9 kB gzip for the CPU and allocation wins, + or ask me to trim. Candidates: item 4, item 3, and S's dead-code-free but + large replay path. +9. **Layout reads at mount (§5).** + - Code that reads a flex-derived position in the same task as the mount now + gets the laid-out value, not 0. In the demo, three Flex pages move up + 82.5 px to where their code intends. + - It follows from the approved text sizing before the frame (T1, design + 3.4). Restoring 1.6's value would mean delaying flex again. + - I listed it in MIGRATION as a behaviour change. Confirm that is + acceptable. + +## 9. Renderer: commits with measured gains (`v2-solid-integration`) + +| Commit | What | Measured | Status | +| ------------ | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | -------------------------- | +| `407b973` R1 | `TextNode.measure()` lays text out before the walk | Solid uses it (T1): walks 2 → 1, `loaded` 5 → 0, flex passes 7 → 3 | kept | +| `87633b8` R2 | text-keyed `LayoutCache`, no key string | per hit 0.39–0.43 µs / 845 B → 0.016 µs / 0 B (title); 0.77–0.83 µs / 1,121 B → 0.017 µs / 0 B (description) | kept | +| `770c80f` R3 | typed-array advance/kerning tables | line breaking 3.1x (title), 1.8–2.2x (description); 17,100 parity cases bit-identical | reverted (`6392ce4`), §8.1 | +| `dc09e5e` R4 | public `insertBefore` | draw order follows the child order (B19) | kept | + +## 10. Deferred renderer proposals (`docs/superpowers/specs/renderer-proposals.md`) + +- **P1:** layout inside the scene pass, so there is no second walk for any + layout. +- **P2:** known open risks: measure, do not fix. +- **P3:** keep bundlers from inlining the walk's helpers as per-node closures. + Under terser defaults this is 56.7 → 3.4 KiB renderer allocation per press + with the workaround. +- **P4:** idle maintenance's `gl.getError()` costs 0.5–0.9 ms per press at 6x. +- **P5:** coalesce queued `loaded` per node. Two writes before one frame give + two events, the first stale. +- **P6:** a text layout cache sized in bytes, or scan-resistant. + +## 11. Open risks and device runs needed + +- **All numbers are a desktop M4 Pro at 6x CPU throttle in Chromium 141.** + Needed before release: + - a run on a real low-end TV (webOS / Tizen, Chrome 47–87 class) of the + demo's `#/benchmark` and the bench scenarios; + - specifically text-details-panel and poster-mount, where timer and profiler + disagree; + - Crankshaft-era V8 (Chrome 47–58): the code avoids `try` in hot functions + and keeps the hidden classes stable, but it was not run there. +- **Chrome 47 floor, pre-existing in 1.6.4 and not fixed:** `globalThis` in + `clickInspector.ts`, and `Object.entries` in `domRenderer.ts`. +- **The test suite is order-sensitive** when files share one worker + (`--no-file-parallelism`; pre-existing). The default parallel run is clean. +- **The bench's `--skip-build` reuses a stale count-mode build.** I hit this in + this series and re-ran; documented in `docs/perf/README.md`. +- **Process notes.** + - Stream S needed 5 fix rounds plus 2 targeted fixes, past the usual + 5-round limit. I continued with fully specified fixes rather than stopping; + the final review covered the result. + - One agent popped another stream's lint-staged backup from the shared git + stash. It was repaired and verified; your stash entry is intact. diff --git a/docs/superpowers/specs/renderer-proposals.md b/docs/superpowers/specs/renderer-proposals.md new file mode 100644 index 00000000..602a9c11 --- /dev/null +++ b/docs/superpowers/specs/renderer-proposals.md @@ -0,0 +1,112 @@ +# Renderer proposals from the solid 1.7 work + +Changes that would help `@solidtv/solid` 1.7 but fall outside what the 1.7 +brief lets Solid's work change in `@solidtv/renderer` (the surface Solid +touches, and text measurement). None is implemented. Each gives the evidence +and what it would take. + +## P1. Layout inside the scene pass + +**Idea.** Run Solid's flex layout in the renderer's walk, where text sizes are +known in the node's visit, so a text change costs no `loaded` event and no +second walk. + +**Why not in 1.7.** + +- It changes `ScenePass` and adds flex props to `NodeStore`'s typed arrays, + both out of bounds. +- Content-sized containers need a bottom-up measure and a top-down placement: + two walks, or a pre-pass over dirty containers. Solid's post-mutation pass + plus a synchronous `TextNode.measure()` (in bounds, adopted for 1.7) is that + pre-pass already, and reaches one walk per text change without moving flex. +- Solid's flex semantics (`flexBoundary`, `flexCrossBoundary`, `flexItem`, + `flexOrder`, `onLayout`, the Row and Column scroll on layout) would move into + the renderer, and `onLayout` callbacks are app code that must run between + walks anyway. + +**Evidence.** `docs/perf/text-flex-alternatives.md`, section 2.8. With +`measure()` and a depth-ordered queue the walk count is already 1; the only +remaining gain is Solid's per-pass accessor overhead, which the 1.7 flex +rewrite addresses inside Solid. + +**Prerequisite for revisiting.** The measured cost of Solid's flex after the +1.7 rewrite, on device. + +## P2. Known open risks this brief's workloads hit (measure, do not fix) + +From the renderer's `HANDOFF.md`. The 1.7 benchmark suite reports both; the +decisions stay with the renderer. + +- **Every glyph is re-uploaded each drawn frame** (spec 10.3). Text-heavy + scenarios (`text-details-panel`, `text-flex-mount-*`, `text-virtual-row`, + `portal-focus-text`) pay it on every animation frame of a press. +- **Animated shader props, or `w`/`h` on a shaded node, allocate a params + block per frame** (about 350-470 B per animated node per frame). Hit by the + `$focus` scale with a border (`thumbnail-focus`, `poster-*`) and the + NavDrawer width transition (`navdrawer-toggle`). + +## P3. Keep bundlers from inlining the walk's helpers as closures + +**Measured.** The demo app's production build (terser with `compress` on, +`mangle` off) inlines `ScenePass`'s single-use world-transform helper into +`visit` as an IIFE, `!function(s, id, parent){…}(s, id, parent)`, which +allocates on every dirty node the walk visits, every frame. The solid 1.7 +benchmark (arm B, alloc mode, every allocation sampled) charges up to 68 KiB +per key press to it. Rebuilt with `compress: { reduce_funcs: false }`, the +IIFE is gone and the renderer's allocations per press drop from 56.7 to +3.4 KiB (rows-ud-auto), 67.7 to 8.6 KiB (virtual-grid), 8.6 to 4.0 KiB +(thumbnail-focus) and 49.6 to 21.0 KiB (text-flex-mount-same) +(`docs/perf/results/2026-10-03/profiles.md`). Three other renderer helpers +are inlined the same way (`bench/dist/B/assets/renderer.js`: the setter +helper near line 1328, a UV helper near 2434, and one at 4454). + +**Why it is a proposal.** The fix in the renderer is in `ScenePass` (out of +bounds): keep the helper from being a single-use top-level function, for +example a `ScenePass` method or a `/*@__NOINLINE__*/` call-site annotation, +and add a check to the renderer's size or allocation tooling that builds with +a terser config like the demo's. Until then an app's build sets +`reduce_funcs: false` (proposed for solid-demo-app in Phase 3, and for +Solid's docs). + +## P4. Idle maintenance's `gl.getError()` after every press + +**Measured.** Every press that ends in idle runs the renderer's idle +maintenance, whose out-of-memory probe calls `gl.getError()` (a GPU sync). +In the 6x profiles it costs 0.6-0.9 ms per op on renderer v2 against about +0.18 ms on 1.9.3. It runs after the frame that shows the press, so it does +not delay that frame, but it is main-thread CPU on every isolated key press. + +**Why it is a proposal.** It is in `Renderer.maintain` and `GlContext`, not +the surface Solid touches. Options for the renderer: probe less often (every +Nth idle transition, or on a timer), or only after frames that uploaded +textures. Needs a device measurement first (a TV's driver may make the sync +cheaper or far more expensive). + +## P5. Coalesce queued `loaded` events per node + +**Measured.** With Solid measuring flex text through `TextNode.measure()` +(stream T), two text writes to one node in separate tasks before one frame +each queue a `loaded` event; the listener hears both, the first with a stale +size (`[257, 52]` where one event `[52]` is enough). The final layout is +correct; the cost is an extra listener call per stale write, and an app +listener (Marquee-style width tracking) sees a size that was never drawn. + +**Why it is a proposal.** The event queue is the renderer's (between walks). +Options: keep one pending `loaded` per node and update its payload in place, +or drop a queued event whose node was re-measured since. + +## P6. A text layout cache that a page swap does not flush + +**Measured.** Eager layout of flex text (approved decision 5.2) pushes a +page's strings through the text-keyed layout cache (R2) on mount. With the +default 250 entries, `page-mount`/`page-swap` (283 strings) hit 0.00-0.01; +with 1024 entries, 1.00. An LRU falls to a 0% hit rate as soon as a page's +working set exceeds its capacity, whatever the capacity. + +**Why it is a proposal.** The cache policy is the renderer's. Options: size +the cache in bytes rather than entries (a description layout is about +8x a title's), or make it scan-resistant (for example a small probation +segment, as in SLRU/2Q), so a one-off page does not evict the strings that +recur. Solid can only pick `textLayoutCacheSize` at init. + +