Repository navigation
Description
On a page whose words change every frame, such as a live counter, the margin lays out every one of its rows on each frame. An agent session working on hover previews measured this in Chromium with 80 pointer moves beside a counter whose textContent is reset every frame: about 5 ms per move with 32 marks and 16 ms with 512, against 0.46–0.59 ms with no counter. A CPU profile put the time in layoutMarginRows. That was on the thread-previews branch on Nov 6, since landed as #5618. #5623 has since made moving a row restyle only that row, so the per-frame cost may be lower now; I haven't re-measured on 6a62560e2. What still holds on main, from the code below, is that each such change lays out every row. Root AGENTS.md, "Responsiveness", asks that a hover cost the same on a page of ten sections as of five hundred, and that a keystroke and a wheel step each fit in 8 ms on the largest page leaf-dev bench generates.
The same full pass runs for any attribute write a page script makes to a box's style, class, hidden or open. heardPage (margin-layout.js:686-692) calls layoutMarginRows after the script for every style, class, hidden or open change anywhere outside Leaf's surfaces, such as a class toggled on <html>, and for any child-list change on a box in the watched geometry. That geometry is every row target's ancestors plus all their siblings (lines 1610-1632), so a counter beside any marked section is in it, and the size observer over the same set calls the same pass on any resize (line 620). The pass itself walks every row and re-reads each target's chain (layoutMountedRows), so each of these changes costs a pass proportional to the rows the margin holds, however little it moved.
Unconfirmed: that session also reported that tracking the margin entry under the pointer takes 0.3 ms at 32 entries and 4.8 ms at 512. I couldn't find the measurement behind those numbers, so they need re-measuring before anything is built on them.
A fix likely has each change say which rows it can move, as "Responsiveness" asks of work a pass would redo for the whole page ("which its owner records when the change happens"): a text, child-list or attribute change, or a box's resize, can move only the rows whose targets stand in or after that box in its lane, and the pass lays out those rows rather than every row. #5194's fourth cost, repeated layoutMarginRows while scrolling a page with threads, comes from the same whole-margin pass and would likely shrink with the same change. A leaf-dev bench page with words that change every frame would show the growth in its readings.
This was written by Claude Code on behalf of max-sixty
Activity
Stop every focus move restyling the page in Chromium (#5844)
Bench opening a diff line's comment box on a page of n asks (#5864)
Stop measurement ranges slowing every DOM write on a long page, paint…
Draw a sent comment and a Resolve before the server's reading on a lo…