Repository navigation
perf: one reactive flush per focus change, States without construction per remove, Row/Column/Grid leftovers (1.8 streams F, P) - #90
Merged
Conversation
handleNavigation merged transitionLeft/Right/Up/Down into `transition`
with a new object (and a `{}` when unset) on every press. The merged
objects are now cached by base transition, then by directional
transition (WeakMaps), so a press allocates nothing and the node keeps
the same `transition` object while the direction and the base do. A new
base from the app still gives new merged objects.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 4a044c3)
…sition The merged-transition cache keyed every Row without a `transition` object by one shared sentinel, so those Rows shared one merged object per direction and an app mutating `row.transition` in place would have changed it for all of them. Without a base object the cache is now keyed by the element. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit d911c85)
Rows given the same base `transition` object shared the merged objects, so an in-place edit of one Row's `transition` reached the others. The cache is now per element, rebuilt when the element's base `transition` object changes. An in-place edit of the base after a press in that direction is not picked up (it was re-spread on every press): assign a new object. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 058070a)
Grid built onUp/onDown/onLeft/onRight/onFocus inline in its spread, which re-runs on every vertical move (for `y`), so each move made five new functions and wrote them to the node. They are now created once; each reads the app's handler of the same name when called, so a reactive one still runs first and still stops the Grid's move by returning true. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 1f25922)
`y={scrollY()}` sat in Grid's spread, so every vertical move (a
focusedIndex change) re-ran every prop of the spread. The spread now
takes the initial y once and an effect of its own writes the changes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 728fcb5)
- static get [Symbol.species]() returns Array: Array methods (slice,
splice, filter, ...) build a plain Array instead of running the States
constructor with a length as its callback (MIGRATION 2.5).
- remove() shifts in place instead of splice; so does merge().
- B2: remove('focus') removes '$focus', as has('focus') matches it, so
toggle('focus') while '$focus' is on turns it off.
- onChange is a declared field assigned in the constructor (no class
field emit), and the object form no longer uses Object.entries
(Chrome 47 floor).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 14e84c7)
…hange - updateFocusPath stamps each node of the new path with a generation; a node of the previous path without the stamp lost focus (no indexOf diff). The path is built in a reused buffer and published as a copy, since focusPath readers keep the array. A focus callback that calls setActiveElementCore re-entrantly gets its own array, and the outer change falls back to the scan, as before (pinned by a new test). - 5.1: setActiveElementCore runs the focus phase (callbacks, setFocusPath, Config.setActiveElement) in one batch: callback order is unchanged; effects triggered by their signal writes run once, after the last callback (new contract test). - No closure per focus change: the batch, and Config.setActiveElement as useFocusManager installs it, read module variables. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 560717f)
…without an IIFE Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 3ebfa37)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports what is left of 1.8's Stream P (primitives) and Stream F (focus) onto
main. This follows #89 (Streams L, T and N). The 8 commits are cherry-picked with-x, so each names its 1.8 original.What's in it
Stream P
transition(4a044c3,d911c85,058070a). A key press reuses the merged object for its direction instead of allocating one. The cache is per element, so editing one Row'stransitionin place never affects another. It is rebuilt when the element's basetransitionobject changes.1f25922). Before, they were rebuilt on every vertical move. Each handler still runs the app's own handler of the same name first, read at call time.yfrom its own effect (728fcb5). A vertical move no longer re-runs every other prop of the spread.Stream F
560717f):onFocus,onBlur,onFocusChanged,focusPath,activeElement) runs in one Solidbatch.indexOf, and a reused buffer with onesliceper change._signalWrapperis gone.setActiveElementCorehas no local (3ebfa37), so terser inlines it without wrapping it in a function.States: no construction on every remove; fixes B2 (14e84c7).States[Symbol.species]isArray.removeandmergeshift items in place.remove('focus')andtoggle('focus')now match'$focus', ashas('focus')already did.Behaviour changes for apps
onFocus,onBlurandonFocusChangedrun in the same order as before.focusPathrun in the same flush as those onactiveElement.activeElementorfocusPathto effects.batchdrops the effects queued by earlier callbacks of that change. The error still propagates.statesarray methods (2.5):states.slice(),filter(),map(),splice()and the otherArraymethods return a plainArray, not aStates.Statesmethods onnode.statesitself are unchanged.states.remove('focus')andtoggle('focus')act on'$focus'. Before, they did nothing when only'$focus'was in the list.transitionobject in place is not picked up; assign a new object, as with other cached objects.Measured gains (from 1.8's
docs/perf/log.md)States and the focus path, single 6x runs on desktop V8 against the 1.6.4 lockstep port. Memory per press:
updateFocusPath's 148 bytes per press are gone.Those figures also include 1.8's key-dispatch rewrite, which
mainalready has from perf: remove per-press allocations (no functional change) #71. The gain over currentmainis theStates, focus-path and batch part, so it will be smaller.Row, Column and Grid: not measurable in a single run, since the merged transition was one small object per press. No bench scenario covers Grid. The Grid contract test shows an unrelated prop getter read once (at mount) instead of 4 times over three vertical moves.
Not ported, on purpose
8b5a5ad,8161b66and7fcd44c(1.8's key-dispatch rewrite):mainalready has the same work from perf: remove per-press allocations (no functional change) #71 and B3/B4 from Backport 1.8 bug fixes to 1.7 (B1, B3, B4, B13–B17, B21, renderer 2.0 compat) #72. What's left of them is cosmetic and would conflict withConfig.inferKeyRepeat, which onlymainhas.7cbdbc7: it fixes walk-skip flags that 1.8's rewrite added andmainnever had.Conflicts resolved
Grid.tsx:main'sstrictBounds={false}is kept next to the handlers that are now created once and theyeffect.focusManager.ts:main's comment and clearing of_dispatchEventare kept. 560717f'spublishActiveElementis added, and a comment that still named the removedownerContextis reworded.Testing
npm run tsc,npm run lintandnpm run buildpass.npm test: 751 passed, 1 skipped, with 4 workers, with 1 worker, and with shuffled file orders (seeds 3, 4, 5). One skip fewer thanmain, because 14e84c7 turns on the B2 test.npm run test:webgl: 38 of 38 pass.🤖 Generated with Claude Code