Skip to content

Stop thread cards and Resolve reflecting every key on the page, seat each margin row against only the rows beside it, and name a revealed code block's Copy key - #5866

Merged
max-sixty merged 5 commits into
mainfrom
grind/send-1024
Nov 12, 2026

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Sending a comment on the generated asks page at 1,024 sections now draws the message in a median 185 ms in Chromium, down from 354 ms, and shows the server's reading at 298 ms, down from 504 ms. Resolving a thread there shows the server's reading at 194 ms, down from 470 ms. Both are still above the 100 ms root AGENTS.md ("Responsiveness") asks for; what remains is listed at the end. In Firefox, the send's main-thread time at 1,024 sections falls from 639 ms to 487 ms, and Resolve's from 601 ms to 217 ms. A code block that a disclosure or a tab reveals now names its Copy key, Enter, to assistive technology as soon as it shows; before, it named none until something repainted every key.

Why

Profiling the send at 1,024 sections in Chromium found two costs in the frame after the press that grew with the page.

  • Every key on the page was reflected again. Opening the thread card called paintKeys() (previewChanged, margin-projection.js), which marks every element that declares keys. A send re-read 7,196 elements' aria-keyshortcuts and button availability, about 110 ms of a profiled frame. Closing the card by Escape and opening it by its margin row did the same, through the same call and through closePreview, and a Resolve did it twice, before and after its landing (landGesture, thread/folding.js).
  • Each margin row was seated against every row seated before it. seatRow copied the whole list of seated footprints into its own arrays for each pin, and packRow filtered and sorted it for each rail row. A rows-only pass (Seat margin rows from what the last pass read, and read again only the rows a change names #5817) still seats every row, so each of the send's two passes cost 27–30 ms at 1,024 sections, growing with the square of the rows.

Changes

Key reflection follows what changed. Each element's key reflection is a tracked effect that reads again when a signal it read moves (keyboard/scopes.js). The card already re-reads the keys of what it holds as it shows and as it hides (paintKeysWithin(preview), thread-preview.js, since #4407), a margin row's reflection that asks whether the user is on the card's entry reads the card's revision signal (onOpener), and a settlement in flight already shows in the thread's state, which the reflections read (threadReading, thread-card.js). The four page-wide paintKeys() calls date from before the card painted its own keys (#4407) and before a reflection followed focus only where its rows asked (#5324). They are gone. The stale-keys sweep, fixed here so that it can fail, passes on every published example, and an independent probe of the card and Resolve routes found no stale key (both under Checked). Counted on the 1,024-section page:

Gesture Elements reflected, main This branch
Send 7,196 18
Escape out of the card 7,200 3
Reopen the card from its margin row 7,200 6
Resolve 7,204 twice 17 and 14

Seated footprints are indexed by their tops. Footprints (margin-placement.js) holds the footprints the shared seating order has placed so far, sorted by top, and answers the two questions the seating folds ask: the footprint a rectangle overlaps (hit), and the footprints in order of their tops from the first that can reach below a line (from, for packRow's push down). Each question reads only the footprints level with the rectangle it names, so a pass costs the rows times the logarithm of their number. Every row stands where it stood. A slide moves a seat past the first footprint it meets, and with a gap between seats, which of two overlapping footprints it meets first changes where the seat lands, so hit answers the overlapping footprint seated first, as main's scan in seating order did. pinSpot is no longer exported, since only a test used it; that assertion now goes through seatRow. On the 1,024-section page each rows-only pass of a send now takes 7–10 ms, from 27–30 ms (timed in the page, unprofiled).

The stale-keys sweep repaints every element's keys again. Its forced repaint called commandsChanged(document.body), which since #5369 marks only the element it names, and body declares no commands, so the repaint read no element's keys and the sweep could not fail. The check API now exports paintKeys, and the sweep calls it.

A code block a disclosure or a tab reveals names its Copy key. The repaired sweep failed on four examples, on this branch and on main alike: dynamic-widgets, file-editor, motion and feature-gallery. A block's Copy row was live only once Web Awesome had drawn the copy control's button (copyTrigger), and projectCommandScope reads the row at once, in the task that makes the control, before the control's first update draws the button. Sampled frame by frame on motion after opening its disclosure, the row was read once, with no button yet; the button drew a frame later, and nothing read the row again, so the block's aria-keyshortcuts lacked Enter until something repainted every key. Blocks shown at load already named Enter once the page settled, since the sweep's reading on arrival found none stale; a block prepared later, as a disclosure or tab reveals it, stayed stale. code.copy (code-copy.js) now works as heading.link.copy (heading-links.js) already did for a control that hasn't drawn yet: its row has no condition, and its run waits for the control's definition and first update before clicking. The row so never depends on when the control draws, and nothing needs reading again.

The bench times the frame that paints. leaf-dev bench's paint pass timed a goal at the first task after the frame that showed it. When the server's answer arrived during a long input, its task ran before that one, so the send's painted included applying the server's reading. A profiled run at 1,024 sections read painted and shown both as 382 ms, while the frame showing the message had been laid out at about 245 ms. painted.js now times the frame with a size observation made as the frame renders, which the browser delivers after the frame's animation callbacks and layout, just before its paint. Both arms of a run use the same measurement, so main's numbers below are measured this way too. The review measured the step this puts into the daily chart: with the same runtime, old against new painted.js, at 64 sections over 4 rounds, a send's shown reads a median 101 → 90 ms, a Resolve's 40 → 37.5 ms and a click's 31 → 30 ms.

Measurements

Chromium, uv run leaf-dev bench asks --sizes 256,1024 --input comment --input resolve --rounds 3 --base 3b9ff6464: both arms interleaved in one run, this branch against its merge base with main, load average 7.8 at the start and 9.2 at the end. Each cell is the median of 3 rounds, with the range in brackets. Paint is from the input to the frame that draws its own result; shown is to the frame presenting the server's reading of it; CPU is the input's main-thread time.

Input Sections Paint, main → branch (ms) Shown, main → branch (ms) CPU, main → branch (ms)
Send 8 57 [54–88] → 55 [54–89] 87 [86–88] → 89 [88–89] 75 [75–84] → 85 [80–85]
Send 256 112 [111–113] → 81 [74–84] 155 [154–158] → 124 [122–124] 152 [146–159] → 118 [115–124]
Send 1,024 354 [310–362] → 185 [167–323] 504 [430–507] → 298 [283–323] 451 [447–458] → 291 [291–326]
Resolve 8 20 [19–25] → 22 [21–22] 33 [30–45] → 32 [32–34] 38 [37–46] → 34 [32–35]
Resolve 256 124 [119–126] → 57 [56–60] 124 [119–126] → 57 [56–60] 134 [124–135] → 67 [65–73]
Resolve 1,024 242 [226–249] → 108 [108–110] 470 [438–481] → 194 [194–198] 431 [426–470] → 210 [201–214]

The 8-section rows measure the runtime's fixed work, which this change leaves alone, and their differences are within the spread of the rounds.

Firefox, the same command with --browser firefox, which reads only main-thread CPU there, run straight after; load average 8.8 at the start and 16.8 at the end:

Input Sections CPU, main → branch (ms)
Send 8 75 [70–94] → 82 [74–90]
Send 256 210 [190–245] → 172 [165–268]
Send 1,024 639 [591–673] → 487 [433–489]
Resolve 8 46 [39–46] → 41 [40–54]
Resolve 256 206 [189–221] → 109 [99–119]
Resolve 1,024 601 [555–603] → 217 [189–316]

What remains at 1,024 sections

In the run above, the bench's long-frame attribution at 1,024 sections puts 135 ms of script in the press's task and 51 ms in the frame after it. The costs below are part of that time and grow with the page. Each time given is from a profiled run of this branch at 1,024 sections, with the host's load about 17, so read the times as proportions:

  • The annotations are collected and drawn whole, twice per send. The presenter's paint of the sent comment and the card's own redraw (showPreview → renderAnnotations.refresh) each run paintAnnotations. Its collectEntries (annotation-inventory.js) reads every thread, contribution and workflow on the page. Its renderNow walks every entry, and though it skips drawing a host whose entry is unchanged, it registers every row and reads every target's place down the page (readSpokenPositions). Each marker's name also counts the markers ("3 of 1,024"), so a row added or taken away renames every marker (nameMarkers). Together 64 ms profiled in the press's task, and the same again when the server's reading arrives. Removing it takes an inventory that rebuilds only the entries whose inputs a publication changed (an unchanged entry already keeps its identity, keptEntry), a projection that visits only the hosts whose entries changed, and one paint per send rather than two.
  • The application's publication shares every subtree with the last reading (framework/snapshot.js, share), 16 ms profiled for the send's own publication. Folds that produce only what moved would remove it.
  • The rows-only margin pass still visits every row, 12–14 ms profiled: each row's record is carried and its seat written, though only the new row moved. A change to the page's words or styles lays out only the margin rows it can move #5752 describes the change that removes it, a pass that seats only the rows a change can move.
  • The Tab stop is chosen from every marker (syncRoving → visibleRows, margin-projection.js), clipping each marker's box, 8.5 ms profiled. Reading only the markers around the window would remove it.
  • Focus moves record the reading place (recordPlaces, version.js, through elementsFromPoint), 17 ms profiled across the press and the frame.

This change does not close #5752: a change to the page's words or styles still reads every row.

Checked

  • test_presses_and_fills_leave_no_element_naming_stale_keys (tests/journeys/test_render_navigation.py), the stale-keys sweep, on all 37 published examples: after each of 40 seeded presses and fills, some followed by Escape, it forces a repaint of every element's keys and fails on any attribute the repaint changes.
    • It can fail now. With every visible aria-keyshortcuts overwritten before the repaint, the old repaint passed on review-a-plan and paintKeys() fails. With focus tracking removed from focus.js, it fails on review-a-plan at step 14, on the margin projection's keys.
    • Repaired, it failed on four examples, identically before the copy fix on this branch and with main's runtime: dynamic-widgets, file-editor, motion and feature-gallery, each a code block a disclosure or tab revealed that lacked Enter. With the copy fix it passes on all 37; after the copy row took the heading link's design, it passes on those four again.
    • Under parallel load, file-tree's teardown sometimes reports an unmoved scroll: the vendored file tree (pierre-trees) writes a scrollTop that moves nothing, which the write watch flags. It is not a stale key, and main's runtime shows it too. Across every parallel run that included file-tree, it showed in 4 of 11 on this branch and 2 of 8 with main's runtime; in the last four alternating pairs over the same 10 examples, in 2 on main and none on this branch. Alone, file-tree passed in all 5 runs.
  • An independent review forced the real paintKeys() after a send (with its POST held and landed), Escape, reopening the card from its margin row, Tab into the card, a Resolve (held, landed, and refused with a 409), z and a second Resolve, on review-a-plan and the bench's asks page, and found no stale aria-keyshortcuts or aria-disabled. It also reproduced the speedup: send paint 348 → 193 ms and Resolve paint 227 → 124 ms at 1,024 sections in Chromium.
  • the footprints answer what a scan in the order they were seated answers (new, tests/runtime/margin-placement.test.mjs): 400 footprints of mixed heights, many overlapping and some sharing a top, against 400 probes, comparing hit and from with a linear scan. It fails when hit answers the first overlapping footprint by top rather than the first seated. The other placement tests now seat through Footprints.
  • A scratch comparison, not committed, seated rows in 4,000 randomized trials (up to 120 rows each, rail rows and pins, held, folded and level pins, and gaps up to 8 px) with main's seatRow and packRow and with this branch's: every seat and push was identical. With hit answering by top instead, it failed on trial 5.
  • 41 browser tests by name: the full-pass comparison and seat tests in margin/test_pins.py, the reachability and held-marker tests in margin/test_rail.py and margin/test_clusters.py, the card's opening, closing, Escape and travel tests in margin/test_opening_threads.py, the Resolve, Reopen, undo and in-flight tests in threads/test_resolving.py, and the submit-shortcut test in navigation/test_commenting.py.
  • 28 code-block copy tests by name: the copy tests in test_render_anchors.py (Enter beside nested links, hidden and deferred blocks, closed sections, scroll stops) and test_render_code_reading.py, and the copy controls in margin/test_scrollers.py, drafts/test_draft_editing.py, threads/test_rewrites.py, widgets/test_lifecycle_and_controls.py and test_page_head.py. All 28 pass. test_hidden_code_arrivals_do_not_read_skipped_blocks now also asks that the block a disclosure reveals names Enter, and fails on main's copy row.
  • pnpm run test:runtime (936 pass), pnpm run check:browser, pre-commit on every changed file.
  • The reflection counts above, read with a temporary counter in reflectKeys on main and on this branch.

Not checked

  • Firefox's paint and shown times: the bench reads only CPU there.
  • WebKit.
  • The broad suite and the main-push browser tier.
  • The stale-keys sweep presses controls in a seeded random order, so it reaches the card and settlement routes it happens to press, not every one.

Part of #5194.

…eat each margin row against only the rows beside it

Sending a comment on the generated asks page at 1,024 sections spent most
of the frame after the press on two costs that grew with the page.

Opening the thread card called paintKeys() (previewChanged), which re-read
the keys of every element that declares them: 7,196 at 1,024 sections,
about 110 ms of a profiled frame. Closing the card through closePreview did
the same, and a Resolve did it twice (landGesture). The card already
re-reads the keys of what it holds as it shows and hides (#4407), a margin
row's reflection that asks whether the user is on the card's entry reads
the card's revision signal, and a settlement in flight already shows in the
thread's state the reflections read. Without the four page-wide calls, the
stale-keys sweep over every published example finds no stale attribute.
A send now reflects 18 elements, a Resolve 31.

seatRow and packRow scanned every footprint seated before each row, so a
pass, which seats every row, grew with the square of the rows: 27-30 ms per
rows-only pass at 1,024 sections, now 7-10 ms. Footprints
(margin-placement.js) keeps the seated footprints sorted by top, and each
question reads only those level with the rectangle it names. Seats are
unchanged: hit() answers the overlapping footprint seated first, as the old
scan in seating order did, since with a gap between seats a slide lands
differently depending on which overlapping footprint it meets first. In
4,000 randomized trials against main's folds, every seat was identical.

leaf-dev bench timed a goal at the first task after the frame that showed
it, so when the server's answer arrived during a long input, the send's
`painted` included applying the server's reading. painted.js now times the
frame with a size observation, which the browser delivers after the frame's
layout, just before its paint.

Chromium, 1,024 sections, median of 3 interleaved rounds against the merge
base: send paint 354 -> 185 ms, send shown 504 -> 298 ms, Resolve shown
470 -> 194 ms. Both are still above 100 ms; the pull request lists what
remains.

Claude-Session: https://claude.ai/code/session_01GQAnFBpRfi8Gh5cgPofNzs
The sweep's forced repaint called commandsChanged(document.body). Since
#5369 that marks only the element named, and body declares no commands, so
the repaint read no element's keys and the sweep could not fail. The check
API now exports paintKeys, and the sweep calls it.

With every visible aria-keyshortcuts overwritten before the repaint, the old
call restored none on review-a-plan and the sweep passed; paintKeys restores
them and the sweep fails. With focus tracking removed from focus.js, the
sweep fails on review-a-plan at step 14, a stale aria-keyshortcuts on the
margin projection.

On this branch and with main's runtime alike it now fails on four examples
(dynamic-widgets, file-editor, motion, feature-gallery): a code block a
disclosure or tab reveals gains its Copy key, Enter, only on a full
repaint. The block's row asks whether its copy control has drawn its
button; the likely cause, not yet confirmed, is that nothing marks the
block when the control draws it.
painted.js times the frame that first shows a goal as it is laid out, just
before its paint, rather than at the first task after it. painted.py and
bench.py still described the old reading.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once this lands, the repaired stale-keys sweep (test_presses_and_fills_leave_no_element_naming_stale_keys) will turn the nightly journeys tier red on dynamic-widgets, file-editor, motion and feature-gallery. The description says the Copy-key staleness behind those failures predates this change and is "left to a follow-up", but no open issue tracks it. Unless one does, the nightly CI-failure report will open a cause issue pointing at this PR, and the next session will have to work out again that the cause is declareCopy (code-copy.js) and not this change. Either fix it here by marking the block when its copy control draws its button, or open an issue for it before marking this ready, naming the four examples and the suspected cause.

A code block's Copy row is live once Web Awesome has drawn the copy
control's button (copyTrigger). projectCommandScope reads the row at once,
in the task that makes the control, and the control draws its button only
on its first update after that. Sampled frame by frame on the motion
example after opening its disclosure, the row was read once, with no button
yet; the button drew a frame later and nothing read the row again, so the
block's aria-keyshortcuts lacked Enter until something repainted every key.
Blocks shown at load already named Enter once the page settled; a block
prepared later, as a disclosure or tab reveals it, stayed stale.

declareCopy now reads the block's keys again, with paintKeysWithin(pre),
once the control's first update completes. In the same sampling, Enter
appears in the frame the button draws.

The repaired stale-keys sweep failed on dynamic-widgets, file-editor,
motion and feature-gallery for this, on this branch and with main's
runtime alike; it now passes on all 37 published examples. The hidden-code
arrival test now also asks that the block a disclosure reveals names Enter.
…link's

A code block's Copy row was live only once Web Awesome had drawn the copy
control's button, and the previous commit read the block's keys again once
the control's first update completed. heading.link.copy (heading-links.js)
already handles a control that has not drawn yet another way: its row has
no condition, and its run waits for the control's definition and first
update before clicking. code.copy now does the same, so the row never
depends on when the control draws, nothing needs reading again, and both
copy rows work alike. The re-read in declareCopy is gone.

The stale-keys sweep passes on motion, feature-gallery, dynamic-widgets and
file-editor; the 28 code-block copy tests, including the one that asks that
a block a disclosure reveals names Enter, and pnpm run test:runtime (936)
pass.
@max-sixty max-sixty changed the title Stop thread cards and Resolve reflecting every key on the page, and seat each margin row against only the rows beside it Stop thread cards and Resolve reflecting every key on the page, seat each margin row against only the rows beside it, and name a revealed code block's Copy key Nov 12, 2026
@max-sixty
max-sixty marked this pull request as ready for review November 12, 2026 07:57
@max-sixty
max-sixty merged commit 49d85b5 into main Nov 12, 2026
6 checks passed
@max-sixty
max-sixty deleted the grind/send-1024 branch November 12, 2026 08:13
max-sixty added a commit that referenced this pull request Nov 12, 2026
… the margin once per card open, and skip clip walks for boxes off screen (#5893)

A sent comment on the generated asks page at 1,024 sections now draws in
a median 136 ms in Chromium, down from 171 ms on main, and shows the
server's reading at 214 ms, down from 271 ms. A Resolve shows the
server's reading at 135 ms, down from 177 ms. That is still above the
100 ms root `AGENTS.md` ("Responsiveness") asks for; what remains is
listed at the end. The largest part of the gain comes from DOM writes,
which were slow on a long page whatever made them, so it reaches beyond
the send. In Firefox the send's main-thread time at 1,024 sections fell
from 299 ms to 269 ms, measured with this branch's first commit.

## Why

Profiling the send at 1,024 sections on main after #5866 left these
growing with the page in the press's task and the frame after it, in ms
of real (unprofiled) time from timers placed around each function,
against the same at 8 sections:

| Work | 8 sections | 1,024 sections |
| --- | ---: | ---: |
| Thread card build (`buildThreadCard`) | 7.8 | 17.6 |
| Annotation paints, two in the press's task (`paintAnnotations`) | 2.8
+ 2.0 | 21.3 + 12.9 |
| The send's publication (`publish`) | 1.0 | 15.1 |
| Recording the reading place (`recordPlaces`) | 0.5 + 1.8 | 10.7 + 3.1
|
| Margin pass (`layoutMarginRows`) | 1.3 | 9.3 |
| Tab stop (`syncRoving`) | 0.0 | 6.1 |

The card build's growth had no reason in the card. Timing a DOM write
alone found it: on the 1,024-section page, inserting and removing one
empty element took half a millisecond, against none at 8 sections, and
the same for an element never attached to the document.

## Changes

**Measuring a node's lines reuses one range.** A `Range` stays live
until a garbage collection reclaims it, and Chromium updates every live
range of a document on each insertion and removal, attached or not. The
margin's cover reading (`childIndex`, margin-layout.js) made a range for
each text node it measured: 18,432 of them during load at 1,024
sections, by a count of `createRange` calls, and every pass that reads
all the rows makes its own. Until a major collection, every DOM write on
the page walked all of them. 2,000 insert-and-remove pairs on a detached
element took 1,110 ms on the loaded page, 35 ms after forcing a
collection, and take 24 ms with this change, uncollected. shown-box.js
now keeps one range for reading a node's contents (`contentsRects`,
`contentsBox`, and `elementBox` for a `display: contents` element),
which lets go of the node once read. A thread card's head fit
(`wordsWidth`), a heading link's first line (`firstLine`) and a text
field's send corner (`#cornerTaken`) measured through ranges of their
own and now read through the shared one, and `browser/AGENTS.md` names
it under "One answer for each question". A count of the ranges made
while typing, sending, resolving and scrolling now finds tens per
gesture; the largest left are `caretAt` (editor-view.js), about 4 per
keystroke, and `rangeOf` (passages.js), 54 per send, listed below. The
review measured a keystroke at 1,024 sections at 6.5 ms of main thread,
from 6.9 ms.

**Opening a thread card paints the margin once.** `showPreview` redrew
the whole margin after the card opened (#5420), only so that the
redraw's tracking would follow the card's message ages. A send paid that
as a second full annotation paint in its task. The card's thread now
follows its own reads instead (`follow`, application.js, the mechanism
the margin's direct redraws already used), so the card's ages still
advance with the clock and the margin is painted once.
`test_message_age_may_shift_metadata_but_leaves_the_thread_in_place[card]`
fails with the card's draw left unfollowed and passes with it.

**A box outside the visible viewport skips its clip walk.** `seenRect`
(geometry.js) cuts a box by every box that clips it and then by the
visible viewport's height. The clips only cut, so a box the viewport's
height doesn't reach is now answered null before the walk. Choosing the
margin's Tab stop asks this of every marker.

## Measurements

Chromium, `uv run leaf-dev bench asks --sizes 256,1024 --input comment
--input resolve --rounds 3 --base 5bb337b`: both arms interleaved in
one run, this branch's head against its merge base with main (#5889),
load average 7.1 at the start and 6.0 at the end. Each cell is the
median of 3 rounds, with the range in brackets. Paint is from the input
to the frame that draws its own result; shown is to the frame presenting
the server's reading of it; CPU is the input's main-thread time.

| Input | Sections | Paint, main → branch (ms) | Shown, main → branch
(ms) | CPU, main → branch (ms) |
| --- | ---: | --- | --- | --- |
| Send | 8 | 57 [54–88] → 52 [51–87] | 88 [83–90] → 87 [71–90] | 82
[75–85] → 81 [74–85] |
| Send | 256 | 79 [72–82] → 68 [68–70] | 119 [105–121] → 105 [105–107] |
110 [104–115] → 104 [102–106] |
| Send | 1,024 | 171 [162–177] → 136 [130–142] | 271 [269–278] → 214
[206–233] | 258 [258–274] → 209 [198–213] |
| Resolve | 8 | 35 [19–36] → 18 [17–19] | 35 [30–36] → 30 [27–31] | 34
[32–39] → 36 [35–37] |
| Resolve | 256 | 54 [33–62] → 56 [53–57] | 59 [54–62] → 56 [53–57] | 65
[64–71] → 62 [60–63] |
| Resolve | 1,024 | 173 [104–179] → 135 [126–153] | 177 [173–179] → 135
[126–153] | 182 [181–185] → 148 [138–155] |

The 8-section rows measure the runtime's fixed work, which this change
leaves alone; their differences are within the spread of the rounds. The
same run's long-frame attribution at 1,024 sections puts the send's own
task at 94 ms of script, from 126, and the frame after it at 40 ms, from
46. Most of the gain is the range change: a two-round run of the first
commit's two smaller changes alone read the send's paint at 157 ms
against main's 166.

Firefox, the same command with `--base origin/main` and `--browser
firefox`, which reads only main-thread CPU there, on this branch's first
commit, which also wrote only the focused marker's place (withdrawn
since); load average 4.3 at the start and 4.0 at the end:

| Input | Sections | CPU, main → branch (ms) |
| --- | ---: | --- |
| Send | 256 | 136 [130–139] → 124 [113–127] |
| Send | 1,024 | 299 [297–301] → 269 [267–620] |
| Resolve | 256 | 108 [96–129] → 107 [103–128] |
| Resolve | 1,024 | 180 [178–194] → 173 [173–173] |
| Load | 1,024 | 4,108 [4,064–4,115] → 3,703 [3,639–3,842] |

Firefox gains less from the range change than Chromium; I haven't
profiled why.

## What remains at 1,024 sections

The send's own task is 94 ms of script and the frame after it 40 ms.
Timed in the page at 1,024 sections with this branch, against 8
sections, these still grow with the page:

- **The send's publication**, 15 ms against 1 (`publish`,
framework/application.js). Every publication derives the whole effective
state (`derive`) and shares each subtree against the last reading
(framework/snapshot.js, `share`), whose module header names this as its
design: "a fold rebuilds its whole result on every publication".
Removing it takes folds that produce only what a change moved.
- **Recording the reading place on the focus move the send makes**, 11
ms against 0.5, and 3 ms more in the frame (`recordPlaces`, version.js).
`capturePlace` hit-tests the landing edge right after the send's DOM
writes, which forces the page's style and layout there, and anchors the
line it finds by searching the page's text for that line's copies
(`findQuote`).
- **Collecting the annotation inventory**, 9 ms against 0.6
(`collectEntries`, annotation-inventory.js). It reads every thread,
obligation, contribution and change, names every group, and sorts the
groups by rendered order, building each node's ancestor chain afresh for
every comparison. Caching each node's chain for the sort, and each
unchanged group's entry, would take most of it.
- **The margin's rows-only pass**, 8 ms against 1.3
(`layoutMarginRows`), which still visits every row; #5752 describes
seating only the rows a change can move.
- **Naming every marker on each render**, about 7 ms in the send's paint
(`nameMarkers` 4.5, `readSpokenPositions` 2.7). Each marker's name says
where its row stands among the rows and how far down the page ("3 of
1,024, 40 percent down"), so a row that comes or goes renames every
marker, and every render reads every target's place. Writing the place
into the focused marker's name only, which an earlier commit of this
branch did, renamed the button in the task that moves focus to it, which
a screen reader may announce twice, and took the place from browse mode,
so it is withdrawn. The platform can't say the place for us:
`aria-posinset` isn't allowed on a button, and a list item gives a
button no position.
- **Ranges made per gesture**: `caretAt` (editor-view.js), about 4 per
keystroke, and `rangeOf` (passages.js), 54 per send. Each stays live
until a collection, so moving them onto the shared range would keep DOM
writes from slowing as they pile up.
- **Forced style recalculations**: in profiled runs, about 30 ms of the
send's window at 1,024 sections and about the same at 64, where each
restyles 15 to 230 elements at around 15 µs an element. They don't grow
with the page, so they are fixed cost, but they are the largest single
item left in the send's task, and the same at every size.

## Checked

- `pnpm run test:runtime` (952 pass), `pnpm run check:browser`,
pre-commit on every changed file.
- 41 browser tests by name across margin seats, card opening and
closing, Resolve and the send (the selection #5866 ran): all pass, the
full-pass comparison
`test_a_pass_for_a_change_to_the_rows_seats_them_as_a_whole_pass_would`
among them, which reads every pin's cover through `childIndex`.
- 177 marker, walk and Page Map tests by name, with main's marker names
and the tests that read them restored, in `margin/test_page_map.py`,
`margin/test_entries.py`, `margin/test_clusters.py`,
`margin/test_opening_threads.py`, `margin/test_status.py`,
`navigation/test_threads.py`, `navigation/test_key_scopes.py` and
`test_render_aim.py`: all pass but
`test_a_comment_uses_the_viewport_when_its_target_fills_the_vertical_lane`,
which times out the same way with main's runtime.
- `test_message_age_may_shift_metadata_but_leaves_the_thread_in_place`
(both surfaces) passes; its card case fails with the card's thread draw
left unfollowed.
- 21 tests by name for the card's message ages, heading links, the send
corner and held news, which the moved measurements reach.
- `tests/model/test_owner_index.py`, which checks the owners table.
- The stale-keys sweep on all 37 published examples passed on the
branch's first commit, with file-tree's teardown flake (#5866 describes
it).
- Timers around the functions in the first table, and a count of
`createRange` calls by caller while loading, typing, sending, resolving
and scrolling at 1,024 sections, both temporary and not committed.

## Not checked

- Firefox's paint and shown times: the bench reads only CPU there.
- WebKit.
- The broad suite and the main-push browser tier.
- Inputs other than the send and Resolve, beyond the review's keystroke
reading above.

Part of #5194.
leaf-agent added a commit that referenced this pull request Nov 13, 2026
#5911)

The code block's Copy row (`code.copy`, added in #5866) and the
heading's copy-link row (`heading.link.copy`) each repeated the same
three steps: wait for the copy control's definition, wait for its
update, then click its trigger. The code block's comment pointed at the
heading's copy of those steps. Waiting until the control has drawn its
button is the copy control's own rule, so `copy-control.js` now keeps it
as `pressCopy`, beside `copyTrigger`, and both rows call it. No behavior
changes.

Verified with `test_code_copy_on_plain_http_machine_name` (click and
Enter) and `test_render_heading_links.py` (6 passed), plus the browser
type check and `pre-commit`. No new test, since both paths keep their
existing coverage. The nightly review of recent commits found the
duplicate.

Co-authored-by: leaf-agent <[email protected]>
max-sixty added a commit that referenced this pull request Nov 15, 2026
…it (#6001)

After a sent comment on `leaf-dev bench`'s 1,024-section asks page, the
readings the page publishes keep every record the send left alone as the
object it was, so every reader that keeps what it read by identity skips
them. The publication that takes in the server's reading of the send
drops from a median 16.9 ms to 9.8 at 1,024 sections, and the
publications from the press until that reading is taken in from 20.5 ms
to 14.6 (timed in the page; an independent profile of that window found
a 2–6 ms saving, Measurements). Sharing an event log grown by one event
also gets cheaper than on main. The other costs #5899 left are measured
below; two of them no longer hold on current main.

## Why

Commenting on a question hands its obligation to the agent, so the
obligation leaves `readObligations().user`. `share`
(framework/snapshot.js) compared each item of a list with the item at
the same index of the prior list. Each record after the one that left
was compared with its neighbour's, found different, and published as a
new object, so every reader that keeps a reading by identity (kept.js)
read all 1,023 of them again. Found by keeping the annotation
inventory's entries by their records: the collection after the server's
reading remade all 1,024 entries, though only one obligation had
changed.

## Change

`share` names a list's records by the rule the server's patch protocol
names a list's items by (`src/leaf/served_state/tail.py`, `_named`):
each record's string `id`, else its event's `id`, and only where no two
records of the list share a name. Where both lists are named by one
rule, a record whose name differs from the one at its index is compared
with the prior list's record of its name. A list whose records go by no
name, or share one, is compared place by place, as on main. Deep
equality still decides whether a subtree is replaced, so only the choice
of which prior record each new one is compared with changes.

While every item stands for the prior list's item at its index, by
identity or by name, an item past the prior list's end is returned
without being compared, so sharing a log grown by an event builds no
index of the log.

Lines of mechanism, counting code and leaving out comments, blank lines
and tests: 36 added and 8 removed, all in snapshot.js. 20 are the
helpers that name a list's records and pair them, and 16 replace the
8-line loop that pairs each item with a prior one.

## Measurements

Timed in the page with `performance.now()` around each outermost call of
`publish` (framework/application.js), unprofiled, at 1,024 sections. No
publication ran nested inside another during these sends (counted), so
each is counted once. Main and this branch alternated, two runs of five
sends each, with the host under heavy load (load average 66–122). Each
cell is the median of the ten sends, with the lowest and highest in
brackets:

| Publications | main (ms) | this branch (ms) |
| --- | --- | --- |
| The press's own | 3.2 [2.7–4.7] | 2.7 [2.5–4.5] |
| The one that takes in the server's reading | 16.9 [15.1–21.5] | 9.8
[8.5–11.6] |
| From the press until the reading is taken in, summed | 20.5
[18.4–27.9] | 14.6 [13.1–20.0] |
| Every one of the send's, until the page settles | 23.6 [20.3–30.1] |
16.5 [13.6–22.3] |

An independent review profiled every publication from the press until
the page took in the reading, the third row's window, with V8's sampling
profiler, two runs each, on main and on this PR's first commit: a send
17.0 and 16.4 ms against 14.8 and 12.2, a Resolve 18.1 and 14.4 against
12.7 and 11.6, a pick 28.4 and 24.0 against 23.1 and 20.6. That is 2–6
ms over the window, against the timers' 6 ms for a send; the two differ
in method, in host load and in the branch's commit.

Sharing a list alone, in Node, the median of 15 interleaved trials (load
average about 31), in ms:

| List | main | first commit | this branch |
| --- | ---: | ---: | ---: |
| 1,000 events, grown by one in place | 0.040 | 0.071 | 0.017 |
| 4,000 events, grown by one in place | 0.149 | 0.231 | 0.027 |
| 16,000 events, grown by one in place | 0.659 | 1.330 | 0.106 |
| 16,000 new records, the first one gone | 4.8 | 6.4 | 7.3 |

On the last row this branch keeps 15,999 records' identity, where main
keeps none; the extra time is naming both lists. A list of fresh records
grown by one costs the same as on main (4.9 and 5.1 ms at 16,000).

Chromium, `uv run leaf-dev bench asks --sizes 64,256,1024 --input
comment --rounds 5 --base 7ec8751`, on this PR's first commit against
main, both arms interleaved, load average 5.2 at the start and 17.9 at
the end. CPU is the send's main-thread time from the press until 400 ms
after its reading shows, less the page's idle time. Each cell is the
median of five rounds, with the lowest and highest in brackets.

| Sections | CPU, main → branch (ms) | Shown, main → branch (ms) |
| ---: | --- | --- |
| 64 | 79.5 [73.3–82.6] → 78.0 [70.7–86.5] | 96.7 [87.6–113.0] → 97.0
[88.2–102.6] |
| 256 | 90.5 [88.1–106.6] → 93.5 [86.1–106.2] | 113.2 [112.6–126.7] →
110.5 [109.5–113.1] |
| 1,024 | 178.1 [160.1–204.3] → 167.1 [158.0–219.2] | 185.4
[171.7–204.9] → 187.5 [166.5–196.7] |

The rounds' spread at 1,024 sections is wider than the saving, so the
CPU column shows the direction and not the size. The paint pass's
long-frame attribution put applying the server's reading (`paintedOwed`)
at 39 ms of script per window on main and 15 on this branch, and 42 and
12 in an earlier three-round run. It counts only frames of 50 ms or
more, so a frame that drops just under that line leaves the count; it
shows that the reading's frames got shorter, not by how much. Paint, the
frame that draws the sent message, moves within the rounds' spread: the
change is in the reading's application, after that frame.

## The costs #5899 listed, on current main

Timed in the page on main (`7ec8751318`) with `performance.now()` around
each function, unprofiled, median of five sends, before the frame that
draws the message:

| Step | 64 sections | 1,024 sections |
| --- | ---: | ---: |
| Margin pass (`layoutMarginRows`) | 1.4 ms | 9.3 ms |
| Annotation inventory (`collectEntries`) | 0.6 ms | 6.1 ms |
| Reading place (`recordPlaces`; its `lineAnchor` 0.0 and 0.1 ms) | 1.7
ms | 3.1 ms |
| Forced style in the press's task (trace, 22 recalcs) | 15.5 ms | 17.9
ms |

- **Margin pass.** Spread over every row. Timed by phase over a send's
two passes at 1,024 sections, 15.9 ms in all: seating itself is 2.5 ms,
and the rest is finding held rows, carrying each row's record, writing
each seat, the new pin's cover reading every child of `main`, and the
layout event's listeners. Seating only the rows a new row can reach
would cut the 2.5 ms and leave the rest; making the whole pass follow
the change is a restructure of `layoutMountedRows`, judged not worth it
for about 2–6% of a send's CPU.
- **Annotation inventory.** I built keeping each item and entry by the
records and label it was made from (kept.js), with the kept entries left
in their order and only the remade ones placed among them. It cut a
collection from 6.1 to 4.5 ms, but an interleaved five-round A/B against
this branch read the send's CPU at 1,024 sections as 171.8 ms without it
and 170.6 with it, for about 75 lines, so it is not here. The cost is
visiting every obligation and resolving its target (`getElementById`,
`targetPath`, the label, the group map), about 4.5 µs each; making
entries is about 0.6 ms of it. Skipping records whose list didn't change
would have to resolve targets by id and read labels from attributes the
page's reading doesn't hear, and `an entry stays one object until what
it is made from changes` holds that an `aria-label` change shows at the
next collection.
- **Reading place text search.** Gone on current main (#5875 changed
that search): `lineAnchor` takes 0.1 ms. `capturePlace` still grows, 0.7
→ 2.2 ms, from visiting every text block to find those on screen
(`textBlocks`, `renderedBlocks`).
- **Forced style.** It does not grow with the page, and no rule restyles
more than the card: each of the 22 recalcs touches at most 97 elements,
all in the thread card, the composer, one margin row or their ancestors
(invalidation tracking in an unprofiled trace). `--lf-ring-at` is
registered as non-inheriting (base.css, since #5116), so focus rules
setting it restyle only the box they match. The 16–18 ms is the number
of places a script reads style or layout after a write in the press's
task: `scrollToEnd` in `showArrival`, `motionTime` reading a token
twice, `focusBox`, `cardMinimum`. That is a question of the card's build
order rather than of CSS.

The margin projection's per-row work grows too: `renderNow` 2.1 → 6.3
ms, of which `readSpokenPositions` (each target's place down the page)
is 2.6 and `nameMarkers` 1.8, and the Tab stop (`syncRoving`) 0.3 → 2.5.

## One record of what changed?

The brief asked whether one shared record of what changed would replace
`readingElements` (#5872), the `derive` steps' memo (#5899),
`Footprints` (#5866) and `drawnElements` (#5871). It would not:

- `drawnElements` keeps nothing between calls. It walks what the browser
draws, asking `checkVisibility`, and skips the rest.
- `Footprints` is an index of seats built in each margin pass and
dropped at its end. The margin's record across passes is `seatings`,
which the page's observers drop: a resize, a mutation, a scroll inside a
box, a transition's end.
- `readingElements` and the `derive` memo are records of change for
different inputs. The memo compares immutable state by identity, which
needs no observer because publication shares every unchanged subtree.
`readingElements` keeps its answers on pieces of the page's reading,
which the reading's mutation observer drops.

These already compose. The page's reading exposes its state as an
identity token, `pageReadingVersion`, which an identity-keyed reading
takes as one more input, as `gatherConversations` (thread/placement.js)
and `prepareVisualActions` (anchor-controls.js) do. Geometry is a third
kind of change, reported by resize observers, scroll events and
transition ends rather than by a mutation, so folding `seatings` into
the same record would move it only partway. What made a cost like these
hard to remove was a fault in the identity record itself, which this
fixes: positional sharing broke identity for every record after one that
moved, and each identity-keyed reader paid for it.

## Checked

- `pnpm run test:runtime` (970 pass) and `pnpm run check`; pre-commit on
both files.
- The new test, `sharing a list keeps each record equal to the prior one
of its name` (framework-snapshot.test.mjs), fails on main and on this
PR's first commit: records lost, gained mid-list and reordered as new
objects, records named by their events, a list of unnamed records, and
two records sharing an id, which stay two objects.
- The review's fuzz of 20,000 lists passes: every result deep-equals the
new list, reuses a prior subtree only where it is equal, and in no list
do two places become one object (104 to 108 lists did on the first
commit).
- 41 browser tests, all passing on the final head, selected with `-k`
from `widgets/test_obligations.py`, `threads/test_resolving.py`,
`test_render_semantic_news.py`, `margin/test_page_map.py`,
`margin/test_entries.py`, `test_render_options.py`,
`threads/test_panel_list.py`, `projection/test_widget_actions.py`,
`projection/test_thread_replies.py` and
`projection/test_live_versions.py`: obligations answered, cleared and
walked; threads resolved and reopened; agent news; Page Map
reconciliation; margin rows leaving; undo and refused picks; live
revisions.

## Not checked

- Firefox and WebKit.
- The broad suite and the main-push browser tier.
- Which lists besides the user's obligations shift in a send's reading;
the publication time is measured, not attributed list by list.

## Calls Max may reverse

- The annotation inventory's kept entries are left out, measured as
above.
- Where the two lists are named by different rules, `share` compares
records place by place, where the server's patch treats every item as
new. Both are correct; place by place can still find an equal record.
- A long list of new records that loses its first one costs more than on
main (the table above), in exchange for keeping every record's identity.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants