Repository navigation
Leave boxes in skipped content out of reach and the geometry readings - #1340
Conversation
reachScrollers called getComputedStyle on every element in its scope. That meant 8k calls on a corpus revision, and it forced style recalculation of every hidden tab panel (`hidden="until-found"`, which is content-visibility: hidden) and every closed disclosure's content, because any question about a box in skipped content makes the browser style that whole subtree. In the revision profile the sweep took ~120 ms, ~100 of it 66 forced recalculations of 1–4k elements each. Two changes, each aimed at one of those costs: - Candidates come from the stylesheets in force. Every style rule in a sheet the tree reads that declares an overflow able to scroll contributes its selector. The sheets are the document's or a shadow root's, both linked and adopted, and the walk goes through @media, @layer, @import, and nesting (`&` resolves to `:is(parent)`). One forgiving `:is()` query then returns a few hundred candidates out of ten thousand elements. Declarations count as scrolling when they say auto/scroll, when they set `hidden` on one axis (the other axis's `visible` then computes to `auto`), or when they hold `var()` in a longhand or the shorthand. The query also always matches the scrollers from the UA sheet (popovers, dialogs), inline styles, and shadow hosts. Computed style still decides, on candidates only. - A candidate that `checkVisibility()` reports unrendered is not asked. It waits in `unrendered`, watched by the existing size observer, and is reached when it first has a box: a tab chosen, a disclosure opened. paintReach likewise leaves an unrendered box as it was, since measuring it would force the same recalculation. I considered and passed over two alternatives. One was having each owner declare its scrollers through reachReadingScroller's door. That would put a second home beside each of ~36 overflow rules in 10 stylesheets, and a page's own CSS would be left uncovered. The other was sweeping once per revision and reusing the result: that still pays the whole cost at startup and on every revision. Measured with scripts/profile_page.py on the corpus, base origin/main vs head, 3 runs each, on a heavily loaded shared machine (so read proportions): - revision: reachScrollers inclusive ~158 ms/run -> ~21 ms/run. The remaining time is mostly the layout checkVisibility forces, which paintReach needed anyway. - move: the thread panel's pass (prepareFrozenWidgets) ~5.2 ms/run with 6–7 forced recalcs -> ~2 ms/run with 1. Total style time per revision is unchanged (base 170–250 ms, head 159–201 ms). The same hidden-panel recalculations now land in margin code that also asks about boxes in skipped content (margin-projection renderNow's Page Map positions, margin-layout settleResidency, geometry shownParts), so the end-to-end saving waits on those callers. Paired one_transition timings were too noisy under the machine's load (load average 30–70) to read. Tests: test_a_scroller_the_page_styled_is_reached_whatever_rule_made_it adds a page whose own CSS makes boxes scroll through each rule shape the query reads, plus one in a closed disclosure that is reached once opened. Removing nesting resolution, at-rule recursion, the one-axis rule, the var() case, or the reveal pass each fails it. lf-code's comment no longer claims the pass cannot see into shadow trees. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… do without them Once reach stopped asking about boxes in hidden tab panels, total style time per revision stayed where it was. The same forced recalculations moved to whichever reader next asked about a box in skipped content. Any question about such a box (its computed style, its rect, its scroll offsets) makes the browser style and lay out the whole skipped subtree first. The readers that asked were captureCarry's scroll offsets, the Page Map's spoken positions (renderNow), settleResidency's aside styles, layoutMarginRows' anchors, and the sidenote rects. Each hidden corpus example is a 1–4k-element panel, and all of them were forced on every revision. geometry.js now owns the rule as `skipped(el)`: whether el stands in content the browser skips, meaning a `content-visibility: hidden` box's content (which is what a `hidden="until-found"` panel is) or a closed disclosure's content. It answers without forcing anything. `checkVisibility` says whether el is drawn. When it is not, the nearest drawn ancestor says why: a skipping box, or display: none/contents on the way down. That ancestor is drawn, so reading its style is cheap. Callers that have nothing to say about a box on no screen ask this first: - reach: a skipped candidate waits, observed, and is classified once it is drawn. - layoutMarginRows: a row whose target is skipped is withheld, like one whose target has gone, and is anchored by the pass that runs once the target is drawn. Sidenotes in skipped content no longer take room. - Page Map positions: a skipped target has no "percent down". - settleResidency: an aside in skipped content takes no room. It already got none; now the pass also stops asking for its style. - captureCarry: a box in skipped content carries no scroll offset across a revision. This is the one behaviour that changed: a code block scrolled sideways in a tab the user has left, and then replaced by a revision, comes back at offset 0. anchor-paint still asks targetParts about element anchors in hidden content, because the outline class has to be in place before the tab is revealed. That is one small forced pass per revision (836 elements on the corpus). Measured with scripts/profile_page.py on the corpus, base origin/main vs this branch, 3 runs each, taken back to back: - revision: style 157–318 ms -> 23–25 ms per run; renderer main-thread CPU over the recording 759–1206 ms -> 667–799 ms. - move: style 25–28 ms -> 9–10 ms per run; input-to-paint window 108 -> 84 ms median (under tracing). Revealing each corpus tab in turn shows the same margin rows as base (.tmp probe, per-tab shown/total identical). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The stylesheet walk misses scrollers declared with :scope inside @scope. For example, Chromium applies @scope (.outer) { :scope > .box { overflow-x: auto } } to a wide .box, but the nested rule's selectorText is :scope > .box; document.querySelectorAll(':is(:scope > .box)') returns no candidates. Such a page-authored scroller loses the tab stop and continuation marks that reachScrollers promises. The candidate query needs to preserve the scope root (or conservatively include these rules) before this can cover page CSS generally.
A rule nested in `@scope (.outer) { :scope > .box { overflow-x: auto } }` serializes
its selector as `:scope > .box`, which a document query can't match. So the
page-authored scroller it makes never got a tab stop or continuation marks. The
walk now substitutes the scope's root selector for `:scope`, and for `&` directly
inside the scope. It leaves the scope's limit out, which gives a superset that the
computed style narrows. The styled-scrollers test gains a scoped box, and removing
the substitution fails it.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
On a corpus move on current main, walking every sheet's rules on each reachScrollers call cost the thread panel's pass (~3.5 ms of ~5 ms per run) about as much as the element sweep it replaced. No sheet's rules change in place: the layer's constructed sheets are built once, and a <style> or <link> whose text changes is a new sheet object. So the selectors each sheet contributes are memoized per sheet in a WeakMap. The thread panel's pass on a move drops to ~1.6 ms per run (base 4.5 ms). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The @scope fix still misses nested scopes whose root is relative to the enclosing scope. For @scope (.outer) { @scope (:scope > .inner) { :scope > .box { overflow-x: auto } } }, Chromium applies overflow-x: auto to .box, but this walk substitutes the inner root literally and queries :is(:is(:scope > .inner) > .box) from the document, which matches nothing. That leaves a page-authored scroller without its tab stop and continuation marks. Resolve each scope root against its enclosing scope before using it to replace the leaf rule's :scope, and cover this case in the browser test.
In `@scope (.outer) { @scope (:scope > .inner) { :scope > .box { ... } } }`, the
inner root is relative to the outer one. Substituting it literally gave a query
that matched nothing. Each scope's root is now resolved against its enclosing
scope and parent, the same way a style rule's selector is, and the
styled-scrollers test gains a box in a nested scope.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The new browser test makes the test job fail: test_the_resources_a_fixture_owns_are_taken_from_that_fixture reports test_render_gate.py:3284 page.close() — the browser fixture does (CI run). The test's own assertion passes, but the fixture owns that page's teardown; the inline suggestion removes the extra close.
CI failed — the added browser test closes a fixture-owned page.
The fixture owns closing pages it opens (test_interact_layer's ownership check). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ing stylesheets The stylesheet reader reinterpreted CSS: it rewrote `&` and `:scope` as strings and special-cased @import, @scope, nesting, var(), popovers, dialogs, inline styles and shadow hosts. Any rule shape it misread would silently drop a keyboard stop. The measurements showed the cost it removed was never the element walk. It was the forced styling of skipped content. So reach walks every element again with a TreeWalker, and rejects the subtree at the first box that `skipped` (in geometry.js) reports. That box waits, watched by the size observer, and is swept once it is drawn. Profiled on the corpus against the stylesheet version, 3 runs each (scripts/profile_page.py): - revision: reachScrollers ~16.5 ms/run vs ~17.5 ms; style per run 24–31 ms vs 27–29 ms. - move: the thread panel's pass ~2.4 and ~3.0 ms/run vs ~1.1 and ~1.9 ms, over two rounds, so about 1 ms slower. Paired one_transition medians (stylesheet arm, then pruned) were within noise: move 59/64 and 73/63 ms, revision 1962/1689 ms. The styled-scrollers test existed only to exercise the stylesheet reader's rule shapes. It is replaced by one box a page's CSS makes scroll inside a closed disclosure, which must get its tab stop, holds mark and sideways paint once it opens. Removing the reveal sweep fails it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…lane The disclosure test passed on base too, because base gave the box its stop ahead of time. The test now covers both skipped shapes, a closed disclosure and an lf-tab panel not chosen. In each it asserts that the box carries no holds mark before it is shown, and every mark it is owed after. Walking into skipped content fails both cases, and so does dropping the reveal sweep. A row whose target is skipped now keeps the lane it stands in instead of moving to the root lane. Before, a row in a reading region's hidden panel moved between lanes on every tab switch. reach's walk filter drops its checkVisibility() call, which only repeated skipped()'s first line. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # skills/leaf/assets/runtime/carry.js
) Activating a revision took every authored attribute, class token and inline declaration off `html` and `body` and put the arriving revision's back on, including the ones both revisions write. A class taken off `body` and put back restyles the whole document, so every corpus revision paid a full restyle for attributes that hadn't changed. This came out of re-profiling revisions after the recent performance PRs (#1321, #1324, #1334). `replaceAuthoredAttributes` now takes off only what the outgoing revision wrote and the arriving one doesn't, and writes only what differs, through the layer's identical-write rule (`keeps`). Declarations are compared by name, so an empty custom property (`--x: ;`, which reads back as `""`) stays, and a newly declared empty one is written as the single space that parses to it, since `setProperty` with `""` removes; the old code dropped both. Runtime-owned attributes and inline properties survive, as before; the existing live-revision test covers adding, retiring and the runtime-owned `--lf-thread-panel-width`. Measured on the corpus with `scripts/profile_page.py corpus revision` (3 runs each, current main, load ~20): | | main | this branch | |---|---|---| | style per revision | 149.5 ms | 54.6 ms | | install task | 313–357 ms | 160–188 ms | Most of what's left in that task is `reachScrollers`, which #1340 takes down separately; the two together bring style per revision to about 15 ms. New test: a revision that changes only the title makes no authored attribute write on either root. It fails on the old code. > _This was written by Claude Code on behalf of max-sixty_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
On a corpus revision,
reachScrollerswas the largest self-time function in the profile (~120 ms). Almost none of that was the walk over ~8k elements. It was forced style recalculation: 66 passes of 1–4k elements each. The corpus keeps each example in a hidden tab panel (hidden="until-found", which iscontent-visibility: hidden). The browser leaves that content unstyled, and any question about a box inside it (computed style, rect, scroll offsets) makes the browser style and lay out the whole panel first. Stopping reach from asking didn't reduce total style time. The same passes moved to the next readers that asked about boxes in hidden panels: captureCarry, the Page Map positions, settleResidency, and layoutMarginRows. So this PR fixes the rule once, where geometry lives, and routes every such reader through it.skipped(el)in geometry.js. It says whetherelstands in content the browser skips (acontent-visibility: hiddenbox's content, or a closed disclosure's) without forcing anything.checkVisibilitysays whetherelis drawn. When it isn't, the nearest drawn ancestor says why, and reading that ancestor's style is cheap. The readers that have nothing to say about a box on no screen ask it first:reach otherwise still sweeps every element and asks its computed style, so a scroller made by any rule (theme, package, runtime chrome or the page's own CSS) is found with nothing declared. An earlier revision of this PR found candidates by reading the stylesheets instead. It measured about the same on a revision and ~1 ms faster per move, but it amounted to a second CSS interpreter (selector rewriting, special cases for @scope, nesting, var(), popovers and so on), and any rule shape it misread would silently lose a keyboard stop. So it is gone.
Measured on the corpus with
scripts/profile_page.py, 3 runs each, baseorigin/mainvs this branch, both after merging main:reachScrollersinclusive per runreachScrollers(prepareFrozenWidgets) per runone_transitionrevision, 8 runs (head faster in 7)The pruned sweep against the stylesheet reader, also 3 runs each: revision
reachScrollers~16.5 vs ~17.5 ms/run, and revision style 24–31 vs 27–29 ms. On a move the pruned sweep is about 1 ms slower (2.4/3.0 vs 1.1/1.9 ms/run over two rounds). The paired medians were within noise (move 64/59 and 63/73 ms, revision 1689/1962 ms). Other suites loaded the machine throughout (load average 15–40), so read the wall-time rows loosely.What changed for the user:
The one remaining forced pass on a revision is anchor-paint's
targetPartsfor element anchors in hidden content (836 elements on the corpus). The outline class has to be in place before a tab is revealed, so it still pays.Tests:
test_a_hidden_scroller_is_reached_once_it_is_shown, with two cases: a box the page's CSS makes scroll inside a closed disclosure, and one inside an lf-tab panel not chosen. Each must carry no holds mark before it is shown, and its tab stop, holds mark and sideways paint after. Walking into skipped content fails both cases, and so does dropping the reveal sweep.npm run test:runtime.origin/main's runtime too, and green in this PR's CI:test_an_acknowledgment_uses_status_until_an_active_claim_restores_a_disclosure,test_a_thread_waiting_on_the_user_colors_its_margin_entry, andtest_visual_review_gallery_gives_a_laptop_to_the_evidence.🤖 Generated with Claude Code