Repository navigation
fix(core): batch positional class invalidation per parent - #592
Merged
Merged
Conversation
houko
force-pushed
the
fix/positional-class-invalidation
branch
from
November 17, 2026 15:37
10e2029 to
87dd2ca
Compare
A child that gained a positional class searched its parent's native children for its place, rebuilding that list after every insertion, so mounting N striped rows still took memory and time with the square of N. It now resolves with the place its parent's queued walk last found, and queues that walk when the place is not known yet.
Children that a relational selector also matches resolve their positional classes through the selector path, which reads their place itself. The test reorders such children and checks both their own positional classes and the parent's :last-child selector.
houko
force-pushed
the
fix/positional-class-invalidation
branch
from
November 18, 2026 01:26
87dd2ca to
dac33fc
Compare
Collaborator
Author
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.
Summary
Closes #584. A
last:hiddenin an unrelated branch used to make mounting 4,000 plain children rebuild and walk their siblings on every insertion. Child-order and spacing changes now coalesce per parent before resolve, and each positional child resolves with the index from that walk. Moving or removing the last positional child leaves no permanent dependency flag.A child that gains a positional class no longer searches its parent's children for its place either: it keeps the place the parent's last walk found and queues that walk when the place is not known yet. Mounting thousands of striped rows (
odd:bg-gray-100) was still quadratic before this, in both time and memory.Spacing refreshes also clear removed spacing classes and propagate positional, peer-dependent and environment-dependent spacing to the affected children.
Relational selectors (
[&>view:first-child],has-[...]), which landed on main after this branch started, still read a matched view's place when they match it, sonode.position()stays for them. A child that a relational selector also matches resolves its own positional classes through that path;TestPositionalClassesBesideRelationalSelectorscovers it through reorders.Targets
core); applies to every backendScreenshots
None; rendering behavior is preserved.
Verification
TestMountingChildrenWalksSiblingsOncemeasures the bytes allocated mounting 4,000 children, plain besidelast:hiddenelsewhere and striped withodd:, against the same children without positional classes. With main's implementation: 16,902 and 7,051,918 extra bytes per child (it fails, as doTestPositionalAndSpacingClassesCanBeRemovedandTestPositionalSpacingFollowsReorderedRows); on this branch: 17 and 300 (the limit is 2,048).Show, keyedEachadditions/removals/reorders, nested transparent regions moved between parents, view identity, dynamic class removal, positional spacing and positional children beside relational selectors.go tool nsgo test ./core(717 passed) andgo tool nsgo test -run 'Layer|Skills|Doc' .(35 passed) on Linux;go vet ./corefor windows/amd64, linux/amd64, android/arm64 and js/wasm.go tool nsgo check -target allon Linux (every target but the Apple mobile ones) andgo tool nsgo check -target ioson macOS: every target vetted.go tool nsgo test -target macos -run 'Positional|Spacing|MountingChildren|PeerRegions|Relational' ./coreon macOS: 25 passed.go tool nsgo test -bench BenchmarkMountChildren ./core -- -benchtime=5x -benchmemon the same Linux host:odd:)Benchmark data is approximate.
Checklist