Repository navigation
Skip the shift watch's per-node reading on unchanged frames - #1951
Merged
Merged
Conversation
The layout-shift sensor read every node of a watched page on every frame, even when nothing had changed: an idle page with 400 paragraphs spent a whole core on it. A reading only appends where a node's reading differs from its last, so a frame on which nothing could have changed now keeps the last complete reading. Every passive verdict starts from a layout-shift entry, and an entry, whether the observer hears it or a paint checkpoint takes it, now makes the reading that judges it complete: it marks the next reading full, and reads the entry's paint itself where the following frame kept an unchanged reading. A held frame's poses date from the complete reading they repeat, so a comparison from it can admit the shift. Whether a shift without input is found therefore no longer depends on a list of change sources. Between entries, a frame reads completely when something was announced since the last complete reading: DOM writes in every tree, running or changed animations anywhere in the composed tree (the document's own getAnimations() leaves out shadow trees, so readMotion and begun() now read each shadow root too), input/focus/scroll/drag/resize/load/reset/ beforetoggle events, emulated media, the frame's own visibility, and the calls that restyle without a DOM write (custom states, constructed and adopted sheets, form-control values and setRangeText, animation mutators); and on the frame after, since native anchoring follows its scroller a frame late. The audit skips comparing two frames between which no pose was appended. The gate checks itself: every 30th unannounced frame, and the first once the fixture asks for the verdict, reads completely and fails the test where any reading differs, in one line naming the innermost changed node and counting the rest. New sensor tests fail without each piece: the shadow-tree enumeration, the entry-driven complete reading, the end-of-test check, and the reset and setRangeText announcements. Results, on the sensor tests, words watch, send placement, margin, chrome contracts, aim, widgets, controls, threads, drafts, navigation and drawing (about 1,970 tests): 1957 passed, and every failure also fails on the base sensor, apart from the two new self-check tests, which need the check. With the check on every frame, the same sample reported no missed change. Idle watched page, script seconds per second (CDP ScriptDuration), base -> new: 10 paragraphs: 0.26 -> 0.021 100 paragraphs: 0.43 -> 0.025 400 paragraphs: 0.99 -> 0.041 test_the_catalog_sidenote_can_be_aimed_whole under 4x CPU throttling, interleaved runs: base 8.3/8.8/8.5/8.4 s, new 7.6/7.8/7.8/8.9 s (mean 8.5 -> 8.0 s). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
previously approved these changes
Oct 7, 2026
leaf-agent
reviewed
Oct 7, 2026
leaf-agent
left a comment
Collaborator
There was a problem hiding this comment.
The full test job is red on this head: the clean test_real_floating_plane_retains_local_motion[-passive-page] case reports the holder and field as moving without input, and five clean test_observed_attachment_credits_only_the_measured_scroll_placement cases report the same false shift after scrolling. These are the ownership paths whose frame readings this change now holds and reuses. The focused local rerun passed, so the failure is sensitive to scheduling; the changed frame and observer path needs to preserve their scroll and placement credit in the full suite before this can merge.
leaf-agent
dismissed
their stale review
October 7, 2026 02:49
CI failed on clean shift-watch scroll and floating-placement cases.
… samples Dating a held frame from the complete reading it repeated (readFrom) looked back past the floating and animation samples the paint checkpoint had already retired, so after an idle stretch a credited floating or observed-attachment move lost its credit and read as moved without input. CI failed five observed-attachment cases and the floating-plane case this way. A held frame now keeps its own time, as the base sensor does; readFrom had no test that needed it. Both tests now idle 60 frames under 6x CPU throttling first (held_stretch), which fails the previous commit 3 of 3 and passes base, the first commit and this one. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
previously approved these changes
Oct 7, 2026
test_the_banner_reads_in_one_order_at_every_width compares readings taken at two widths, and the version label's relative age ticked from 7m to 8m between them on CI, failing an order assertion over a clock. BANNER_ORDER now drops the trailing age from each control's name. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
approved these changes
Oct 7, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 5, 2026
…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
added a commit
that referenced
this pull request
Nov 5, 2026
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 #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; #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_ --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
An idle watched test page now costs almost nothing in the layout-shift sensor (
tests/shift_watch.js). It still catches every shift it caught before, plus a few it missed.Why
The sensor read every node of a watched page on every animation frame, even when nothing had changed. Measured with CDP
ScriptDurationon an idle page, it cost 0.26 s of script per second at 10 paragraphs, 0.43 at 100 and 0.99 at 400 — a whole core while the page sat idle. On CI's few cores, every watched test page competes with Chrome's compositor for that time.What changed
resetandbeforetoggleevents;setRangeText, animation mutators.takeRecords()takes it. The list keeps readings between entries current, which input ownership and typing verdicts use.readMotionandbegun()also read each shadow root's animations, whichdocument.getAnimations()leaves out. That gap was already on main.Measurements
Idle watched page, script seconds per second:
A typing test under 4x CPU throttling, runs interleaved: mean 8.5 s → 8.0 s.
Tests
New sensor tests each fail without the piece they cover:
an_unchanged_frame_misses_no_restyle: a shadow transition, a form reset andsetRangeTexta_shift_is_judged_on_complete_readings: a rule change no announcement coversthe_verdict_checks_a_change_the_test_ends_onAbout 1,970 watched tests ran: shift watch, words watch, send placement, margin, chrome contracts, aim, widgets, controls, threads, drafts, navigation and drawing. Every failure also fails with the base sensor; the exceptions are the two new self-check tests, which the base sensor cannot pass. With the self-check on every frame (
VERIFY = 1), the same sample reported no missed change.Also in this PR
BANNER_ORDERdrops the version's relative age.test_the_banner_reads_in_one_order_at_every_widthfailed on CI when that age ticked from 7m to 8m between its two readings.Known limit
Review raised one unreproduced case. When the frame after an entry kept an unchanged reading, the entry reads the page as it stands now. If an announced frame landed in between and made a move Chrome reports no shift for, such as a transform-only write, that move would fall into this entry's comparison. The case didn't reproduce in 48 runs, including at 8x CPU throttling. One possible bound would end the window at the first complete frame after the entry.