Repository navigation
Stop the shift watch reading content the browser skips - #5540
Merged
Merged
Conversation
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
marked this pull request as ready for review
November 5, 2026 20:40
leaf-agent
approved these changes
Nov 5, 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 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-screencontent-visibility: autobox. 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:browser.unwatched(the page's own work)browser, the watch as onmainbrowser, this branchAll 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 inread(). 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_journeysruns the shift watch;test_render_gate.py,test_render_pages.pyandtest_render_anchors.pyare markedshifts_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 inwatched, not committed):maintest_the_feature_gallery_exercises_its_core_journeystest_page_fixture_renders[feature-gallery]test_an_anchor_written_from_the_mapped_revision_lands_on_the_page[feature-gallery]test_real_page_passages_can_be_quoted[feature-gallery]test_page_fixture_renders[feature-gallery]spends about 55 s of its 110 s here in sevenwait_until_readycalls, 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 oftest_fold_reparenting_keeps_only_its_original_flow_creditfailed. 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 acontentvisibilityautostatechange, 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).held, the population the reading at that time covers, rather than askingeverything()again right afterread(): the second call left out the nodesread()had just taken a departure reading of, so acontent-visibility: autobox 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_watchedholds that a control drawn out of a closed disclosure, a hidden-until-found panel or an off-screencontent-visibility: autobox, 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_readingpushes a drawncontent-visibility: autobox past the browser's drawing margin with a write above it, so no scroll announces the change. Without thecontentvisibilityautostatechangeannouncement 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.skipperandskippedmove fromshown-box.jstoshadow-tree.js, which imports nothing (.dependency-cruiser.mjsholds it to that), so the sensor bundles the runtime's own rule.shown-box.jsimportsrendering.js, whose dependencies run code at load, so it can't go into an init script. Every importer names the new home, andbrowser/AGENTS.mdgains the owner's row.notes/shift-watch-cost.mdrecords the findings (about 14 µs a node per complete reading; most of the gallery's own time to ready is its live samples arriving), theleaf-dev probecommand that reproduces the gallery's presented and settled times, and the open design below.skipperstays inshadow-tree.jsbesideexcludedByInertandnativeLayerHolding, 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.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.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) andpnpm run check.test_a_pressed_panel_control_keeps_its_face_and_takes_the_next_press[feature-gallery]fails on this Mac withmain's watch and with this one alike ("Resolve thread" showscursor: zoom-inwhile its gesture travels) and passes on CI's Linux runner, so it is left out of the comparison.Not verified: the rest of
tests/browserandtests/journeys, which run under this sensor; CI's push tomainis the first run of them all with it.What's left
leaf-dev scalinggenerates, 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.