Skip to content

Find the rail's Tab stop among the rows in the window, so a scroll stops measuring every margin row - #6065

Merged
max-sixty merged 3 commits into
mainfrom
grind/rail-roving
Nov 15, 2026
Merged

max-sixty merged 3 commits into
mainfrom
grind/rail-roving

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

The rail's one Tab stop is its highest row in view. syncRoving (browser/runtime/annotation-overlay/margin-projection.js) found it on every scroll by reading each margin row's visibility and box, three times over (directly, inside visibleRows, and inside holdTabStop), so a wheel step's work grew with the rows the margin holds.

An IntersectionObserver rooted at the document's window now keeps the set of rows within a window's height of the window (rootMargin: "100% 0px"), and reads the stop again when a row crosses that band's edge. syncRoving measures only those rows, and visibleRows, which the margin walk and the Page Map's hand-back read, filters to them before measuring. A row is drawn at tabindex -1, so moving the stop rewrites the row it leaves and the row it reaches rather than every row. With no row in view the stop is still the row nearest the window, which measures every row, as before.

The band is wider than the window because the observer reports a crossing only after the frame that moved the row. With a band no wider than the window, the frame that drew a scroll up read the stop without the rows the scroll brought in at the top, and left it on a lower row for a frame or two: in review, Shift+Tab 16 ms after a wheel step up landed below the highest row in view 6 times in 7 in Chromium. With the margin, the scroll's own frame finds them, for any scroll of up to a window between reports.

Evidence

Chromium, uv run leaf-dev bench asks --sizes 8,64,256 --input scroll --read cpu --rounds 3 --base, CPU per wheel step:

8 64 256 exponent
main 1.7 ms 2.3 ms 3.5 ms 0.76
this PR 1.7 ms 2.3 ms 3.0 ms 0.61

Firefox, --browser firefox --rounds 3 --base: 2.2 / 2.7 / 5.0 ms on main, 2.3 / 2.7 / 3.5 ms on this PR. Firefox's readings vary more than Chromium's: a 2-round run of the same command read 2.5 / 2.8 / 5.2 ms on main and 2.3 / 3.4 / 5.6 ms here.

Profiled (--profile --rounds 2 --base, before the margin), time under syncRoving across the scroll steps: 3.2 → 22.4 ms from size 8 to 256 on main, 3.1 → 3.0 ms on this PR.

The growth left in a wheel step is outside the rail: reading-place.js capturePlace under version.js recordPlaces (12.6 → 20.9 ms across the profiled steps from size 8 to 256), and native style and layout time.

Tests

In tests/browser/margin/test_rail.py, each in Chromium and Firefox:

  • test_tab_enters_the_rail_at_the_row_the_window_shows Tabs into the rail after a scroll down, after a row is drawn in view, after a scroll back up, and from either side of a gap with no row in view. It passes on main, and fails when the observer no longer reads the stop again on a crossing, or no longer observes a row drawn after load. It also passed once in WebKit.
  • test_the_rail_s_tab_stop_moves_in_the_frame_that_draws_a_scroll scrolls up three rows and reads the stop in a task after the scroll's frame and before the next, where a key pressed straight after the scroll lands. It passed 3 of 3 runs on main and with the margin, and failed 3 of 3 without it.

Ran: tests/browser/margin/ files test_rail, test_page_map, test_entries, test_clusters, test_status, test_card_placement, test_pins, test_opening_threads, test_scrollers, test_card_reply; pnpm run test:runtime; the browser type check. test_margin_entry_tone_stays_distinct_from_control_and_agent_state fails locally on main's runtime and on this branch alike, before and after merging #6069.

Left as it was

  • With no row in view, each scroll still measures every row to find the one nearest the window. Keeping the nearest row on each side of the window would make that constant too, at the cost of a cache to keep current; a page with many rows and long stretches between them is the case that pays.
  • When the stop lands on a delivery status, it passes to the nearest row that acts, found among all rows' visibility (no geometry), as before.
  • A scroll of more than a window between the observer's reports, such as a jump to a heading, leaves the stop behind for a frame or two until the report arrives.

Part of #5194

…ops measuring every margin row

The rail's one Tab stop is its highest row in view. `syncRoving` found it on
every scroll by reading each margin row's visibility and box, three times over
(directly, inside `visibleRows`, and inside `holdTabStop`), so a wheel step's
work grew with the rows the margin holds.

An IntersectionObserver rooted at the document's window now keeps the set of
rows the window holds, and reads the stop again when a row crosses the window's
edge. `syncRoving` measures only those rows, and `visibleRows`, which the margin
walk and the Page Map's hand-back read, filters to them before measuring. A row
is drawn at tabindex -1, so moving the stop rewrites the row it leaves and the
row it reaches rather than every row. With no row in view the stop is still the
row nearest the window, which measures every row, as before.

Evidence, Chromium, `uv run leaf-dev bench asks --sizes 8,64,256 --input scroll
--read cpu --rounds 3 --base`: a wheel step's CPU at sizes 8 / 64 / 256 went
from 1.6 / 2.4 / 3.7 ms on base to 1.7 / 2.4 / 3.3 ms, growth exponent 0.71 to
0.61. Profiled (`--profile --rounds 2 --base`), time under `syncRoving` across
the scroll steps went from 3.2 / 22.4 ms at sizes 8 / 256 to 3.1 / 3.0 ms.
Firefox (`--browser firefox --rounds 2 --base`): 4.2 / 4.4 / 6.0 ms on base,
3.5 / 4.3 / 5.6 ms on head. The growth left is outside the rail: reading-place.js
`capturePlace` under version.js `recordPlaces` (12.6 to 20.9 ms across the
profiled steps from size 8 to 256), and native style and layout time.

`test_tab_enters_the_rail_at_the_row_the_window_shows`, in Chromium and
Firefox, Tabs into the rail after a scroll down, after a row is drawn in view,
after a scroll back up, and from either side of a gap with no row in view. It
passes on base, and fails when the observer no longer reads the stop again on
a crossing, or no longer observes a row drawn after load.
…s current in the frame that draws a scroll

The observer reports a row crossing its band after the frame that moved it, and
`syncRoving` reads the stop again in the frame after that. With the band no wider
than the window, the frame that drew a scroll up read the stop without the rows
that scroll brought in at the top, and left it on a lower row for a frame or
two: in review, Shift+Tab 16 ms after a wheel step up landed below the highest
row in view 6 times in 7 in Chromium, against 1 in 7 on main. A root margin of
the window's height above and below (`rootMargin: "100% 0px"`) puts those rows
in the set before the scroll, so the scroll's own frame finds them. A scroll of
more than a window between reports still waits for the observer.

`test_the_rail_s_tab_stop_moves_in_the_frame_that_draws_a_scroll` scrolls up three
rows and reads the stop in a task after the scroll's frame and before the next. In
Chromium and Firefox it passed 3 of 3 runs on main and with the margin, and failed
3 of 3 without it.

Chromium, `uv run leaf-dev bench asks --sizes 8,64,256 --input scroll --read cpu
--rounds 3 --base`: a wheel step's CPU at sizes 8 / 64 / 256 is 1.7 / 2.3 / 3.5 ms
on main and 1.7 / 2.3 / 3.0 ms here.
@max-sixty
max-sixty marked this pull request as ready for review November 15, 2026 20:31
@max-sixty
max-sixty merged commit 3b07903 into main Nov 15, 2026
6 checks passed
@max-sixty
max-sixty deleted the grind/rail-roving branch November 15, 2026 20:40
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