Skip to content

perf: compiled style plans and diffed state application, B18 as 1.6.4, the final fix wave (1.8 stream S) - #91

Merged
chiefcll merged 2 commits into
mainfrom
perf/streams-s-fixwave
Nov 20, 2026
Merged

chiefcll merged 2 commits into
mainfrom
perf/streams-s-fixwave

Conversation

@chiefcll

Copy link
Copy Markdown
Contributor

Ports 1.8's Stream S (compiled style plans, diffed state application), the B18 removal you decided at Checkpoint 2, and the rest of the final fix wave. This follows #89 and #90.

The three 1.8 merges (0932889, 8886583, de1d782) are applied as one net 3-way patch rather than commit by commit. Picking S on its own first would have meant merging main's #73 border-shader swap into B18 code that the removal then deletes. This way #73 is merged once, against the final code.

What's in it

Stream S (new src/core/stylePlan.ts)

  • A $state block, and a border or shadow object, is compiled once and cached by object identity. A getter in a $state block is still read on every apply.
  • A state change writes only the keys whose resolved value changed. Before, every change and every undo re-wrote every key of every active state.
  • Exception for the border keys (border, borderTop, borderRight, borderBottom, borderLeft): when a change writes one of them, they are all written again in order, as 1.6 did, so the sides and the whole border combine as before.
  • Assigning an unchanged states list does nothing. That covers an array or string with the same states in the same order, or an object that adds and removes nothing.
  • Setting linearGradient or radialGradient again updates the shader it made instead of creating a new one.
  • B18 stays a known bug, as in 1.6.4. Border and shadow writes merge into the shader props, the later write winning, and a state undo writes the fallback object through the same setter. 1.8 skips the B18 test as it.skip('BUG: B18 …').

Final fix wave: hot paths without per-call closures under terser's default reduce_funcs

  • The layout phase runs inline in the post-mutation pass, and is skipped when nothing is queued.
  • insertChild, removeChild, animate(), render(), destroy() and _listenTextLoaded allocate no closure or context per call.
  • TextMeasure declares its fields; measureFontWaiting becomes a static method of it.
  • The flex scratch arrays grow inline; preFlexwidth and preFlexheight are set in the constructor.
  • An animation without settings shares one settings object, and onAnimation.stopped is called through the timer's arguments instead of a closure per write.
  • render() reads onEvent with for…in, for Chrome 47.

Behaviour changes for apps

  • Adding a second state no longer restarts the first state's transition. For example, 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. For example, node.border = { width: 6, color: GREEN } made while $focus sets a blue border stays green when $hover: { alpha: 0.5 } is added; 1.6 showed blue again. The border-key exception above still rewrites borders together.
  • The undo is a state change too. If the base value (theme, else style) is === the value the state wrote, the undo skips the key. Otherwise it restores theme, then style, then undefined, as before.
  • Changing a $state, border or shadow object in place after its first use is not seen. Assign a new object or use a getter. Main's tests/shaderProps.test.ts pinned the old result and now checks both cases.
  • Assigning an equal states list no longer re-applies the states.
    • With forwardStates, a child that changed its own states keeps them until the parent's list actually changes.
    • node.states = node.states no longer empties the list.
  • A gradient shader shared between nodes is now updated in place for all of them.

Merged with main

Measured gains (from 1.8's docs/perf/log.md and Checkpoint 2 report)

  • State application allocates nothing per press. None of the replaced functions appears among the sampled allocation sites. Solid's own memory per press:
    • thumbnail-focus: 2.63 → 1.52 KiB
    • navdrawer-toggle: 14.91 → 7.29 KiB
  • CPU: _stateChanged inclusive time 49.0 → 37.6 µs per press on thumbnail-focus, and 98.4 → 73.8 µs on navdrawer-toggle.
  • Writes: navdrawer-toggle makes 23 node writes per press instead of 25, and 1 shader write instead of 2.
  • Time is flat within noise.
  • Fix wave: six single-use helpers had each become a closure per call under terser's default reduce_funcs. The bundle now has none on a per-press path.
  • Size (after the B18 removal): about +1.4 kB gzip for Stream S.
  • All figures are from desktop V8 on 1.8, against the 1.6.4 lockstep port. They were not re-measured on this branch or on TV hardware.

Found while merging, not changed here

On main today, #73 swaps a roundedWithShadow node to roundedWithBorderWithShadow when a border is added. If an app registered only some types, as the demo app does, createShader returns null for that type and the node loses its shader. _syncShaderType could keep the current shader when the new type isn't registered. That would be a separate fix to #73.

Testing

  • npm run tsc, npm run lint and npm run build pass.
  • npm test: 767 passed, 2 skipped (one is the deliberate BUG: B18 skip). Same result with 4 workers, with 1 worker, and with shuffled file orders (seeds 3, 4, 5).
  • npm run test:webgl: 67 of 67 pass, including 1.8's new shader-props suite and main's border-shader suite.
  • Not checked on a device or in the demo app.

🤖 Generated with Claude Code

chiefcll and others added 2 commits November 20, 2026 11:03
…am S), B18 as 1.6.4, the final fix wave

Ports 1.8's net change across three merges, applied as one 3-way patch so
main's #73 border-shader swap is merged once, against the final code:

- 0932889 Merge stream S: compiled style plans, diffed state application
- 8886583 Merge the final fix wave: no per-call closures on hot paths
- de1d782 Merge: remove the B18 fix (Checkpoint 2); border and shadow
  writes as 1.6.4

Stream S: a $state block, border or shadow object is compiled once and
cached by identity (src/core/stylePlan.ts). A state change writes only the
keys whose resolved value changed; the border keys are rewritten together
in tracked order when one of them changes, as 1.6 did. Assigning an
unchanged `states` list does nothing. Setting a gradient again updates the
shader it made. B18 stays a known bug (1.6.4 behaviour).

Final fix wave, the parts main did not have: the layout phase inline in the
post-mutation pass; insertChild, removeChild, animate(), render(),
destroy() and _listenTextLoaded without per-call closures or contexts;
TextMeasure declares its fields (measureFontWaiting is a static method);
flex scratch arrays grown inline; preFlex sizes in the constructor; one
shared animation-settings object; onAnimation.stopped without a closure
per write; render() reads onEvent with for-in (Chrome 47).

Left out, as main already has them: the fix wave's focusManager.ts
(8161b66, 7fcd44c; #71) and states.ts (e9a3713, f7b5481; #71) changes and
Virtual.tsx (037c0f5; #72). main's tests/states.test.tsx is kept.

Merged with main:
- #73: the shader accessor and the effects setter keep writing the
  sub-props into _shaderProps and call _syncShaderType, so a shader
  convertToShader made still swaps to or from roundedWithBorder when a
  border width moves to or from 0 (before an animation reads its start
  values; after it stops for one shrinking to 0). main's convertToShader
  is kept.
- #71's parseAndAssignShaderProps name cache (borderSideMap,
  shaderPropNames) is replaced by stylePlan's shaderParse.
- tests/webgl/shader-props.test.tsx N5 registers
  roundedWithBorderWithShadow and expects a border written after a shadow
  to swap to it, per #73; a shadow after a border keeps roundedWithBorder.

(cherry picked from commits 0932889, 8886583, de1d782 on 1.8, net)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…gn 3.3.1)

main's test pinned the 1.6 result, where an object changed in place and
assigned again wrote its new values. Stream S parses a border or shadow
object once and caches it by identity: assign a new object instead. The
test now checks both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant