Repository navigation
Seat margin rows from what the last pass read, and read again only the rows a change names - #5817
Conversation
Sending a comment changes the margin's rows twice, once as the send adds the new thread's row and once as the server's reading replaces it, and each change ran a pass that read and seated every row. Nearly all of that pass was each pin reading the words and controls around its target (`coverIn`): profiled at 1,024 sections on the generated asks page, the two passes took 520 ms, 402 ms of it in `pinSeating`. A pass now knows why it runs. Every page observer the margin already has marks the page moved, and the pass after it reads and seats every row as before. A change to the rows alone, a row registered, renamed or let go, or a face drawn at another size, leaves the page where it stood, so that pass reads only the rows the change names (`unsettled`) and keeps every other row's seat from its record of the last pass that seated it (`seatings`). It walks the same held-and-arrival order as a full pass and seats a kept row again, from its record shifted by the document's scroll since, only where a footprint that changed reaches into the room its seating read (`seatReach`, `packReach`): one a departed row freed, one a row read afresh took or takes, or one a kept row moved from or to. A row held, withheld, or standing in a pane, carrier or header frame is read every pass. The full pass is the same loop with nothing kept, so seating has one path, and a kept row writes nothing. Measured on the generated asks page in Chromium, base and head interleaved, medians of 5 rounds: a send's paint went 188 to 122 ms at 256 sections and 581 to 359 ms at 1,024; the server's reading shown went 282 to 160 ms and 978 to 494 ms; the send's main-thread CPU went 270 to 165 ms and 1,050 to 489 ms. At 64 sections the paint is within noise (90 to 88 ms) and the CPU went 122 to 92 ms. Behaviour unchanged: a row's leaving still lets the rows it pushed come back up, which `test_a_row_pushed_down_comes_back_up_when_the_row_above_it_leaves` holds by waiting for the pass the row's leaving brings, rather than one a layout change forces, and which fails with the reach check disabled. Property tests in `margin-placement.test.mjs` scatter footprints and check that those outside a seating's reach leave the seat as it was. Claude-Session: https://claude.ai/code/session_01GQAnFBpRfi8Gh5cgPofNzs
`leaf-dev bench --input resolve` sends a comment as `comment` does, waits for the page to take in the server's reading of it, and presses Resolve in the thread's card. Its result is painted once the thread's margin row leaves (`rowLeft` in `painted.js`), and shown once the page presents the server's reading of the resolve. It measures the margin's other common change to its rows, a row leaving, beside `comment`'s row arriving. Claude-Session: https://claude.ai/code/session_01GQAnFBpRfi8Gh5cgPofNzs
The resolve input sent its comment on the passage `comment` had already commented on, so the thread's row never left and the input timed out when both ran in one pass. It now puts away any card an earlier input left open and comments on the next passage, so its row is its thread's alone, and names that row by the card it opened. `PASSAGE` skips the paragraph a comment's editor holds, which follows the title in document order once a comment has been written. Claude-Session: https://claude.ai/code/session_01GQAnFBpRfi8Gh5cgPofNzs
Every pass asks which rows the user holds, and a pass that keeps most rows' seats asks it of every row too. Asked through `:has()` of each row it took 1.4 to 2.1 ms at 1,024 sections; the same selector written to name the held row or the part inside it, then each match's row, takes 0.4 ms. A row that keeps its seat is still one nobody holds. Claude-Session: https://claude.ai/code/session_01GQAnFBpRfi8Gh5cgPofNzs
An independent review found two cases where a pass for a change to the rows alone left rows where a pass over the whole margin would not. - A hold ending moved a row later in the seating order, and the kept rows before it were never asked again: a row stayed 30 px above its line. The pass kept a row's seat while no changed footprint reached the room its seating read (`seatReach`, `packReach`), a second statement of what `seatRow` and `packRow` test that had to stay in step with them. Every pass now seats every row in the shared order, a row with a record from what the last read found, carried by the scroll since, and any other from a fresh read, so the order and the occupied footprints are a full pass's by construction. The reach, its footprints, the changed list and the write filter go, with their property tests. - An immediate contribution update draws a face and flushes the layout in one task, before the face records are delivered, and the pass's `faces.takeRecords()` threw them away: a pin grown from 31 to 62 px stayed past the window's right edge. A pass now first hears the face records still waiting and checks the restyled rows' sizes, dropping the record of each that changed. The state folds into the one map: a change that may move the page clears every record, which replaces `pageMoved`, and a change to one row drops its record, which replaces `unsettled`. Seating every row grows with the square of the page, as the full pass already does: timed on the generated asks page through four sends and a resolve, a pass for the rows alone went from about 1.8 to 3.3 ms at 256 sections and from about 5 to 22 ms at 1,024. Indexing the occupied footprints by height would take that out of both passes. `test_a_pass_for_a_change_to_the_rows_seats_them_as_a_whole_pass_would` compares every row after each of a hold ending, a face growing at once, a row leaving, a scroll and a sent comment, and a resolve with where a forced full pass stands it. It fails on the previous head at the first two, and at the face growing without the face records heard. It replaces the pushed-row test, whose case it covers. The `shiftedPin` test now names every positional field of a pin, and fails for each of the seven left unshifted. Claude-Session: https://claude.ai/code/session_01GQAnFBpRfi8Gh5cgPofNzs
leaf-agent
left a comment
There was a problem hiding this comment.
The description still describes the design that 611fec56 replaced. That matters because the body becomes main's commit message on squash:
- Design and What later changes keep working with describe
seatReach/packReach, a kept row seated again only where a changed footprint reaches it, and thepageMoved/unsettledstate. The last commit removes all of these. Every pass now seats every row in the shared order, and oneseatingsmap stands in for both flags. A reader following the "a change to those folds … must widen the reach" rule would look for a reach that no longer exists. - Checked cites the
seatReach/packReachproperty tests andtest_a_row_pushed_down_comes_back_up_when_the_row_above_it_leaves, which were removed or replaced. It doesn't mentiontest_a_pass_for_a_change_to_the_rows_seats_them_as_a_whole_pass_would, the test that now holds the incremental pass to the full pass. - Measurements were taken on
831b820. The commit message says the redesign raised a row-only pass from about 5 to 22 ms at 1,024 sections, because seating every row is quadratic again. So the table and the "18 ms for the send's two passes" figure are from before that change. Re-running the bench on the head, or saying which numbers predate the redesign, would keep the table accurate.
A page pin's cover counts the words a neighbouring scrolling pane shows, and a pane's scroll dropped no record, so the next pass for the rows alone seated the pin from its stale cover: on the review's page it stayed over words the pane had scrolled under it, at (1367, 153), where main and a full pass stand it at (225, 183). A scroll in any box inside the page short of the document, outside Leaf's chrome, now clears every record. A transition or animation ending can carry words under a pin the same way, after the pass its start brought read them where they started: a probe with a transform transition and a keyframe animation each left a pin over words a full pass moved off (1367 against 303 and 247 px). The handler both feed already reads the rows under the moving box again; it now clears every record too. Measured first: the review's asks journey (four sends and a resolve at 256 sections) ends no transition or animation outside the chrome, so it keeps the same 2,553 rows from their records, and sweeping the pointer and wheel down five pages ended 0 to 4, all on Leaf's own controls in the page. The comparison test gains a pane-scroll step and a transition step; each fails without its clear. `hearFaces`, the check a pass runs first, is now `takeFaceRecords`, apart from the observer's `heardFaces`. Claude-Session: https://claude.ai/code/session_01GQAnFBpRfi8Gh5cgPofNzs
leaf-agent
left a comment
There was a problem hiding this comment.
The pane-scroll and motion-end clears close the two cases the re-review found. The same gap remains for page content that changes without moving any box the margin watches. In heardPage, records are dropped only for an attributes record or a record whose target is in wantedGeometry, which holds a target's ancestors and their siblings. pageChanges doesn't observe characterData at all. So suppose a widget swaps the words in a nested element of a fixed-height card beside a pin: the record's target is that nested element, nothing watched resizes, and the kept pin's coverIn reading still counts the words that used to be there. A Lit text binding updates in place (node.data = …), so the same happens with no record at all. The next pass that touches only the rows (a send, a resolve) then seats that pin from its stale cover. Main reads every row on that pass and gets it right. This is the same mechanism as the pane case: words beside a pin change while no event the margin listens to fires.
This is the third case of one kind. A record stays valid unless one of a fixed list of events clears it, and each review has found another event to add to the list. The cover a record holds depends on any change to the page outside the margin, so the clear could key on exactly that: drop every record on any pageChanges record not on the surface, with characterData observed too. The asks bench would then show whether the send and the server's reading still keep their records. If they do, the scroll and motion-end clears remain the only special cases. If they don't, it's worth knowing which page mutations the send causes before committing to the list.
leaf-agent
left a comment
There was a problem hiding this comment.
The earlier draft review's point still stands at this head and isn't blocking. A text or nested child-list change beside a kept pin drops no record, so the next row-only pass seats that pin from its old cover. Main doesn't hear those changes either until some later pass runs. Making the margin hear page text changes is #5752's work, and this design leaves that fix as easy as before: such a change only needs to clear seatings.
… row (#5818) Resolving a thread no longer restyles every element of the page, and sending a comment no longer restyles every margin row. On the generated asks page at 1,024 sections in Chromium, Resolve's style work drops from 841 ms to 16 ms in a profiled run, and Send's from 125 ms to 39 ms. ## Why Profiling the margin on the generated asks page found two restyles whose cost grew with the page, separate from #5817's margin work: - **Resolve** forced one style recalc of 185,554 elements (744 ms) at 1,024 sections, read by `landingBand` in `reading-regions.js`'s `pageGeometry`. - **Send** restyled every margin row, first under `holdSelection`'s read of the selection (46 ms) and again under `marginColumn` (6,176 elements). ## Causes Neither restyle came from the code that read the style. Each read forced a recalc that an earlier DOM write had made large; Chromium's invalidation tracking names the writes. **Resolve.** Resolve closes the card and returns focus to the thread's passage. `paintFocus` (focus.js) marks every ancestor of the focused element `data-lf-focus-within`: the paragraph, its section, the article and `main`. reading.css's fade beside a table's sticky row names is keyed on that mark: ```css &[data-lf-more-before]:not([data-lf-focus-within]) > * > tr > :first-child::after ``` Its last compound names no type, class, id or attribute, so when the mark changes on an element, Chromium restyles every element under it. With `main` marked, that is the whole page. `landingBand`'s `getComputedStyle(root)` was the next style read in the frame, so it paid the recalc. The `data-lf-floating-editor` attribute and the `calc(0 * var(--lf-landing-top))` padding from #5580 play no part. With the rule dropped, the same mark change restyled 980 elements on a 40-section page instead of 7,185. That residual has a second cause, on pages whose `main` carries a column Layout (the asks page has none, so the bench doesn't show it). Every restyle of `main` restyled the boxes under it, even a restyle that changed nothing: 246 elements at 10 sections, and 6 with the room set to a constant. The column's room, `--lf-free-start` and `--lf-free-end` in layouts.css, is a length less a percentage registered as `<length-percentage>`, and Chromium 158 counts that value as changed each time it is recomputed. A plain page reproduces it: a no-op restyle of a parent declaring `--free: calc(10px - 50%)` restyles all 200 children; with a plain length, a plain percentage or `syntax: "*"`, it restyles the parent alone. Focus marking `main` restyles it, so on a column page Resolve still restyled the whole column. **Send.** The frame-edge rules in reading.css are bare compounds: ```css :nth-child(1 of :not(.lf-ui, [data-lf-gen])) :nth-last-child(1 of :not(.lf-ui, [data-lf-gen])) ``` Chromium matches them against every element, whether or not the frame's container query holds. Once it has evaluated `:nth-child()` for a parent's children, it restyles all of them whenever a child is inserted or removed. Send removes the comment's row from the margin toolbar and inserts the thread's row, so every row in the toolbar was restyled, and Resolve's removal of the row did the same. `holdSelection`'s read of `rangeCount` was the first read after the insertion. ## Fix All three are CSS changes at the rule that owns the invalidation: - reading.css: the row-name fade and its `data-lf-more-before` background rule end in `:where(th, td):first-child`, so a mark on an ancestor restyles only first cells. `:where` keeps the rules' specificity. - layouts.css: the column computes its room in two new non-inheriting `<length-percentage>` properties, `--lf-room-start` and `--lf-room-end`, so every unit in it (the shell's `cqi`, and a page's `--col`, `--col-pad` or `--aside` in `ch`, `em` or `rem`) resolves on the column, as on main. It passes the result to its children in `--lf-free-*`, now registered `syntax: "*"`, so children inherit a fixed expression of lengths and a percentage that Chromium compares by value, and each reader resolves the percentage against its own containing block, as before. A non-inheriting value that Chromium counts as changed restyles only the column. notes/browser-support.md records the engine gap and how to recheck it. The comment on the reset rule after it (#5609) loses its performance reason, which was the same gap, and keeps its job: without the reset, a flow inside a plain wrapper breaks out of the wrapper ([168, 888] becomes [24, 1416]). - reading.css: the frame-edge rules check `:where(:not(.lf-ui, [data-lf-gen]))` before `:nth-child()`. Chromium stops at the first failing part of the compound, so it never evaluates the position for chrome, and the toolbar is no longer marked. `:where` keeps the specificity: a plain `:not()` raised it and beat a `margin-bottom: -15px` on the pr-walkthrough diagram, which `leaf-dev stills` caught. `landingBand` and `holdSelection` are unchanged. With the invalidations fixed, `landingBand`'s read restyles 25 elements at 1,024 sections, and `holdSelection`'s read no longer appears among the forced recalcs. ## Before and after `uv run leaf-dev bench asks --sizes 256,1024 --input resolve --input comment --rounds 2 --base origin/main` at the head with the review fix (96f89a5), interleaved, lowest of two rounds, load average 4.0 at the start and 3.1 at the end: | reading | 256 main | 256 this | 1,024 main | 1,024 this | |---|---|---|---|---| | resolve, main-thread CPU ms | 321.9 | 155.0 | 1,162.9 | 480.7 | | resolve, input to painted ms | 243.9 | 134.2 | 900.9 | 244.2 | | resolve, input to server's reading shown ms | 305.7 | 134.2 | 1,131.8 | 461.9 | | comment send, main-thread CPU ms | 153.0 | 143.6 | 478.7 | 440.0 | | comment send, input to server's reading shown ms | 158.7 | 154.5 | 497.3 | 453.8 | The first commit's three-round run read the same within a few percent (resolve painted 897.5 → 244.0 ms at 1,024 sections). At 1,024 sections, the forced style and layout in the long frames after Resolve fell from 644 ms to 6 ms. Send's gain is the row restyle alone (about 40 ms); the rest of its time is script the profile attributes elsewhere, and both inputs still take over 100 ms to show the server's reading at 1,024 sections. A profiled run of head at 1,024 sections, against the profile that found the problem: | | before | after | |---|---|---| | Resolve, style ms (forced) | 841 (797) | 16 (14) | | Resolve, largest forced recalc | 185,554 elements, `landingBand` | 222 elements, card close | | Send, style ms (forced) | 125 (78) | 39 (35) | | Send, recalc under `marginColumn` | 6,176 elements | 38 elements | | `holdSelection` self time | 45 ms | not in the top functions | The column-Layout cause doesn't show in the bench, whose page has no Layout. The new resolve test reads it: with `--lf-free-*` registered `<length-percentage>` again, a page of 24 sections restyles 120 more elements than one of 4. ## Tests Two tests in `tests/browser/test_chrome_contracts.py`, beside #5580's floating-editor test, count the elements Chromium restyles for one input on pages of 4 and 24 sections of questions in a column page's article, and fail if the larger page restyles 10 or more elements more. They run with reduced motion, so the card doesn't ease in over a host-dependent number of frames, and without the shift watch, whose cameras inserted into the chrome are restyles of their own. With all fixes the counts are equal at both sizes. | test | with the fixes (4 → 24) | fails without | |---|---|---| | `test_sending_a_comment_restyles_only_the_rows_it_changes` | 2,147 → 2,147 | the frame-edge guard: 2,150 → 2,170 | | `test_resolving_a_thread_restyles_what_focus_marks` | 1,178 → 1,178 | the row-name types: 1,894 → 4,294; `--lf-free-*` registered `<length-percentage>`: 1,196 → 1,316; the frame-edge guard: 1,181 → 1,201 | A third test, `test_a_column_stated_in_font_units_gives_every_breakout_the_same_room` in `tests/browser/test_render_pages.py`, holds the room's units to the column. On a column page and a sidebar page with `:root { --col: 50ch; --col-pad: 2em; }` at 1600px, three blocks that break out, in the page's font, a 10px monospace font and 24px, must reach the same edges, and the page must not scroll sideways. It passes in Chromium, Firefox and WebKit, and failed in all six cases on this branch's first commit, which registered the room `*` without resolving it on the column: the column page's blocks stood at [20, 1580] and [48, 1552] beside [34, 1566], and the sidebar page's monospace block ran to 1738px. ## What I checked - The two restyle tests, and #5580's floating-editor restyle test, after the review fix as well. - 92 browser tests selected by `-k "resolv or landing or floating_editor or floating_comment or restyle"`: 90 pass. `test_a_resolve_s_notice_stands_for_that_resolve_alone` fails here with and without this change (main's CSS restored, by node id), so it is inherited. - 56 tests in `test_render_pages.py` that read the column's room (breakouts, notes, sidebar, tracks and the new font-unit test, `-k "breakout or room or note or sidebar or available or wide or column or track or font_units"`), on Chromium, Firefox and WebKit, and the two sticky row-name tests: all 58 pass. - On the first commit, `leaf-dev stills` for `breakout-captions-scrolled`, `table-scrolled-sideways`, `release-notes`, `pr-walkthrough`, `breakout-table-caption`, `sidebar-contents`, `gallery-wide-passage` and `proxy-note-paragraph`: 0 px changed. `table-scrolled-sideways` lists one DOM difference, the comment box's resting label; `leaf-dev probe` shows head without this change lacks it too, so it is capture timing. - `pnpm run test:runtime` (913 pass), and pre-commit on the changed files. An independent review re-ran `leaf-dev stills` on this head: 30 states in Chromium and WebKit, and 26 in Firefox, leaving out four that never settle in Firefox on main either. No state shows a layout change. One Firefox state, github-discoveries, shows glyph-edge raster differences (216 px, at most 26 of 255 levels) with every box and computed style identical. Not checked: Firefox and WebKit restyle counts (both fixes are Chromium invalidation behavior; the layout tests above hold the values in all three); the broad suite, which CI runs. ## Follow-up, not in this PR Each focus move still restyles about 6 elements for every block before the focused one, on a page whose blocks are `main`'s children: 92, 272 and 992 elements at 10, 40 and 160 blocks. Thirty `:has()` rules in 12 files name a focus mark (`data-lf-focus`, `data-lf-focus-visible` or `data-lf-focus-within`) in their argument, so Chromium starts a `:has()` invalidation walk on every focus move, and broad `:has()` subjects, such as `:has(> [data-lf-track])` in layouts.css among others, make that walk visit the preceding blocks. Fixing it means keeping focus marks out of `:has()` arguments or narrowing those subjects, a change across many rules. > _This was written by Claude Code on behalf of max-sixty_ https://claude.ai/code/session_01GQAnFBpRfi8Gh5cgPofNzs
…each margin row against only the rows beside it, and name a revealed code block's Copy key (#5866) 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 (#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 3b9ff64`: 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. #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.
Why
Sending a comment on a long page changes the margin's rows twice. The send adds the new thread's row before the next frame, and the server's reading about 80 ms later replaces it with the accepted thread's row (and on the generated asks page takes the section's question row away). Each change ran a pass that read every row again. Nearly all of that pass was each pin reading the words and controls around its target (
coverIn): profiled at 1,024 sections, the two passes took 520 ms, 402 ms of it inpinSeating, of which 149 ms was rebuilding the child index. RootAGENTS.md("Responsiveness") asks that an input's work depend on what it changes, not on how much the page holds.Design
Every pass seats every row in the one shared held-and-arrival order. What changes is how much it reads.
seatingsinmargin-layout.js) holds what the last pass read to seat it: its read, its home before any push, and a pin's prepared seats and cover, at that pass's scroll. A row with a record is seated from it, carried by the document's scroll since (shiftedPin). Any other row is read afresh, as before.lf-layout, a slot change, a window resize, a scroll whose stir reading flips a row, a scaled scroll ending. A scroll in any box inside the page other than the document, and a transition or animation ending outside Leaf's chrome, clear every record too. A change to one row (registered with another target, let go, or drawn at another size) drops only that row's record.So a pass for a change to the rows alone reads only the rows that change names and seats everything, and ends with every row where a pass that read them all would stand it. Before a pass, the margin first hears the face changes still waiting to be delivered, so a face drawn and laid out in one task is read at its new size.
Two smaller changes ride along:
:has()of every row: 1.4–2.1 ms → 0.4 ms at 1,024 sections.leaf-dev benchgains aresolveinput, which measures a row leaving besidecomment's row arriving.What the review found
An independent review confirmed the saving in Chromium and Firefox, and found two cases where the first version left rows where a full pass would not. Both now pass a test that fails on that version.
seatReach,packReach). After a hold ended, the released row moved later in the seating order, and the kept rows before it were never asked again, so a row stayed 30 px above its line. That reach was also a second statement of which rectanglesseatRowandpackRowtest, which every change to them would have had to keep in step. Fix: the reach is gone (−150 lines with its tests). Every pass seats every row, so the order and the occupied footprints are a full pass's by construction.application.js), before the face observer delivers. The pass's ownfaces.takeRecords()then discarded those records, so a pin grown from 31 to 62 px stayed past the window's right edge. Fix: a pass first runs the waiting records through the observer's handler and checks the restyled rows' sizes, dropping the record of each that changed. The review also tried re-reading every restyled row instead: that read 595 rows afresh rather than 28 and lost the saving.The two pieces of state the first version added fold into the one map. Clearing it replaces the "page moved" flag, and dropping a row's record replaces the set of unsettled rows.
The re-review confirmed both fixes in Chromium and Firefox. Its full-pass comparison showed no differences on the asks journey, a hide-and-show journey or 8 shipped examples, and the saving held. It found one new case, which main does not have:
Measurements
uptimefirst (load 2.6–3.0), thenuv run leaf-dev bench asks --sizes 64,256,1024 --input comment --input resolve --rounds 5 --base origin/main: Chromium, both arms interleaved in one run, head 611fec5 against main at 7d3a418. Each cell is the median of 5 rounds, with the range in brackets. Paint is from the input to the first frame showing its own result; shown is to the frame presenting the server's reading of it; CPU is the input's main-thread time.The pane and motion clears (9a65849) came after this run. They change no pass on these inputs: the bench scrolls no pane, and the asks journey ends no transition or animation outside the chrome, so it kept the same rows from their records with them. The re-review measured send paint at 172 → 122 ms at 256 sections and 555 → 353 ms at 1,024.
Against the first version, measured the same way, the send's paint saving is unchanged at 256 sections (51 → 53 ms, within noise) and goes from 231 to 199 ms at 1,024. Its CPU saving at 1,024 goes from 554 to 506 ms.
The resolve's paint at 64 sections is the one cell that reads slower, as it did for the first version. When the server's answer arrives before the resolve's first frame, the browser presents the reading in that same frame, so its paint equals its shown. A 7-round recheck of the first version found both arms doing this in 4 to 5 of 7 rounds at 8 and 32 sections. At 64 sections the branch did it in 6 of 7 and main in 3, because the reading's pass is now cheap enough to fit. At 128 sections neither did, and paint read 159 → 139 ms.
Cost of seating every row. Timed directly on the asks page through four sends and a resolve, a pass for the rows alone takes a median of 3.3 ms at 256 sections and 22 ms at 1,024. With the reach it took 1.8 and 5 ms in the review's timing. A full pass takes 52 and 223 ms.
Follow-up: index the occupied footprints. Seating every row grows with the square of the page, as the full pass always has.
seatRowcopies and scans every footprint already seated for each pin, which is also most of the 22 ms. Indexing the occupied footprints by height on the page, so each seating reads only those near its target, would take that out of both passes.Checked
test_a_pass_for_a_change_to_the_rows_seats_them_as_a_whole_pass_would(new,tests/browser/margin/test_pins.py). It compares every row with where a forced full pass stands it, after each of:Each fix has a step that fails without it. On the first version the test fails at "a hold ends" (line-1's row) and "a face grows at once" (the question's pin, 1397 → 1367 px). With the face records left unheard it fails at the face step alone. Without the pane-scroll clear it fails at the pane step, and without the transition-end clear at the transition step. It replaces the earlier pushed-row test, whose case is its "a row leaves" step.
The
shiftedPintest names every positional field of a pin, and fails for each of the seven fields left unshifted. The earlier test caught 3 of 7.pnpm run test:runtime(913 pass),pnpm run check:browser, pre-commit on every changed file.58 focused browser tests by name: rail, pin, cluster, entry, scroller and card-placement tests in
tests/browser/margin/, and the floating-panel, outbox, margin and send-placement tests that add, resolve or undo rows. After the pane and motion clears, 37 pane, scroll, transition and placement tests among them were run again.The same before-and-after comparison on four shipped examples (
release-notes,review-a-fix,rust-sort,pr-walkthrough). Each added rows by contribution, scrolled, added more, then took two batches away. No row moved under the forced full pass after any step.Not checked:
What remains of the send and resolve at 1,024 sections, from a profile of the first version, is outside this pass:
holdSelectionrestyling every margin row once (46 ms).landingBand(744 ms when profiled), which main has too.