Skip to content

Move a quoted margin row with the page's scroll in the task that scrolls - #5225

Merged
max-sixty merged 5 commits into
mainfrom
grind/marker-lag
Nov 3, 2026
Merged

max-sixty merged 5 commits into
mainfrom
grind/marker-lag

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

A margin row quoting a passage now stands in the root lane wherever the page's own scroll is the only thing moving its words, as rows on whole elements already did, so a script finds the row where it is drawn in the same task as a scroll. Every row is also placed again once a CSS transition or animation that moved its words or its element ends.

What this buys, and what it doesn't. Real users saw nothing wrong on main. A real tap or click on the marker three frames after a scroll reached it in 12 of 12 runs, and an independent review's recordings show the painted marker within ±1 px of its words on both arms, smooth scroll included. The gain is for scripts, which on main read the row at its old place until the next frame rendered. That includes Playwright's actions: #5120's reviewer saw a tap aimed in that window scroll to the old place and miss. It also covers probes and the suite, and it leaves fewer position: fixed carriers on a page. The transition re-placement is a gain for users. A row on an element whose transition moved it 160 px stayed 160 px off on main until some unrelated pass ran, and so did a quoted row in Firefox; both now stand on their words once the transition ends.

Cause. #3091 put every quoted row in a carrier anchored to its words, so the row would follow words that a box inside the target scrolls. It did that for every passage, including words that only the document scrolls. A carrier takes up a script's scroll only as the next frame renders: css-anchor-position-1 updates anchor positions once a frame. Chromium also caches an elementFromPoint answer given in that window, for 23 to 28 more frames.

Change. carrierAnchor takes the passage's words as the row's subject, by the rule rows on elements follow:

  • A row whose words sit in a pane, an inner scroller, or inside a sticky or fixed box keeps a carrier anchored to its words.
  • A row under a sticky header the page declares stands in a carrier anchored to the document's first box, as a row on an element does. Pages with such a header, an lf-tabs strip for instance, keep every row in a carrier, and this change doesn't reach them.
  • Every other row stands in the root lane.

Rows stand where they stood. On review-a-plan at 1440 × 900 and 390 × 844, and ship-review and release-notes at 1440 × 900, every row's rectangle matches main's.

The re-check that already runs, once a frame, when a box inside the page scrolls and when a transition or animation ends asked only whether each row under that box still shows. It now also places a row again when its subject, the words or element it stands by, has moved from where the last pass stood the row by it (subjectMoved). The re-check measures that against whatever carries the row, so it covers rows in carriers too.

A trade-off Max may reverse. In Chromium and WebKit, a carrier anchored to the words carried a quoted row along while a transform moved them. In the root lane the row trails a running transform and lands at its end, as rows on elements always have. The decision and the rejected alternative are recorded in carrierAnchor's comment. Two cases stay off, as rows on elements already are on both arms:

  • A scroll-driven animation fires no end event. Its quoted row ends 39 px off in Chromium and WebKit until the next pass, where main left it 16 px off.
  • A Web Animations motion (element.animate) fires no end event either, so subjectMoved never sees it. In the review, with a held animation in Chromium, main's quoted row followed its words and this branch's stays 160 px off until the next pass, as element rows already do on both arms. lf-deck flights land right on both arms only because the deck's put-away step writes a style at the end of the flight, which brings a pass. A quoted row and an element row on the card Back brings in measured the same on both arms, during the flight and at rest, in all three engines.

subjectMoved also runs in the existing once-a-frame reading of a scroll inside a box, not only when a transition ends. In Firefox, inside a scaled box, that changes what a smooth scroll does. Firefox carries an anchored row by the scroll's layout distance, not the distance the words move on screen. On main the row drifted up to 48 px and was placed once at scrollend. Now the re-check finds the words leaving it and places it again during the scroll: 26 passes over 72 frames, the row within 7 px of its words, and no frame over 15 ms on a four-row page. The scrollend pass stays, since WebKit is 24 px off without it. By the code's reading, WebKit's measured anchor moves with the words, so its rows still drift until scrollend; that is not measured. The stir comment, the css-anchors.js header and the scaled-scroll entry in notes/browser-support.md now say so.

Evidence. The scroll measure loads review-a-plan at 390 × 844 with touch and reduced motion, and scrolls the marker to a third of the window. It then counts the frames until the marker's box, and a hit test at one point where the marker is drawn, have caught up. 0 means they were right in the task that scrolled. Five runs per cell, main and this branch back to back:

engine main: box main: hit test this branch
Chromium 156.0.8078.4 2 frames late 23–28 frames late 0 for both
Firefox 157 2 2 0 for both
WebKit 27.2 1 0 0 for both

The transform measure, at 1440 × 900, is the offset of each row from where a fresh pass stands it, at rest after a 160 px transition. It uses the reviewer's page with its quoted row (moving) and element row (mover), run with leaf-dev probe --journey --base=origin/main:

engine main: quoted main: element this branch: quoted this branch: element
Chromium 0 160 0 0
Firefox 160 160 0 0
WebKit 0 160 0 0

During the 500 ms transition, the quoted row in Chromium trailed by up to 160 px on this branch, where main kept it on the words; WebKit and Firefox trailed on both arms.

Tests.

  • test_a_passage_s_row_moves_with_the_page_s_scroll_in_the_task_that_scrolls scrolls a quoted row into view and reads, in the same task, its offset from its words and whether elementFromPoint where it is drawn finds it, for a pin at 390 px and a rail row at 1440 px. On main both cases fail: the box is still 3727 px and 1374 px from its words.
  • test_rows_stand_by_words_a_transition_moved_once_it_ends moves a box 160 px by a CSS transition and reads, two frames after transitionend, where the quoted row and the element row stand. On main the element row fails, 160 px off. Without subjectMoved both fail.
  • test_the_rail_tab_stop_follows_a_carried_row_back_into_view needs a row that stands in a carrier. ship-review's first row no longer does, so the test now builds one on a line a box scrolls sideways; the behaviour it protects is unchanged.
  • notes/browser-support.md records Chromium's cached elementFromPoint answer, with the evidence that real input isn't affected, under "A cached elementFromPoint answer in Chromium". Rows in carriers keep it.

Ran:

  • the three tests above against main, the branch without subjectMoved, and this branch;
  • 53 tests in tests/browser/margin/test_scrollers.py selected for carriers, panes, passages, code blocks, scaled and widened boxes, sticky cuts and transitions;
  • 13 tests asserting that a scroll writes nothing or reflows nothing;
  • 26 more on quoted rows, cards on shipped examples, comment marks and the smoke tests;
  • pnpm run test:runtime (753 passed), pnpm run build:browser, pnpm run check:browser, and pre-commit on the changed files.

Not verified: the iOS simulator; and the journeys tier and corpus render gate, which landing runs.

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

max-sixty and others added 3 commits November 3, 2026 10:30
… scrolls

A margin row quoting a passage now stands in the root lane wherever the
page's own scroll is the only thing moving its words, as rows on whole
elements already did. #3091 put every quoted row in an anchored
`position: fixed` carrier, so the row would follow words a box inside its
target scrolls. A carrier moves with a script's scroll only once the next
frame renders, so a script reading the row in between found its box, and
its hit testing, at the old place.

`carrierAnchor` now takes the passage's words as the row's subject, by
the rule rows on elements follow: a carrier anchored to the words, as
before, where a pane, an inner scroller or a sticky or fixed box moves
them, and the root lane otherwise. Rows stand where they stood; only the
lane holding them changes.

On `review-a-plan` at 390 x 844, after an instant `scrollBy` brought the
`plan-stop` marker to a third of the window, main read its box at the old
place for 2 frames in Chromium 156 and Firefox 157 and 1 in WebKit 27.2,
and Chromium kept answering `elementFromPoint` at a point tested in that
window from the stale reading for 23 to 28 frames. With this change all
three engines read the box and hit-test the marker in the task that
scrolled, in every run.

`test_a_passage_s_row_moves_with_the_page_s_scroll_in_the_task_that_scrolls`
fails on main for a pin at 390 px and a rail row at 1440 px.
`test_the_rail_tab_stop_follows_a_carried_row_back_into_view` builds its
carried row on a line a box scrolls sideways, since ship-review's first
row no longer stands in a carrier.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed them ends

Moving quoted rows into the root lane gave up what an anchored carrier
did in Chromium and WebKit: carry the row with a transform moving its
words. After a 160 px transition, a quoted row stood 160 px off its
words until some unrelated pass, as a row on an element always had in
every engine, and a quoted row in Firefox.

The re-check that runs when a CSS transition or animation ends asked
only whether each row under the moved box still shows. It now also
places a row again when its subject, the words or element it stands by,
has moved from where the last pass stood the row by it, measured from
whatever carries the row (`subjectMoved`). On the reviewer's page, at
rest after the transition, the quoted and the element row now stand 0 px
from where a fresh pass stands them in Chromium, Firefox and WebKit,
where main left the element row 160 px off in all three and the quoted
row 160 px off in Firefox. While the transform runs, a quoted row in
Chromium now trails it, as WebKit's and every element row already did.
A scroll-driven animation fires no end event, so its rows stay off until
the next pass on both arms; `lf-deck` flights measure the same on both.

`carrierAnchor`'s comment records the root lane as a decision against
anchoring every passage's carrier to its words, and drops the half
second Chromium's cached `elementFromPoint` lasts for the note, which
now records that cache as Chromium's behaviour rather than treating the
once-a-frame anchor update the spec sets as a gap.
`test_rows_stand_by_words_a_transition_moved_once_it_ends` fails on main
for the element row and without `subjectMoved` for both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…led box

`subjectMoved` runs in the once-a-frame reading of a scroll inside a box
as well as when a transition or animation ends. In Firefox, whose
anchors `anchorBox` measures without their transforms, a smooth scroll
inside a scaled box now places a row again while it runs: 26 passes over
72 frames held the row within 7 px of its words, where main let it drift
up to 48 px until `scrollend`, with no frame over 15 ms on a four-row
page. The stir comment, the `css-anchors.js` header and the scaled-scroll
entry in `notes/browser-support.md` said rows drift until `scrollend`;
they now say what each engine does. `carrierAnchor`'s comment also names
that a Web Animations motion fires no end event, so its rows wait for the
owner's next pass. No behaviour changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@max-sixty
max-sixty marked this pull request as ready for review November 3, 2026 21:35
leaf-agent
leaf-agent previously approved these changes Nov 3, 2026
leaf-agent
leaf-agent previously approved these changes Nov 3, 2026
@max-sixty
max-sixty merged commit 10431f6 into main Nov 3, 2026
4 checks passed
@max-sixty
max-sixty deleted the grind/marker-lag branch November 3, 2026 22:29
max-sixty added a commit that referenced this pull request Nov 3, 2026
The kernel is rebuilt from the merged sources. #5225 added each row's `subject` to the
margin layout's final loop, reading `scrollX` there. That loop now reads the window's
scroll once before it writes any row, so the subject reads that value too, as the
loop's other coordinates do. Reading `scrollX` after a row's write would lay the page
out again, once per row.
max-sixty added a commit that referenced this pull request Nov 4, 2026
… the history it lacks, and fail superlinear growth daily (#5271)

#5252 wrote the rule into root `AGENTS.md`, "Responsiveness": no cost of
a large page grows faster than the page. It also fixed the paths that
broke the rule worst. This PR fixes the rest of what measurement and
review found, in the browser and on the server. It also sends each tab
only the history it lacks, and adds a daily test that fails any cost
whose growth passes n^1.5. Part of #5194.

## Browser

Five steps walked one page-size collection for each member of another:

- `coverIn` read every sibling's box for each margin pin. `pinSeating`
now reads each parent's children once per pass, sorted by top, with a
tree of the lowest bottom over each run. Each pin visits only the
children that reach into its band.
- The margin layout's last loop read positions after writing each row,
which forced a layout per row. It now reads every row first, then
writes. The merge with #5225 needed the same fix for its new `subject`
field.
- `hearTargetChanges` tested every row against every moved node. It now
collects the moved nodes once and climbs from each row's target.
- `obligationHolding` placed every obligation to find a node's. It now
climbs the node's ancestors through an index of where obligations sit
(`namedPlaces`).
- `claimPaintedRoots` climbed from every scoped element. It now walks
only the outermost painted roots.

On 512 questions (`leaf-dev scaling asks`, main and branch in one run),
main-thread CPU went:

| | main | this PR |
|---|---|---|
| click | 680 ms | 374 ms |
| keystroke | 16 ms | 8.5 ms |
| wheel step | 45 ms | 28 ms |

The keystroke's growth exponent went from 1.96 to flat. On this loaded
host one run can differ from the next by 2×. An earlier run measured
clicks at 1.6 s on main and 0.6 s here.

## Server

Each of these walked a collection once per member of another; each now
reads it once per reading. The table gives CPU seconds before → after on
generated pages:

| Path | Before → after |
|---|---|
| delivery batch: thread anchors, unsent work, `batch_threads` | 9.83 →
0.29 at 6,400 threads |
| `page_action_unsettled` (`PageSettlement`) | 3.94 → 0.24 at 3,200
asks; 25.2 → 0.08 for a board of 1,600 moved cards |
| `previously_requested` and conditional writes | 11.7 → 0.05 at 800
conditionals |
| board columns (`AuthoredOrders`, replacing `authored_positions`) |
3.43 → 0.04 at 800 boards |
| `record_members` | 1.12 → 0.15 for 800 picked groups |
| thread questions (`ThreadAnswers`) | 0.58 → 0.22 for 1,600 questions |
| `leaf page state PAGE THREAD` | 1.79 → 0.49 for 1,600 messages |

Every reading is byte-identical to the base on 28 pages, 13 of them
copies of real pages: `page_state()`, `delivery.batch_data`, `leaf page
state` at several limits, and two appends.

## History tail

A click's answer used to carry the whole history, so a session's traffic
grew with the square of its log. Now each answer carries
`browser.basis.key`, and the tab sends the key of the reading it holds
back as `Leaf-Held-Basis`. The server re-reads the history lists at that
sequence within the same page transaction. It sends what is new or
changed, plus `since.dropped`, and the browser completes the tail into a
whole reading before anything adopts it (`completeState`). The server
keeps no record of what each tab holds. A key it can't extend gets the
whole answer.

`state.schema.json` drops `receipts` and `coverage`, which the browser
now derives, and adds `browser.basis.key` and `since`. On 64 asks with
200 events, a click's answer goes from 664 KB to 30 KB. When the log has
moved, the server spends 4.5–8 ms more per answer. No protocol bump:
this changes the served state, not the log.

## Daily test

`tests/journeys/test_scaling.py` measures each `leaf-dev scaling` axis
at 8, 64, 128 and 256. It measures each size twice, interleaved, and
keeps the lower reading. It fails a cost whose growth above the
8-section page fits an exponent past 1.5. Fitting the cost itself, as
`leaf-dev scaling` first did, let fixed work hide growth: a click's 30
ms of fixed work plus 20/80/320 ms of quadratic work fitted 1.4. Fitting
its growth gives 2.0.

The test scored 0/45 false alarms on real readings taken at load 50. It
missed 14 of 36 injected 100 ms quadratics, where fitting the cost
missed 24. `leaf-dev scaling` uses the same `exponent` and the same
threshold. It measures the 8-section page every run, and its `!` marker
moves from 1.3 to 1.5.

## Review and tests

Four Codex reviews re-ran their own cases against each commit's parent
and found no behavioral difference. For the history tail, they covered
undo, pickup, revision changes, two tabs, refusals, a restart and
crossed answers. All of these pass:

- model tests (1,886);
- `pnpm run check`, including the runtime tests;
- the margin, On me and key-scope browser tests;
- the interact-server process tests;
- the daily test, on all three axes.

## Left out

- Four scans that walk one widget's members or one thread's history per
member, rather than the page. A move compares its column's order, a
selection searches its picked values, a batch checks each summary
against earlier ones, and a conditional's history scans state events per
revision.
- Button reflection, which rereads every declaration each frame. That
costs 9.5 ms per keystroke at 512 sections and grows linearly.
- A click on 512 threads still answers with about 1 MB, mostly threads,
workflows and obligations sent whole. That grows linearly with the page.

> _This was written by Claude Code on behalf of max-sixty_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants