Skip to content

Declare the margin's keys once, and group its rows by lane in one pass - #5367

Merged
max-sixty merged 3 commits into
mainfrom
margin-keys-once
Nov 4, 2026
Merged

max-sixty merged 3 commits into
mainfrom
margin-keys-once

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

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": 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

Every margin cluster declared the same commands as a scope of its own: 512 scopes on the
`asks` page at 512 sections. The keyboard runtime's reflection walks every scope's rows on
each pass, and the rows asked where the user is through computeds #5308 added so that
answer was worked out once per focus move rather than once per cluster.

The keys are now one scope on the projection `nav`, which 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: the `onSteppableEntry` and `onMarker` computeds in margin-projection.js and
`onOpener`'s in thread-preview.js, whose only purpose was sharing one answer among the
clusters' reflections; the rows read focus directly. `drawnMargin` and `cardRevision`
stay, since they keep the one reflection current when the margin renders or the card
opens while focus stays put.

Measured at 512 sections 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 |
|---|---|---|
| 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. Most of what 512 cluster scopes once cost a click had already gone with the
keyboard runtime's button index on main, so the change now buys less than an earlier
ablation on an older main suggested (a click's median 450 to 322 ms).
A render puts each host that is not yet in the document before the next later host
already in the toolbar. It found that host by slicing the rest of the inventory, mapping
every later entry to its host and searching the result, once per new host: on a first
render, where every host is new, a walk over the inventory for each entry, with an
array the size of the rest of the inventory each time.

Now the render reads every entry's next later host in the toolbar in one walk back over
the inventory, the first time it needs one. The answers hold for the whole render: a host
it puts in stands earlier in the inventory than any host it is read for, and hosts it
creates later did not exist when the old search ran either.

In a profile of loading the `asks` page at 512 sections, the search cost about 7 ms: 2.7 ms
in its mapping and most of the render loop's own 6 ms, which is 1.9 ms now.
To place rows, the layout pass grouped them by lane by filtering every row for each lane,
and searched the rows again for each lane's first. With a lane per independently
scrolling pane, a page with a row in each of 512 panes read a row's lane 394,496 times a
pass (review's count; 24,896 at 128), and a scroll of a pane can bring a pass.

Now one pass over the rows, in their order, gathers each lane's rows, and the lanes come
in the order of their first rows, as the sort by first index gave them. The lanes taken
are the same: the root lane, and each pane lane with frames this pass.
@max-sixty
max-sixty merged commit 484c3db into main Nov 4, 2026
4 checks passed
@max-sixty
max-sixty deleted the margin-keys-once branch November 4, 2026 12:35
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.

2 participants