Skip to content

The page's reading follows a change to its words without rereading the whole page #5753

Open

Description

@max-sixty

On a page whose words change every frame, such as a live counter, each pointer move rebuilds Leaf's whole reading of the page's words. An agent session working on hover previews measured it in Chromium on Nov 6, on the thread-previews branch since landed as #5618: with a counter redrawn every frame far from the page's one mark, the rebuild took 6.5 ms of each move at 1,600 sections, and margin layout (#5752) took about 6 ms more. With the pointer still, nothing asks for the reading and no rebuild runs. A profile put 5.9 of the 6.5 ms in the DOM walk. Root AGENTS.md, "Responsiveness", asks that work a pass would redo for the whole page run only for the change that makes it necessary, and that a hover cost the same on a page of ten sections as of five hundred. I haven't re-measured on 6a62560e2; the code below is unchanged.

The reading is kept per document and dropped whole on any change to it: the watcher (hear, passages.js:1866) forgets the document a record lands in (forget, line 1850), the next reader walks the whole body again (readPage, line 2100), and placement then compares the old and new readings character by character to find what changed (changedSpan, line 2500). The hover frame asks for the reading, so a counter anywhere on the page costs every move a walk of the page.

A fix likely keeps the reading current instead of forgetting it: re-walk only the subtrees the mutation records name (a text node's segment for a text write, the target's subtree for a child-list or attribute change, the host for slot or name), splice the result into the last reading, and hand each splice to the readers that keep a record of the page's words, which deletes changedSpan's page-length compare and the wholesale clearing of per-element readings. The hard parts that session found: locating a removed subtree's old span, since detached nodes can't be ordered (the records' sibling hints help); line breaks that cross a subtree's edge, which would need entries of their own; re-deriving fences and cells over the spliced range; and a full read for inputs no record reports, such as a registry change or a settlement. Rebuilding the joined string and offsets would still be linear, about 0.5–1 ms at 8,004 segments, unless offsets become relative. That session estimated 150–250 lines in passages.js, plus a property test that a spliced reading equals a full read after random mutations.

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