Repository navigation
Lay out the margin only when something a row is seated by changed - #5308
Merged
Merged
Conversation
…eads, and answer the margin's focus questions once for every cluster Every margin render asked for a full margin layout pass twice over: `renderNow` called `scheduleMarginLayout()`, and so did `registerMarginRow` for every row it re-registered. A click renders the margin twice, once for the gesture and once for the server's reading, so it ran two passes. Each pass seats every row; on the `asks` page at 512 sections that took about 100 ms, with `coverIn` run for each pin. Neither render changed a row's target or the size of its face. A render now asks for a pass only where it changed something a seat reads: - `registerMarginRow` asks when a row is new, or names another target, point, passage or place in the order than it did when last registered. - A MutationObserver on the projection (`faces`) asks when a row gains or loses controls or text. When only an attribute in a row changed, such as a label or a hidden state, it measures the face on the next frame and asks only where the face no longer has the size the last pass seated it at. The pass's own writes to its rows are taken back at its end. - `renderNow` no longer asks. - The projection numbers each row among the rows, not among the inventory entries. A click adds an entry with no row of its own, which renumbered every later row. The margin's keys now answer where the user is once for all clusters. Every cluster declares the same rows, and three of them asked focus on every cluster: `margin.controls` (focus on an entry of a cluster with more than one), the marker walk (focus on a marker), and the card's `margin.card.enter` and `margin.card.over` (focus on the entry the open card hangs from). Each answer is now one computed that every cluster's reflection shares (`onSteppableEntry`, `onMarker`, the card's `onOpener`), as composing/input.js reads `focusedHere`. The answers follow `focusRevision`. The entries a cluster offers follow each render (`drawnMargin`). The entry the card hangs from follows the card opening, closing or moving (`cardRevision`); before, a plain variable held it, so a row reading it was read again only on a focus move. Where a keyboard reflection follows only what its rows read, as focus.js's `followingFocus` will make it, a focus move that leaves these answers unchanged re-reads no cluster. Each pass still seats every row the way it did before.
… root does not scroll Where the root does not scroll, the window bounds a pin's seat (`pinSeating` reads the layout viewport). The previous commit stopped every margin render from asking for a layout pass. A window shortened around a fixed-size canvas resizes no box the margin watches, so nothing asked for one any more, and a pin near the canvas's foot kept a seat half outside the window. Main's unconditional request from each render had covered this. The margin layout now asks for a pass on the window's own resize, in the module that reads the viewport. `test_a_pin_stays_inside_a_window_that_shrinks_around_a_fixed_canvas` shortens the window from 900 to 720 px through a pin at 700 px. It fails without this change (the pin's foot stays at 734 px) and passes on main and with it.
…s move, not each cluster's wakeup The comment claimed a focus move that leaves an answer unchanged reads no cluster's keys again. On main every scope's reflection follows `focusRevision` directly (keyboard/scopes.js), so each cluster still re-reads its keys on every focus move. With 512 clusters, moving focus between ordinary buttons makes 1,024 predicate reads. Sharing the answer saves working it out once per cluster; the selective wakeup needs reflections that follow only what their rows read.
# Conflicts: # dist/kernel/kernel.json # dist/kernel/runtime/bundle-annotation-overlay.js # dist/kernel/runtime/bundle-comment-placement.js
leaf-agent
approved these changes
Nov 4, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 4, 2026
…5359) After #5308, a margin render no longer asks for a layout pass, but a hover over a margin entry and a Tab still ran the whole pass, which seats every row. On the `asks` page at 512 sections a pass costs about 124 ms of main-thread time. The requests came from writes the runtime makes to page elements to paint them: the outline a margin entry's hover draws on its target, and the keys command hints show inside a widget. Neither moves a box a seat reads. This applies the rule in root [`AGENTS.md`, "Responsiveness"](https://github.com/max-sixty/leaf/blob/main/AGENTS.md#responsiveness): work a pass would redo for the whole page "runs only for the change that makes it necessary, which its owner records when the change happens". ## What changes **The runtime's marks stand where the margin's observer does not listen.** The aim, the trace a margin entry draws on its target, the proxy ring and the location ring are attributes (`data-lf-aimed`, `data-lf-traced`, `data-lf-proxied`, `data-lf-projected-location`) among the runtime's other paint attributes (`page-paint.js`), rather than classes, and the theme selects them (`surfaces.css`). The margin's page observer hears every change to a page box's class, style, `hidden` or `open`, an author's included, as on main. Design mode's legend ignores the mark attributes, as it ignored the classes they replace. The anchor names the runtime writes inline into a box's style are still heard: a heading the pointer first reaches runs a pass, as on main. Naming anchors without that pass, at a cost bounded by the boxes named, is a change of its own. **Leaf's own surfaces are no page content.** The page observer ignores changes inside the chrome and inside the seats command hints lend a widget for its keys (`.lf-binding-seat`). The pass's index of what a pin keeps clear of skips them too. A widget lends each key the box of the control it names, such as an option's mark or the Add button, and a pin already keeps clear of controls, so no pin stood over a key before this change or after it. Read as cover, though, a key showing on a focus move ran a pass that moved every pin beside the options by 2 to 3 pixels, and moved them back when focus left. Now the pins stay where they are. Checked in Chromium and Firefox. **A row's face asks only when its size could change.** An element added to or removed from a row asks for a pass. Text or an attribute changed in a row asks only where the row no longer measures the size the last pass seated it at. A control's label stands over the row, placed by its own pass, and asks for none. **A document scroll reads only the withheld rows.** The document carries every other row with its target, so the scroll reading now reads only the withheld rows, which the margin keeps where it withholds them. Before, it took every row's anchor and passage and climbed its ancestry, then skipped all but the withheld rows. The rows it reads, and the checks it makes of them, are unchanged. **A full pass reads each row's view of its target once**, keeping it on the row's reading for the seat check, and its index of children asks each child whether it is a Leaf surface instead of climbing its ancestors. **Naming the markers** reads each entry's place in the inventory from a map built once, instead of searching the inventory inside the sort's comparator. ## Evidence Margin layout passes counted in one probe journey on the `asks` page at 512 sections. Main is ecf4dc1, with #5308. | input | main | this branch | |---|---|---| | 10 wheel steps | 1 | 1 | | 10 hovers over headings | 4 | 4 | | 6 hovers over margin markers | 3 | 0 | | 6 Tabs | 3 | 0 | | 10 keystrokes in the panel's field | 0 | 0 | The wheel steps and heading hovers run passes on both arms when a heading first takes the anchor name its link stands by. Reading each row's view of its target once took one full pass at 512 sections from 131 to 124 ms (minimum of 12, with both arms open and measured in alternation). Measured the same way against main at a host load of 57 to 82, on the branch's first two commits, a click on an option at 512 sections went from 605 to 473 ms and a Tab from 419 to 375 ms (minimums). On this host per-input times swing by half between runs, so the pass counts are the firmer measure. ## Checks - Every margin row's place, coordinates and withheld state equal main's at every step of journeys on six pages, compared with `leaf-dev probe --base`: 43 steps in all, covering load, content inserted, shrunk and removed above every row, a target growing a line, a resize round trip, and stacked rail rows whose targets are hidden and shown with and without the pointer holding a row. Pages: a 64-section `asks` page, a 24-section threads page, a page of stacked rail threads, `ship-review`, `review-a-plan` and `log-retention`. - `test_a_control_an_authored_anchor_name_moves_into_a_pin_s_seat_moves_the_pin` hands an anchor name between two boxes of the same size, which carries a button onto a pin, and the pin moves clear. - `test_a_page_s_reaction_to_a_runtime_mark_moves_a_pin_clear` has a custom element move a button onto a pin in the same task the margin's trace marks it: by a restyle, by a class whose words a no-break space runs together, and by an anchor name handed to a box on the pin. The pin moves clear each time. - `test_a_row_in_content_skipped_until_near_stands_once_the_page_scrolls_to_it` scrolls a section of fixed height with `content-visibility: auto` into the window, and its row stands. - `test_an_option_s_key_moves_no_pin_and_stands_under_none` shows the keys with a pin by each option card and forces a pass. It fails on main, where the pins move 3 pixels, and passes on this branch. - 124 margin browser tests by name pass, with the four that read the markers' names, the 49 that read a mark, and the tests of code copy, anchored drawings and their pictures. Three fail here and on main at ecf4dc1 alike: `test_an_aimed_comment_keeps_its_place_with_on_me_open` (both widths), `test_a_heading_copies_the_link_to_the_section_it_opens`, and, in three runs of four on each, `test_a_commented_block_says_so_to_a_screen_user`. - `pnpm run test:runtime` passes 776 tests, and the browser type check passes. > _This was written by Claude Code on behalf of max-sixty_
max-sixty
added a commit
that referenced
this pull request
Nov 4, 2026
#5367) Every margin cluster declared the same keyboard commands as a scope of its own, 512 scopes on the `asks` page at 512 sections, and #5308 added computeds so the rows' questions about where the user is were answered once per focus move rather than once per cluster. The keys are now one scope on the margin's projection, and those computeds are gone. Two loops over the margin's rows that searched them again for each member also run in one pass now. This follows root [`AGENTS.md`, "Responsiveness"](https://github.com/max-sixty/leaf/blob/main/AGENTS.md#responsiveness): an input's work depends on what it changes, and a step that walks one of the page's collections for each member of another grows with the square of the page. ## What changes **One scope on the projection.** The margin's keys (moving through a cluster's entries, the marker walk, and Tab into and back past the thread card from its entry) are declared once, on the projection `nav`, instead of on every cluster. The projection holds every cluster in every lane, since a pane's lane is inserted beside the root lane inside it (`margin-layout.js`, `laneFor`). Nothing between a cluster and the projection declares keys, so a press on an entry or a marker reaches the same rows as before. The thread card stands outside the projection with its own scope and is unchanged. `aria-keyshortcuts` moves with the scope, from each cluster to the projection, since the keyboard runtime writes it on the element that declares a scope. That is a choice: a screen reader announces the shortcuts of the focused element, an entry or a marker, and the cluster and the projection are both its ancestors, so a reader hears the same either way. **Deleted bookkeeping.** The `onSteppableEntry` and `onMarker` computeds in `margin-projection.js` and `onOpener`'s computed in `thread-preview.js` existed to share one answer among the clusters' reflections; the rows now read focus directly. `drawnMargin` and `cardRevision` stay: they keep the one reflection current when the margin renders, or the card opens, while focus stays put. **Where a new margin host goes.** A render puts each host not yet in the document before the next later host already in the toolbar. It found that host by slicing, mapping and searching the rest of the inventory once per new host; on a first render, where every host is new, that walked the inventory for each entry. It now reads every entry's next host in one walk back over the inventory, the first time the render needs one. **The rows of each lane.** The layout pass grouped rows by lane by filtering every row for each lane and searching again for each lane's first row. With a row in each of 512 independently scrolling panes that was 394,496 lane reads a pass, and a pane's scroll can bring a pass. One pass over the rows now gathers each lane's rows, with the lanes in the order of their first rows as before. ## Evidence Measured at 512 sections on the `asks` page against main at 9328f61, both arms open and measured in alternation (minimum and median of 6 clicks, 18 Tabs and 18 walk steps): | input | main | this branch | |---|---|---| | click on an option | 248 / 419 ms | 219 / 404 ms | | Tab | 90 / 222 ms | 170 / 192 ms | | step of the marker walk | 132 / 582 ms | 223 / 599 ms | In a profile of 5 clicks, the keyboard's reflection of buttons per click went from 38 to 30 ms, of which reading every scope's declarations (`buttonDeclarations`) went from 28 to 21 ms. The keyboard runtime's button index on main had already removed most of what 512 cluster scopes once cost a click, so the change lands for its deletions, with the click's ~30 ms as a bonus. In a profile of loading the page, the host insertion search cost about 7 ms, which is now too small to show. A click's remaining margin work at 512 is the projection redrawing every host on every render (`renderNow`, about 44 ms) and presenting each of the 1,024 entries again (`presentContributionEntry`, about 8 ms). Skipping unchanged hosts needs the inventory to keep each unchanged entry's identity, which is a change of its own. ## Checks - Every margin row's place, coordinates and withheld state equal main's at every step of journeys on six pages, compared with `leaf-dev probe --base`: 43 steps covering load, content inserted, shrunk and removed above every row, a target growing a line, a resize round trip, and stacked rail rows whose targets are hidden and shown with and without the pointer holding a row. - The insertion walk matched the old search across 390,806 inventory shapes in review, multiple additions and moved entries included. - 124 margin browser tests by name pass, with the four that read the markers' names and six keyboard tests that reach the margin's keys: the marker's way back onto the page, key repeat on walks, `g` hints on margin entries, keyed reconciliation of the Page Map, a live version keeping the user on the same margin location, and the card following its entry in the Tab order. `test_an_acknowledgment_uses_status_until_an_active_claim_restores_a_disclosure` fails here and on main alike. - `pnpm run test:runtime` passes 781 tests, and the browser type check passes. > _This was written by Claude Code on behalf of max-sixty_
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A click on a large page ran the whole margin layout twice, though nothing in the margin had changed. Every margin render asked for a full layout pass:
renderNowasked once, andregisterMarginRowasked again for every row it re-registered. A click renders the margin twice, once for the gesture and once for the server's reading. Each pass seats every row, which on theaskspage at 512 sections took about 100 ms, mostlycoverInfor each pin.This applies the rule in root
AGENTS.md, "Responsiveness", in the form adopted for the large-page work: work a pass would redo for the whole page "runs only for the change that makes it necessary, which its owner records when the change happens".What changes
A margin render now asks for a pass only where it changed something a seat reads:
registerMarginRowasks when a row is new, or names another target, point, passage or place in the order than when it was last registered.faces) asks when a row gains or loses controls or text. Where only an attribute in a row changed, such as a label or a hidden state, it measures the row on the next frame and asks only if the size differs from the size the last pass seated it at. The observer discards the pass's own writes at the end of each pass.renderNowno longer asks.The margin's keys now answer where the user is once for all clusters. Every cluster declares the same rows, and three of them asked
focused()on every cluster:margin.controls, the marker walk, and the card'smargin.card.enterandmargin.card.over. Each answer is now one computed shared by every cluster's reflection, ascomposing/input.jsdoes withfocusedHere, so it is worked out once per focus move instead of once per cluster. On main every scope's reflection still followsfocusRevision, so each cluster still re-reads its keys on every focus move. The entry the open card hangs from is now a version signal (cardRevision) instead of a plain variable.Each pass still seats every row exactly as before. Only when a pass runs has changed.
Evidence
Margin layout passes counted in the same probe journey on the
askspage, before and after:The Tabs' passes come from page attribute writes heard at the mutation checkpoint, on both arms. This change leaves them alone.
Main-thread CPU per click on the
askspage, from oneleaf-dev scaling --baserun. The host's load was about 40, so only comparisons within the run hold.The shared focus answers pay off once keyboard reflections follow only what their rows read (focus.js
followingFocus, on the keyboard branch). With that branch's source applied, a profile at 512 sections showed per-Tab cluster reflections fall from about 9 ms to 0.5 ms (reflectKeys9.1 → 0.3 ms,reflectElementShortcuts8.3 → 0.5 ms).Checks
leaf-dev probe --baseat every step of several journeys: load; content inserted, shrunk and removed above every row; a target growing a line; a resize round trip; and stacked rail rows whose targets are hidden and shown, with and without the pointer holding a row. Pages: a 64-sectionaskspage, a 24-section threads page, a page of stacked rail threads,ship-review,review-a-planandlog-retention.test_a_pin_stays_inside_a_window_that_shrinks_around_a_fixed_canvasshortens the window from 900 to 720 px through a pin standing at 700 px. It fails without the resize request and passes on main and on this branch.pnpm run test:runtimepasses 764 tests, andpnpm run check:browserpasses.