Skip to content

Stop the shift watch reading content the browser skips - #5540

Merged
max-sixty merged 2 commits into
mainfrom
grind/gallery-test-time
Nov 5, 2026
Merged

max-sixty merged 2 commits into
mainfrom
grind/gallery-test-time

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

The suite's shift watch (tests/shift_watch.js) no longer reads content the browser skips: a shut tab's panel, a closed disclosure's content, the contents of an off-screen content-visibility: auto box. On the feature gallery that cuts the watch's cost of opening the page by more than half, and every watched test whose page holds shut tabs or folds pays less on each frame it changes. This is the sensor half of what #5522 asks of the longest tests; the other half is the page's own load, below.

Where a gallery test's time goes

Measured on this Mac (one-minute load 6–25 from other sessions), Chromium headless shell, 1200×900, reduced motion, opening the gallery and waiting for wait_until_ready, three interleaved rounds per arm:

Arm Time to ready The shift watch's complete readings
browser.unwatched (the page's own work) 7.0–8.4 s none
browser, the watch as on main 13.6–16.1 s 85–99 readings of 5,913 nodes, 6.8–8.5 s
browser, this branch 9.5–10.9 s 92–94 readings of at most 2,923 nodes, 3.1 s

All of the sensors' cost was the shift watch's complete reading. On each frame after an announced change, read() asked every node for its rect, about fifteen computed-style properties, its visibility and its ancestry, at about 14 µs a node; a CPU profile of a watched load put 8.7 s of its 14.9 s in the watch's frame callback, 7.5 s of it in read(). About 3,700 of the gallery's 5,913 nodes stand in skipped content, nearly all in shut tabs. The runtime's own readings already leave skipped content out (skipped), because asking about it makes Chrome style and lay out the whole skipped subtree first.

The page's own 7–8 s is mostly its 16 live samples: the page presents at about 1.6 s, the samples report ready one after another from about 2.6 s to 6.7–7.6 s, and the page is ready within 0.1 s of the last.

Of the long gallery tests on CI's daily run, only test_the_feature_gallery_exercises_its_core_journeys runs the shift watch; test_render_gate.py, test_render_pages.py and test_render_anchors.py are marked shifts_unsurveyed. Call seconds, -n0, base and this branch interleaved over two rounds, then once each with the shift watch removed and with every sensor removed (a scratch switch in watched, not committed):

Test main This branch No shift watch No sensors
test_the_feature_gallery_exercises_its_core_journeys 63, 63 43, 44 19 20
test_page_fixture_renders[feature-gallery] 110, 115 116, 110 109 113
test_an_anchor_written_from_the_mapped_revision_lands_on_the_page[feature-gallery] 25, 24 25, 24 23 24
test_real_page_passages_can_be_quoted[feature-gallery] 24, 22 25, 22 22 23

test_page_fixture_renders[feature-gallery] spends about 55 s of its 110 s here in seven wait_until_ready calls, about 8 s per gallery load, and the rest in its journeys' own probes; on CI's daily runs of November 4 and 5 those seven calls took 292 s and 327 s. So for that test, the longest on CI after the Firefox sweep, the cost is the page's own load, chiefly its live samples, rather than the sensors.

The change

  • everything(), the population of a complete reading, leaves out nodes in skipped content. A node the last reading read while it was drawn gets one more reading, the one that sees it go. Without it, a fold that shrinks to nothing and moves into a closed <details> in one task, as a settled thread does into history, lost the flow credit for the control its shrinking carried, and all six cases of test_fold_reparenting_keeps_only_its_original_flow_credit failed. Content is read again from the frame it is drawn; what reveals it, or makes the browser stop drawing it without a scroll, is a DOM write or a contentvisibilityautostatechange, both of which the watch has announced since Skip the shift watch's per-node reading on unchanged frames #1951 (the header's list of announcements now names the second).
  • A layout-shift entry taken at a paint checkpoint now records held, the population the reading at that time covers, rather than asking everything() again right after read(): the second call left out the nodes read() had just taken a departure reading of, so a content-visibility: auto box carried off screen without input could go unjudged on that path. No control exercises that path with a departure; the change follows from what the population means.
  • test_a_control_drawn_out_of_skipped_content_is_watched holds that a control drawn out of a closed disclosure, a hidden-until-found panel or an off-screen content-visibility: auto box, then moved by script, is still reported. With revealed content never read again, all three cases fail.
  • test_a_box_the_browser_stops_drawing_without_a_scroll_leaves_no_stale_reading pushes a drawn content-visibility: auto box past the browser's drawing margin with a write above it, so no scroll announces the change. Without the contentvisibilityautostatechange announcement the verdict's own complete reading reports "shift watch missed a change to the page's nodes (population)" in 5 runs of 5; with it, 5 of 5 pass.
  • skipper and skipped move from shown-box.js to shadow-tree.js, which imports nothing (.dependency-cruiser.mjs holds it to that), so the sensor bundles the runtime's own rule. shown-box.js imports rendering.js, whose dependencies run code at load, so it can't go into an init script. Every importer names the new home, and browser/AGENTS.md gains the owner's row.
  • notes/shift-watch-cost.md records the findings (about 14 µs a node per complete reading; most of the gallery's own time to ready is its live samples arriving), the leaf-dev probe command that reproduces the gallery's presented and settled times, and the open design below. skipper stays in shadow-tree.js beside excludedByInert and nativeLayerHolding, which also ask the browser about state along the rendered ancestry; a module of its own would add a file and move every importer again.

Checks run

  • uv run pytest tests/browser/test_render_shift_watch.py tests/journeys/test_render_shift_watch.py tests/browser/test_render_words_watch.py tests/browser/test_render_swap_watch.py tests/browser/test_render_write_watch.py tests/browser/test_page_layout_shifts.py tests/journeys/test_page_layout_shifts.py -n 4, plus the watched gallery journey: 466 passed. The sensors' controls (a real shift, lost typed words, a swap, a needless write) still fail where they should.
  • The sensor suites with VERIFY = 1, which checks every frame for an unannounced change: 459 passed; the four gallery tests above also passed with it before the review follow-up.
  • The watched browser and smoke files whose pages hold tabs, disclosures, text documents or samples (18 files, 302 tests): 11 failures and 3 errors across 11 tests, the same set with main's watch and with this one; 8 of those 11 tests also fail on CI's November 5 daily run.
  • pnpm run test:runtime (820 passed) and pnpm run check.

test_a_pressed_panel_control_keeps_its_face_and_takes_the_next_press[feature-gallery] fails on this Mac with main's watch and with this one alike ("Resolve thread" shows cursor: zoom-in while its gesture travels) and passes on CI's Linux runner, so it is left out of the comparison.

Not verified: the rest of tests/browser and tests/journeys, which run under this sensor; CI's push to main is the first run of them all with it.

What's left

  • The page's own load. Every live sample's child page starts as its sample mounts, below the window or not, and the page reads as arriving until the last has; on the gallery that is 16 Leaf runtimes and about 5 s of every load, which users on leaf.page pay too. Starting a child only as its sample nears the window would cut both, but changes when a sample's state is ready, so it is Max's call.
  • The reading still grows with the drawn page. A page that skips nothing, like the 512-section prose page leaf-dev scaling generates, gets nothing from this; Let the scaling journeys and the playground leave test pass on a machine ten times slower #5523 measured the sensors adding about 290 ms to a click there. Reading the full record only for nodes near the window, as the runtime's input work follows the window, would change what a verdict can look back to for a box that jumps into view, so it is in the note as a design for Max.

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

max-sixty and others added 2 commits November 5, 2026 12:10
The suite's shift watch read every node in the page on each frame after an announced
change: its rect, about fifteen computed-style properties, its visibility and its
ancestry, at about 14 µs a node. On the feature gallery that was 85-99 readings of
5,913 nodes per load, 6.8-8.5 s, which roughly doubled the page's own 7-8 s to ready.
About 3,700 of those nodes stand in skipped content, nearly all in shut tabs, and
`skipped`'s own comment records that asking about them makes Chrome style and lay out
those subtrees first.

A complete reading now leaves skipped content out, as the runtime's own readings do.
A node the last reading read while it was drawn gets one more reading, the one that
sees it go. Without it, a fold that shrinks and moves into a closed disclosure in one
task lost the flow credit for the control it carried, and all six cases of
`test_fold_reparenting_keeps_only_its_original_flow_credit` failed. A node is read
again from the frame it is drawn again; the new
`test_a_control_drawn_out_of_skipped_content_is_watched` holds that for a disclosure,
a hidden-until-found panel and a `content-visibility: auto` box, and fails in all
three cases if revealed content is never read again.

The sensor bundles the runtime's rule, so `skipper` and `skipped` move from
`shown-box.js`, whose `rendering.js` import runs code at load, to `shadow-tree.js`,
which imports nothing. Every importer names the new home.

On this Mac, interleaved: the gallery's load to ready went from 13.6-16.1 s to
9.5-10.9 s (7.0-8.4 s without sensors), and
`test_the_feature_gallery_exercises_its_core_journeys` from 63 s to 43-44 s (19 s
without the shift watch). The other long gallery tests don't run the shift watch
(`shifts_unsurveyed`) and are unchanged; `notes/shift-watch-cost.md` records where
their time goes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…est a box the browser stops drawing without a scroll

A layout-shift entry taken at a paint checkpoint read the page with `read()` and then
asked `everything()` for its population again. Since the population now depends on
which nodes the last reading read drawn, that second call left out every node
`read()` had just taken a departure reading of, so a `content-visibility: auto` box
carried off screen without input could go unjudged on that path. The observed
paint now records `held`, the population the reading at that time covers, whether
the reading was taken then or kept from the last complete one.

The departure rule also relies on `contentvisibilityautostatechange`, which the watch
has announced since #1951 but no test held: a scroll announces every other case.
`test_a_box_the_browser_stops_drawing_without_a_scroll_leaves_no_stale_reading`
pushes a drawn `content-visibility: auto` box past the browser's drawing margin
with a write above it. With the announcement it passes; without it, the verdict's own
complete reading reports "shift watch missed a change to the page's nodes
(population)", five runs of five each way.

The note keeps its findings and the probe command that reproduces the gallery's
presented and settled times, rather than the PR's tables.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@max-sixty
max-sixty marked this pull request as ready for review November 5, 2026 20:40
@max-sixty
max-sixty merged commit 94a0161 into main Nov 5, 2026
6 checks passed
@max-sixty
max-sixty deleted the grind/gallery-test-time branch November 5, 2026 20:51
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