Skip to content

Measure the resting rail entry only for a row the rail could hold - #2802

Merged
max-sixty merged 1 commit into
mainfrom
agent-a1b6cad924b279ca7
Oct 14, 2026
Merged

max-sixty merged 1 commit into
mainfrom
agent-a1b6cad924b279ca7

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

On a page where every margin row is a pin, each thread step (t) spent about 100 ms restyling the whole document for a width it never used. layoutMarginRows reads a rail entry's width at the start of every pass, and with no live rail entry restingRail() inserts a measuring clone and removes it, two whole-document restyles (about 3,070 elements on the test page) plus a third at the pass's next skipped() read. A step runs two passes. The width feeds only rowPosture, which returns "pin" without it wherever the rail does not stand or does not stand beside the target's scroller. The path came in with #2252.

The pass now reads the width lazily, once per pass, for the first row the rail stands beside. Pin pages, and rail pages with no rows, no longer clone; a rail page's first comment still measures the native primitive, as restingRail's contract above it requires.

I did not cache the measurement per viewport and theme. The comment on restingRail rules out a cached size, since the allocation comes from the live cascade, package and author overrides included, and a revision can change those without a resize or theme switch. After this change the clone runs only on a rail page that has no rail row yet, or whose rows have all pinned (blocks wider than the rail's inner edge, or sidenotes level with them), so a cache would buy little and add an invalidation rule.

Thread step median, 104-thread page, headless Chrome 153 at 1440x900, 5 runs x 8 steps from the top of a fresh page, keydown to the first painted frame showing the thread:

page main this PR
bare <main> (every row a pin) 186 ms 82 ms
layout-column (rail rows) 75 ms 69 ms

Tests run: pnpm run test:runtime (419 pass); the margin rail/pin posture, first-rail-allocation, sidenote and pin-seating tests in tests/browser/test_render_margin.py, and the thread-walk and thread-travel tests in tests/browser/test_render_navigation.py (33 pass).

This was written by Claude Code on behalf of max-sixty

`layoutMarginRows` read a rail entry's width on every pass, and with no
live rail entry `restingRail()` inserts a measuring clone and removes it,
restyling the whole document twice and forcing a third restyle at the
pass's next read. The width feeds only `rowPosture`, which answers "pin"
without it wherever the rail does not stand or does not stand beside the
target's scroller. On a page whose rows are all pins, every pass paid for
it: a thread step (`t`) runs two passes.

The pass now reads the width lazily, once, for the first row the rail
stands beside. Pin pages, and rail pages with no rows, no longer clone;
a rail page's first comment still measures the native primitive, as the
`restingRail` contract requires.

Thread step median on a 104-thread page, headless Chrome, 5 runs x 8
steps: bare `<main>` (all pins) 186 -> 82 ms; `layout-column` (rail
rows) 75 -> 69 ms.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit d9502d8 into main Oct 14, 2026
3 checks passed
@max-sixty
max-sixty deleted the agent-a1b6cad924b279ca7 branch October 14, 2026 02:04
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.

2 participants