Skip to content

A keystroke and a wheel step on the largest document page fit 8 ms in Firefox #6479

Open

Description

@max-sixty

On the largest document page leaf-dev bench builds (size 512, about 32k lines), Firefox spends 9.6 to 10.5 ms of main-thread time on a keystroke in the comment box and 10.3 to 12.0 ms on a wheel step (lowest of 3 rounds, at e2db751, on a loaded Mac). Root AGENTS.md, "Responsiveness", sets 8 ms for each. A Gecko profile puts the excess in two Leaf mechanisms. Style and layout take about 0.1 ms of a wheel step, with at most one forced layout per input, so they are not the cause.

Keystroke: the comment box's redraw runs the whole repaint frame. Each keystroke asks the box to redraw (draftChanged → refresh() → field.requestUpdate(), composing/input.js:792), and LeafElement.updated → paintKeysWithin then runs every painter in repaint.js: 3.5 to 4.3 ms of the keystroke. Skipping that frame altogether took a keystroke from 9.6 to 6.6 ms at size 512, so 3 ms is the most this part can save.

  • Redraw the box only when what it draws changes: when it empties or fills, gains a second line, or can or can't send. The floating panel already redraws only on such a change (retype, floating-panel.js:1697).
  • Check first whether the send labels' callbacks read the draft, and whether anything else asks for the frame on each keystroke.
  • For the redraws that remain, work out the keyboard scope stack once a frame. stack() runs about five times a frame and takes 1.5 to 2.2 ms of it; reachingNow already keeps its reading once a task.
  • Rejected: letting each painter skip its paint by kept and version(). Focus, the selection, packages' availability checks and geometry carry no version, so each painter would need a hand-kept list of what it reads, which goes stale as painters change.

Wheel step: recording the reader's place walks the whole listing. After each scroll comes to rest, reading continuity's recordPlaces → capturePlace (installReadingContinuity in version.js) costs 2.2 ms at size 8 and 3.8 ms at size 512 (profiled). renderedBlocks already receives the band at the window's top, but drawnSegments walks every run of the listing.

  • Limit that walk to the band, and build the clip cache once rather than once per block (reading-place.js:761). The change stays inside reading-place.js.
  • Later, and only to replace the walk rather than stand beside it: hit testing with document.caretPositionFromPoint.
  • Rejected: quoting the line only when a revision needs it. lf-tabs saves capturePlace's result as JSON, and the quote costs at most 1.2 ms.
  • Other work grows with the page too: with the capture and the repaint frame both skipped, a wheel step still grows from 4.1 ms at size 8 to 7.0 at size 512.

A steady wheel step at size 512 (steps 3 to 32, profiled, ms of main-thread CPU): display list and paint 3.0, reading-place capture 2.6, geometry reads, style and layout 1.6 (1.3 of it the capture's own reads), garbage collection 1.6, other Leaf script 0.6, other browser work 0.5.

Unconfirmed: the wheel step's saving, estimated at about 2 of the capture's 3.8 ms; nobody has made the change.

To measure, profile with the variables the bench.py header names and split the samples by input window (#6480). Until #6480 lands, drop the first two wheel steps, which carry a one-time colouring burst (#6482).

Max paused this work on 18 November 2026; it waits on his go-ahead.

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

Activity

  1. added
    backlog
    next
    on Nov 19, 2026
  2. self-assigned this
    on Nov 19, 2026
  3. added
    ux
    on Nov 19, 2026
  4. max-sixty commented on Nov 25, 2026

    @max-sixty
    OwnerAuthor

    Max's answer, 24 November:

    extend these a bit, maybe give it 12ms, and say that we can look again at this when other architectural changes have settled, in a week or so

    #7100 changes the keystroke and wheel-step budget in root AGENTS.md from 8 ms to 12 ms. On the 19 November figures, Firefox's keystroke (9.6–10.5 ms) fits and its wheel step (10.3–12.0 ms) sits at the line. This issue stays open, assigned to Max, for that second look around 1 December.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

backlognextux

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions