Repository navigation
Find the rail's Tab stop among the rows in the window, so a scroll stops measuring every margin row - #6065
Merged
Conversation
…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
marked this pull request as ready for review
November 15, 2026 20:31
leaf-agent
approved these changes
Nov 15, 2026
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.
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, insidevisibleRows, and insideholdTabStop), 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.syncRovingmeasures only those rows, andvisibleRows, 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: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 undersyncRovingacross 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
capturePlaceunder version.jsrecordPlaces(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_showsTabs 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_scrollscrolls 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/filestest_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_statefails locally on main's runtime and on this branch alike, before and after merging #6069.Left as it was
Part of #5194