Repository navigation
Stop three costs that grew with the page: a root :has() rule, the anchor probe's restyle and view checks per click - #5282
Merged
Merged
Conversation
…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.
leaf-agent
approved these changes
Nov 4, 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.
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-sectionaskspage thatleaf-dev scalinggenerates.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 nowa-page, so the rule styled nothing. The Web Awesome patch inbuild/now deletes it fromthemes/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
anchorDropsTransformschecks once whetheranchor()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'sfirstLineread on the first hover. Averaged over the scaling run's 30 wheel steps, that one stall was the 6 ms per step charged tofirstLine. The pair now stands in a fixed box withcontain: 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_viewshad 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, somatches_viewinpage stateis 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 --checkreproduces the committed kernel and vendor files, andpnpm run test:runtimepasses. The focused browser tests on heading links, on anchors under transforms in Chromium, Firefox and WebKit, and on the user view pass, excepttest_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.