Skip to content

A change to the page's words or styles lays out only the margin rows it can move #5752

Closed

Description

@max-sixty

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

  1. added
    backlog
    etc
    ux
    on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backlogetcux

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions