Skip to content

Stop three costs that grew with the page: a root :has() rule, the anchor probe's restyle and view checks per click - #5282

Merged
max-sixty merged 4 commits into
mainfrom
agent-a548dd316a2d6c9b1
Nov 4, 2026
Merged

max-sixty merged 4 commits into
mainfrom
agent-a548dd316a2d6c9b1

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Three costs on large pages grew with the page's size: a style pass after every node added or removed, a stall on the first heading hover, and a walk of the whole page after every click. They broke the tightened large-page rule in root AGENTS.md, "Responsiveness", which says an input's work depends on what it changes and on what the window shows, not on how much the page holds. Each commit takes one away. All measurements are on the 512-section asks page that leaf-dev scaling generates.

Drop Web Awesome's :is(html, body):has(wa-page)

Chromium answers a :has() on the root by matching its argument across the whole document after each insertion or removal anywhere below it. Adding a fixed div to the chrome and removing it again cost 17 ms of forced style with this rule and 3 ms without it, with Leaf's own root :has() rule removed in both readings. Leaf draws no wa-page, so the rule styled nothing. The Web Awesome patch in build/ now deletes it from themes/default.css, and the build regenerates the theme. The lock's patch hash moves with it, which renames one vendored chunk whose content is identical.

Hold the anchor-transform probe in a box with layout containment

anchorDropsTransforms checks once whether anchor() includes transforms, which Firefox's doesn't. It anchored one fixed box to another in the chrome, and removing the pair made Chromium restyle every anchored element on the page: a trace showed a style pass over 20,209 elements taking 209 ms, forced by the heading link's firstLine read on the first hover. Averaged over the scaling run's 30 wheel steps, that one stall was the 6 ms per step charged to firstLine. The pair now stands in a fixed box with contain: layout, which becomes their containing block. In one probe the first hover took 618 ms on main and 11 ms here. Later hovers cost 2 to 9 ms at both 64 and 512 sections. The check's answer is unchanged in both engines (8 px in Chromium, 0 in Firefox).

Read the view checks for a new revision, window or scheme, not each event

The checks that the agent reads in user_views had the log position in their basis, so every event a click posted re-read every check across the page 300 ms later: 31 ms per click. Now a new revision, a resized window or a scheme change re-reads them at once. A state change, such as a picked option, reaches them at the heartbeat, which re-reads them every 10 s while the page shows, as it already did for a disclosure the user opens. Each reading keeps the log position it was read at, so matches_view in page state is false for up to 10 s after a click, while the checks lag the log. Recording the posts the page sends shows main re-reading the checks after each of three clicks, and this branch keeping the reading taken at load. The heartbeat's reading is still a walk of the whole page, about 110 ms at 512 sections under the profiler.

Checks

node build/browser/build.mjs --check reproduces the committed kernel and vendor files, and pnpm run test:runtime passes. The focused browser tests on heading links, on anchors under transforms in Chromium, Firefox and WebKit, and on the user view pass, except test_a_heading_copies_the_link_to_the_section_it_opens, which fails the same way on main: it waits for a command-reference button that never appears.

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

…heme

Every node added to or removed from the page cost a style pass that grew
with the page. Chromium answers a `:has()` on the root by matching its
argument across the whole document after each insertion or removal
anywhere below it. On the 512-section `asks` page of `leaf-dev scaling`, a
fixed div appended to the chrome and removed again cost 17 ms of forced
style work with this rule and 3 ms without it, with Leaf's own
`html:has(...)` rule removed in both readings. Leaf draws no `wa-page`, so
the rule styled nothing.

The Web Awesome patch now deletes the rule from `themes/default.css`, and
the build regenerates the theme. The lock's patch hash moves with it, which
renames one vendored Web Awesome chunk whose content is unchanged.

Leaf's own `html:has(.lf-margin-preview leaf-text:focus-within, ...)` in
annotation-chrome.css costs the same on every mutation and is still there.
The first heading link a page showed froze the page while Chromium
restyled every anchored element in it. `anchorDropsTransforms` learns once
whether `anchor()` leaves out transforms, as Firefox's does, by anchoring
one fixed box to another in the chrome. Removing that pair from the
window's containing block restyled every element with an anchor: on the
512-section `asks` page of `leaf-dev scaling`, a style pass over 20,209
elements took 209 ms, forced by the heading link's `firstLine` read on the
first hover. That one stall averaged 6 to 7 ms over the run's 30 wheel
steps, and the scaling run charged it to `firstLine`.

The pair now stands in a fixed box with `contain: layout`, which becomes
their containing block, so their anchoring stays inside it. Removing it
cost 7 to 10 ms in the same probe on that page, the price of any node
added to and removed from the chrome there. The reading is unchanged:
8 px in Chromium and 0 in Firefox.
…vent

Every click on a large page walked the whole page again for the view checks
the agent reads in `user_views`. The checks' basis held the log position,
so each event the user's gesture posted re-read every check 300 ms later:
31 ms per click on the 512-section `asks` page of `leaf-dev scaling`.

The checks measure layout, and a state change reaches them as a
disclosure the user opens already did: at the heartbeat, which re-reads
them every 10 s while the page shows. A new revision, a resized window or
a scheme change still re-reads them at once. Each reading keeps the log
position it was read at, so `matches_view` in `page state` is false while
the checks lag the log.

The heartbeat's reading is still a walk of the whole page, about 110 ms at
512 sections under the profiler, every 10 s.
@max-sixty
max-sixty merged commit 36b230d into main Nov 4, 2026
5 checks passed
@max-sixty
max-sixty deleted the agent-a548dd316a2d6c9b1 branch November 4, 2026 05:13
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