Skip to content

fix(core): batch positional class invalidation per parent - #592

Merged
houko merged 3 commits into
mainfrom
fix/positional-class-invalidation
Nov 18, 2026
Merged

houko merged 3 commits into
mainfrom
fix/positional-class-invalidation

Conversation

@houko

@houko houko commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Closes #584. A last:hidden in 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, so node.position() stays for them. A child that a relational selector also matches resolves its own positional classes through that path; TestPositionalClassesBesideRelationalSelectors covers it through reorders.

Targets

  • Shared code (core); applies to every backend

Screenshots

None; rendering behavior is preserved.

Verification

  • TestMountingChildrenWalksSiblingsOnce measures the bytes allocated mounting 4,000 children, plain beside last:hidden elsewhere and striped with odd:, against the same children without positional classes. With main's implementation: 16,902 and 7,051,918 extra bytes per child (it fails, as do TestPositionalAndSpacingClassesCanBeRemoved and TestPositionalSpacingFollowsReorderedRows); on this branch: 17 and 300 (the limit is 2,048).
  • Regressions cover Show, keyed Each additions/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) and go tool nsgo test -run 'Layer|Skills|Doc' . (35 passed) on Linux; go vet ./core for windows/amd64, linux/amd64, android/arm64 and js/wasm.
  • go tool nsgo check -target all on Linux (every target but the Apple mobile ones) and go tool nsgo check -target ios on macOS: every target vetted.
  • go tool nsgo test -target macos -run 'Positional|Spacing|MountingChildren|PeerRegions|Relational' ./core on macOS: 25 passed.
  • go tool nsgo test -bench BenchmarkMountChildren ./core -- -benchtime=5x -benchmem on the same Linux host:
4,000 children main This PR
Plain, no positional class elsewhere 54.8 ms, 96.0 MB 49.3 ms, 94.5 MB
Plain, positional class elsewhere 145.7 ms, 165.0 MB 52.7 ms, 95.3 MB
Striped (odd:) 28.3 GB allocated (in the test above) 85.4 ms, 141.7 MB

Benchmark data is approximate.

Checklist

  • Conventional Commit title
  • Owning styles document updated (changelog frozen until 0.1.0)
  • No new dependencies

@github-actions github-actions Bot added bug Something isn't working documentation Improvements or additions to documentation core size/M labels Nov 17, 2026
@houko
houko force-pushed the fix/positional-class-invalidation branch from 10e2029 to 87dd2ca Compare November 17, 2026 15:37
@github-actions github-actions Bot added the conflict Conflicts with the base branch; resolve it first label Nov 18, 2026
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
houko force-pushed the fix/positional-class-invalidation branch from 87dd2ca to dac33fc Compare November 18, 2026 01:26
@github-actions github-actions Bot removed the conflict Conflicts with the base branch; resolve it first label Nov 18, 2026
@houko

houko commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Reviewed. The only CI failures are unrelated to this change: TestNestedZoomedCanvasIsSharp, fixed on main by #631, and the hosted runner's slow simulator boot, addressed by #634.

@houko
houko marked this pull request as ready for review November 18, 2026 02:51
@houko
houko merged commit b92dfcb into main Nov 18, 2026
20 of 22 checks passed
@houko
houko deleted the fix/positional-class-invalidation branch November 18, 2026 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working core documentation Improvements or additions to documentation size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

core: one positional class anywhere makes adding children quadratic for every parent

1 participant