Repository navigation
Draw a sent comment and a Resolve before the server's reading on a long page, and make a publication cost what it changed - #5899
Merged
Merged
Conversation
…ng page, and make a publication cost what it changed
On the 1,024-section page `leaf-dev bench` generates, a sent comment now draws in 94–98 ms in Chromium, from 122–132 ms on main, under the 100 ms root `AGENTS.md` ("Responsiveness") asks for, though not by much. A Resolve draws in 67–83 ms, from 131–136 ms; on main, every round applied the server's reading of it before the frame that drew it. The server's reading of a send shows at 176–193 ms, from 203–205 ms, and still misses 100 ms; what remains is listed at the end. The cost: on a small page the server's reading of a gesture shows about a frame later, as `shown` at 8 sections in the table below. In Firefox the send's main-thread time at 1,024 sections falls from 286 ms to 258, and a Resolve's from 171 to 148.
## Why
Timing the send at 1,024 sections on main (#5893's head) with timers around each step, unprofiled, the press's task took about 90 ms and the frame after it about 40:
| Work | ms at 1,024 |
| --- | ---: |
| Publishing the send (`publish`): rebuilding the whole effective state, comparing it with the last reading, and re-deriving every widget's selection | 15 |
| Recording the reading place on the send's focus move, in the press's task (`recordCurrentLocation` → `capturePlace`), a hit test that forced the page's layout midway through the task | 14 |
| Collecting the annotation inventory (`collectEntries`) | 9 |
| Forced style recalculations in the press's task, about half of them restyling the whole thread card (~220 elements) | 26 |
The server answers a send in about 50 ms at 1,024 sections, so its answer arrived while the press's task was still running. In some rounds the browser then ran the answer's task, about 50 ms of applying the reading, before the frame that would have drawn the message, so the message painted only with the server's reading. A Resolve at 1,024 did this in nearly every round.
## Changes
**A publication reads again only what it changed.** `derive` (framework/application.js) runs each step that reads the whole page — the view, the projection and its coverage, the thread fold, widget states, widget relations and the served obligations — through `keptReadings` (kept.js), so a step whose inputs are the same objects as last time hands back what it made then. `share` (framework/snapshot.js) remembers, for each subtree it replaced with an equal one, what it shared it as (`sharedAs`), and answers that subtree, met again against the same value, without reading it. Together, a publication about one thing costs what it changed rather than what the page holds. Every widget's selection now derives from one selection of the parts a widget reads (`select`'s new `from`), so a publication that moves none of them, such as a comment's, reads no widget again; before, each of the 1,024 asks re-read its inputs on every publication. The send's publication takes 3.6 ms, from 15.
**The focus place is recorded in the frame only.** `recordCurrentLocation` (version.js) recorded the reader's place both in the input's task and in the next frame. The record in the task read the page's layout midway through the task's writes, a forced layout of the whole page, only to cover a window resized in the same frame. A frame that resized already records nothing (`regionsSettled`), so a shift there restores the place recorded before the input. That record took 14 ms of the send's task; without it the task is about 8 ms shorter, since the task's next read of the page's layout now lays it out instead. The frame's record stays.
**A reading waits for the frame a gesture is owed.** `afterOwedFrame` (rendering.js) resolves once the frame the page has asked for has painted, or at once where none is asked for or the document draws nothing. While a gesture of the user's is unresolved, `applyState` (state-application.js) waits for it before adopting a reading, so the gesture's own result paints before the server's reading is applied. With no gesture in flight, as while the page loads or when the agent's news arrives, a reading is adopted as before: waiting there too drew an extra frame of the whole page during load, about 75 ms of main-thread time in Firefox at 1,024 sections. The cost: where the reading would have fitted before the gesture's frame, it shows one frame later, as for a Resolve at 8 sections (below).
**The thread card's bounds no longer restyle the whole card.** `measureThreadCard` and the card's fit wrote the card's width and height caps as custom properties (`--lf-thread-width`, `--lf-thread-min-width`, `--lf-thread-max-height`) that only the card itself read, but every element in the card inherited, so each fit restyled about 220 elements. They are now the card's own `max-width`, `min-width` and `max-height`. The transcript's fade lengths (`--lf-thread-fade-top`, `--lf-thread-fade-height`) are registered with `@property` as not inheriting, and the fade (`::after`) takes them with `inherit`, so a scroll of the transcript restyles the thread and its fade only. The send's task spends 18 ms in forced style and layout, from 25, by the bench's attribution below.
**The annotation inventory sorts each place once and names only outline targets.** Its sort read both nodes' ancestor chains and walked their siblings for every comparison; `renderedOrdering` (shadow-tree.js) reads each node's chain once and each parent's children once per sort, and `byRenderedOrder` uses it too. `outlineSubjectFor` checked, for every target, whether it was in the page's outline by scanning the outline, a walk of one collection per member of another; `outlineContexts` (thread/placement.js) counts the outline's labels once and reads a label only for a target in the outline, which is all the inventory used of it. Each obligation's row shares one reading of its words ("Waiting on me") rather than a copy per row.
## Measurements
Chromium, `uv run leaf-dev bench asks --sizes 256,1024 --input comment --input resolve --rounds 3 --base origin/main`, both arms interleaved, this branch against its merge base with main (#5875); load average 3.3 at the start and 2.7 at the end. Each cell is the lowest of 3 rounds, as the bench reports, with the range in brackets.
| Input | Sections | Paint, main → branch (ms) | Shown, main → branch (ms) | CPU, main → branch (ms) |
| --- | ---: | --- | --- | --- |
| Send | 8 | 50.3 [50.3–52.9] → 44.3 [44.3–80.5] | 75.0 [75.0–89.7] → 88.6 [88.6–97.9] | 76.9 [76.9–88.7] → 71.0 [71.0–75.3] |
| Send | 256 | 65.8 [65.8–69.2] → 53.4 [53.4–85.7] | 97.1 [97.1–120.3] → 102.8 [102.8–108.5] | 95.9 [95.9–99.3] → 85.7 [85.7–94.0] |
| Send | 1,024 | 121.7 [121.7–132.3] → 94.3 [94.3–98.4] | 203.0 [203.0–205.2] → 176.0 [176.0–193.3] | 191.0 [191.0–193.0] → 158.6 [158.6–162.2] |
| Resolve | 8 | 20.6 [20.6–52.2] → 23.6 [23.6–31.0] | 38.7 [38.7–52.2] → 50.1 [50.1–62.6] | 33.6 [33.6–52.4] → 51.5 [51.5–52.5] |
| Resolve | 256 | 35.5 [35.5–65.9] → 39.7 [39.7–50.2] | 56.9 [56.9–65.9] → 59.5 [59.5–71.4] | 72.5 [72.5–81.3] → 56.4 [56.4–78.3] |
| Resolve | 1,024 | 130.8 [130.8–136.4] → 67.0 [67.0–83.1] | 130.8 [130.8–136.4] → 129.1 [129.1–130.2] | 143.0 [143.0–150.4] → 117.0 [117.0–131.4] |
| Load | 1,024 | | | 4,378 [4,378–4,417] → 4,381 [4,381–4,418] |
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. Where main's paint equals its shown, the server's reading was applied before the gesture's frame. A Resolve's CPU at 8 sections reads either about 34 or about 52 ms in a round, on either arm across runs. The bench's long-frame attribution at 1,024 sections puts the send's own task at 58 ms of script (18 forced), from 86 (24 forced), and the frame after it at 35 ms, from 39; applying the server's reading now runs in its own task after that frame (`paintedOwed`).
Firefox, the same command with `--browser firefox`, which reads only main-thread CPU there; load average 2.8 at the start and 3.1 at the end.
| Input | Sections | CPU, main → branch (ms) |
| --- | ---: | --- |
| Send | 8 | 66.8 [66.8–71.6] → 64.5 [64.5–68.7] |
| Send | 256 | 122.5 [122.5–128.6] → 105.9 [105.9–111.3] |
| Send | 1,024 | 285.6 [285.6–315.8] → 257.7 [257.7–264.6] |
| Resolve | 8 | 48.5 [48.5–56.5] → 48.0 [48.0–49.9] |
| Resolve | 256 | 91.6 [91.6–113.0] → 96.1 [96.1–108.9] |
| Resolve | 1,024 | 170.8 [170.8–240.9] → 148.2 [148.2–215.8] |
| Load | 1,024 | 4,126 [4,126–4,234] → 4,107 [4,107–4,193] |
Firefox gains less than Chromium from these changes; I haven't profiled it to say why.
## What remains at 1,024 sections
Timed in the page on this branch at 1,024 sections, unprofiled and before rebasing onto #5875, these still grow with the page:
- **The margin pass** (`layoutMarginRows`), 9 ms in the frame against about 1.3 at 8 sections. A rows-only pass still visits every row: finding held rows by one selector over the whole layer, carrying each row's record, seating every row through `Footprints`, and writing every row's seat, together about 4.5 ms; and the send's new pin reads every child of `main` for its cover (`childIndex`), 1.5 ms. #5752 describes seating only the rows a change can move; the cover index could also be kept across rows-only passes, which by definition move nothing on the page.
- **The place record in the frame**, 6–7 ms. Most of it is anchoring the line at the landing edge (`lineAnchor` → `anchorForPassage`), which searches the page's text for that line's copies to choose its context; every focus move, scroll end and keystroke frame pays it. Computing the anchor only when a record is used, from the line's live nodes, would remove it. #5875, merged since this was profiled, changed that search, which I haven't re-profiled.
- **The annotation inventory**, 8 ms in the press's task: it still builds each obligation's group and entry on every collection. Keeping each group's entry by the record and target it came from would leave a collection the groups that changed.
- **The marker names**, 3–4 ms, left alone as #5893 explains.
- **The Tab stop** (`syncRoving`), 2 ms in the frame: it reads every marker's box to find the highest one in view.
- **Forced style recalculations on the thread card**, still about 20 ms of the press's task at every size. Two kinds restyle the whole card: focus marks on the card's ancestors (`data-lf-focus-within`, `data-lf-control-focus-visible`) match rules that set the inherited `--lf-ring-at`, and the card's `visibility`, which is inherited, is cleared once it is placed. Both are theme-wide patterns, which I left for a change that can check every surface they reach.
This change does not close #5752.
## Checked
- `pnpm run test:runtime` (963 pass), `pnpm run check` (which runs `check:browser`), pre-commit on every changed file.
- New runtime tests, each shown failing without its change: a publication that moves no widget's part reads no widget again (`framework-application.test.mjs`); a subtree shared before is answered from that sharing only against its value (`framework-snapshot.test.mjs`, which fails when the memo answers regardless of the current value); a task waiting on the frame already asked for runs once that frame has painted (`rendering.test.mjs`); a sort's ordering answers every pair as rendered order does (`page-walk-order.test.mjs`, which fails with the sibling order reversed).
- Browser tests, all passing but two: `margin/test_page_map.py`, `margin/test_entries.py`, `drafts/test_reading_place.py`, `margin/test_card_placement.py`, `margin/test_opening_threads.py`, `margin/test_card_reply.py`, `margin/test_pins.py`, `margin/test_rail.py`, `margin/test_clusters.py`, `threads/test_resolving.py`, `threads/test_layout.py` (whose `test_the_thread_card_opens_on_its_latest_message_under_its_own_name` reads the fade's box), `navigation/test_commenting.py`, `navigation/test_threads.py`, `navigation/test_obligation_walk.py`, `widgets/test_obligations.py`, `widgets/test_boards.py`, `test_render_options.py`, `test_render_application_boundary.py`, `test_render_semantic_news.py`, and `test_news_just_after_a_press_moves_nothing`. The two failures, `test_a_card_s_head_stands_whole_beside_news[True]` and `test_a_margin_card_is_one_frame_that_rings_for_its_thread`, fail the same way with main's runtime.
## Not checked
- Firefox's paint and shown times: the bench reads only CPU there.
- WebKit.
- The broad suite, the main-push browser tier and the stale-keys sweep.
## Calls Max may reverse
- Dropping the focus place record from the input's task. A window resized in the same frame as a focus move now restores the place recorded before the move.
- While a gesture is unresolved, a reading waits for a frame already asked for, which shows the reading up to a frame later where it would have fitted before that frame, as at 8 sections. Two alternatives I measured and dropped: waiting only for a frame already overdue (asked for longer ago than a 60 Hz frame lasts) still let every Resolve at 1,024 sections paint only with the server's reading in a three-round run; waiting for every reading, gesture or not, drew an extra frame of the whole page during load (about 75 ms of Firefox main-thread time at 1,024 sections). That last version also read the send's paint 4–5 ms faster at 1,024 in two interleaved runs with the arms swapped; I haven't found why, and suspect the extra frames during load leave the margin's and inventory's code warmer for the first send.
Part of #5194.
…emo off other sharing, and test the reading's wait Review of this branch found three gaps and a WebKit problem. Each step of `derive` is now called by `step(key, make, ...inputs)`, which calls `make(...inputs)` with exactly the inputs it is kept by. `logCoverage`, `currentWidgetRelations` and `normalizedObligations` take only the parts they read (the two projections; the descriptors, widgets and desired entries; the obligations, widgets, descriptors and pending withdrawals), and the view, admitted projection, classified ids, projection and thread fold are module-level functions of their inputs. Before, those three steps received the whole view, document or projection and declared only parts, so a later read of another field would have gone stale silently. The memo that answers a subtree from its last sharing now applies only to the fold's result (`shareFold`, used for `effective`). `share` itself keeps no memory, so no other caller is bound to never change a value after sharing it. `tests/runtime/state-application.test.mjs` holds the reading's wait: with a gesture pending and a frame owed, a reading is adopted only after that frame; with none pending, at once. Each fails when the wait is removed or made unconditional. The thread card's fade lengths inherit again. Registered as not inheriting and taken by the fade with `inherit`, they stayed at their first value in Playwright WebKit 27.2 when only they changed (Chromium 158 and Firefox 159 restyle the fade). The fade tracked only because other writes restyled it. The same gap already kept the column's room inheriting; `notes/browser-support.md` now records it as one entry, with a minimal reproduction from today, and the fade rule names it. The card's size bounds stay real properties.
The test that a subtree shared before is answered from that sharing only against its value still called `share`, which keeps no memo since the memo moved to `shareFold`, so nothing held `shareFold`'s guard. It now calls `shareFold`, and fails when `shareFold` answers a subtree from its last sharing regardless of the value now in its place.
max-sixty
marked this pull request as ready for review
November 12, 2026 13:15
leaf-agent
approved these changes
Nov 12, 2026
This was referenced Nov 13, 2026
leaf-agent
added a commit
that referenced
this pull request
Nov 14, 2026
…y it decides (#5943) #5899 made `applyState` (`browser/runtime/state-application.js`) wait for the frame a gesture owes before it adopts the server's reading, so the gesture's own result paints first. So the send's answer, which `round_trip` and `sending` wait for, now lands a task before the page holds the server's thread or offers Undo. Six of the seven macOS failures in #5941 read that state right after the trip: `readThreads()` through `open_panel_thread`, a package widget's thread id, or a `z` pressed straight after a Resolve. They saw the tab's pending copy, and the dropped `z` never retried. This PR makes them wait for the reading itself. It changes no product code. The harness already says delivery does not mean the page applied the returned state (`_Traffic` in `tests/render_harness.py`). - `open_panel_thread` waits until `readThreads()` holds the thread instead of reading it once. - `test_one_field_starts_a_thread_takes_its_reply_and_settles_it` and `test_a_thread_s_keys_answer_in_its_view` undo the Resolve with the existing `undo(page)`, which waits until the dispatcher would take `z`. - `test_package_thread_widgets_keep_local_filters_and_independent_subscriptions` waits for the server's id before it names the panel view. **Verification.** On Linux, the failing state appears when `z` is pressed right after the Resolve is acked. A probe did that 15 times per arm. It failed 6 of 15 at #5899 (`c0ff621c1`), 5 of 15 on main, and 0 of 30 at #5899's parent. In each failing run, a second `z` a second later sent the undo, so the page catches up; only the early press is lost. The same probe using `undo(page)` passed 15 of 15. The six edited tests pass locally. They passed on Linux before this change too, so the macOS evidence is the next scheduled run after merge. I couldn't make the old one-shot `open_panel_thread` read fail on Linux, even with `--cpu-throttle 15`. **What this leaves.** `test_undo_waits_while_the_candidate_is_applying_then_reads_accepted_truth` already uses `undo(page)`. On macOS its page ended at `#sug-thistle`, so that `z` showed the suggestion rather than taking it. That's a different mechanism, and it stays open on #5941. If the next macOS run still shows `readThreads` without the server's thread after these waits, the reading never got adopted, not just adopted late. The likely cause would be an owed frame that never paints, leaving `afterOwedFrame` unresolved. Refs #5941 — automated triage Co-authored-by: leaf-agent <[email protected]>
max-sixty
pushed a commit
that referenced
this pull request
Nov 14, 2026
…wo macOS-only tests (#5949) Two tests failed only in the macOS job of scheduled run [43587194195](https://github.com/max-sixty/leaf/actions/runs/43587194195) because each reads something before it exists. This PR makes each test wait for it. No product code changes. - **`test_packages_and_panel_share_threads_through_gestures_and_authored_content[choose-earlier]`** failed `assert admitted["id"] != pending["id"]` with both ids `pending:98b291bc…`. Since #5899, the page adopts the server's reading a task after the send's answer, so reading the collection once right after `round_trip` can still see the tab's pending copy. #5943 diagnosed this in #5941 and gave the sibling package test the same wait. The test now waits until the thread with the pending key has a different id. - **`test_a_framed_page_moves_nobody_until_the_user_enters_it`** failed in its own `wait_for_function` predicate with `TypeError: Cannot read properties of null (reading 'hasAttribute')`. The inner frame was still navigating and had no `document.body` yet. Its `data-lf-presented` wait, and the identical one in `test_a_same_origin_frame_reads_hidden_and_settled_off_screen`, now use `document.body?.`, so a frame with no body counts as not yet presented and the wait keeps polling. **Verification.** Both tests pass locally on Linux before and after the change, and ruff is clean. Neither failure reproduces on Linux. Per **A red `ci` on main is live**, the next scheduled `test-macos` run after merge is the before/after evidence. Refs #4225 — automated triage Co-authored-by: leaf-agent <[email protected]>
max-sixty
added a commit
that referenced
this pull request
Nov 15, 2026
…it (#6001) After a sent comment on `leaf-dev bench`'s 1,024-section asks page, the readings the page publishes keep every record the send left alone as the object it was, so every reader that keeps what it read by identity skips them. The publication that takes in the server's reading of the send drops from a median 16.9 ms to 9.8 at 1,024 sections, and the publications from the press until that reading is taken in from 20.5 ms to 14.6 (timed in the page; an independent profile of that window found a 2–6 ms saving, Measurements). Sharing an event log grown by one event also gets cheaper than on main. The other costs #5899 left are measured below; two of them no longer hold on current main. ## Why Commenting on a question hands its obligation to the agent, so the obligation leaves `readObligations().user`. `share` (framework/snapshot.js) compared each item of a list with the item at the same index of the prior list. Each record after the one that left was compared with its neighbour's, found different, and published as a new object, so every reader that keeps a reading by identity (kept.js) read all 1,023 of them again. Found by keeping the annotation inventory's entries by their records: the collection after the server's reading remade all 1,024 entries, though only one obligation had changed. ## Change `share` names a list's records by the rule the server's patch protocol names a list's items by (`src/leaf/served_state/tail.py`, `_named`): each record's string `id`, else its event's `id`, and only where no two records of the list share a name. Where both lists are named by one rule, a record whose name differs from the one at its index is compared with the prior list's record of its name. A list whose records go by no name, or share one, is compared place by place, as on main. Deep equality still decides whether a subtree is replaced, so only the choice of which prior record each new one is compared with changes. While every item stands for the prior list's item at its index, by identity or by name, an item past the prior list's end is returned without being compared, so sharing a log grown by an event builds no index of the log. Lines of mechanism, counting code and leaving out comments, blank lines and tests: 36 added and 8 removed, all in snapshot.js. 20 are the helpers that name a list's records and pair them, and 16 replace the 8-line loop that pairs each item with a prior one. ## Measurements Timed in the page with `performance.now()` around each outermost call of `publish` (framework/application.js), unprofiled, at 1,024 sections. No publication ran nested inside another during these sends (counted), so each is counted once. Main and this branch alternated, two runs of five sends each, with the host under heavy load (load average 66–122). Each cell is the median of the ten sends, with the lowest and highest in brackets: | Publications | main (ms) | this branch (ms) | | --- | --- | --- | | The press's own | 3.2 [2.7–4.7] | 2.7 [2.5–4.5] | | The one that takes in the server's reading | 16.9 [15.1–21.5] | 9.8 [8.5–11.6] | | From the press until the reading is taken in, summed | 20.5 [18.4–27.9] | 14.6 [13.1–20.0] | | Every one of the send's, until the page settles | 23.6 [20.3–30.1] | 16.5 [13.6–22.3] | An independent review profiled every publication from the press until the page took in the reading, the third row's window, with V8's sampling profiler, two runs each, on main and on this PR's first commit: a send 17.0 and 16.4 ms against 14.8 and 12.2, a Resolve 18.1 and 14.4 against 12.7 and 11.6, a pick 28.4 and 24.0 against 23.1 and 20.6. That is 2–6 ms over the window, against the timers' 6 ms for a send; the two differ in method, in host load and in the branch's commit. Sharing a list alone, in Node, the median of 15 interleaved trials (load average about 31), in ms: | List | main | first commit | this branch | | --- | ---: | ---: | ---: | | 1,000 events, grown by one in place | 0.040 | 0.071 | 0.017 | | 4,000 events, grown by one in place | 0.149 | 0.231 | 0.027 | | 16,000 events, grown by one in place | 0.659 | 1.330 | 0.106 | | 16,000 new records, the first one gone | 4.8 | 6.4 | 7.3 | On the last row this branch keeps 15,999 records' identity, where main keeps none; the extra time is naming both lists. A list of fresh records grown by one costs the same as on main (4.9 and 5.1 ms at 16,000). Chromium, `uv run leaf-dev bench asks --sizes 64,256,1024 --input comment --rounds 5 --base 7ec8751`, on this PR's first commit against main, both arms interleaved, load average 5.2 at the start and 17.9 at the end. CPU is the send's main-thread time from the press until 400 ms after its reading shows, less the page's idle time. Each cell is the median of five rounds, with the lowest and highest in brackets. | Sections | CPU, main → branch (ms) | Shown, main → branch (ms) | | ---: | --- | --- | | 64 | 79.5 [73.3–82.6] → 78.0 [70.7–86.5] | 96.7 [87.6–113.0] → 97.0 [88.2–102.6] | | 256 | 90.5 [88.1–106.6] → 93.5 [86.1–106.2] | 113.2 [112.6–126.7] → 110.5 [109.5–113.1] | | 1,024 | 178.1 [160.1–204.3] → 167.1 [158.0–219.2] | 185.4 [171.7–204.9] → 187.5 [166.5–196.7] | The rounds' spread at 1,024 sections is wider than the saving, so the CPU column shows the direction and not the size. The paint pass's long-frame attribution put applying the server's reading (`paintedOwed`) at 39 ms of script per window on main and 15 on this branch, and 42 and 12 in an earlier three-round run. It counts only frames of 50 ms or more, so a frame that drops just under that line leaves the count; it shows that the reading's frames got shorter, not by how much. Paint, the frame that draws the sent message, moves within the rounds' spread: the change is in the reading's application, after that frame. ## The costs #5899 listed, on current main Timed in the page on main (`7ec8751318`) with `performance.now()` around each function, unprofiled, median of five sends, before the frame that draws the message: | Step | 64 sections | 1,024 sections | | --- | ---: | ---: | | Margin pass (`layoutMarginRows`) | 1.4 ms | 9.3 ms | | Annotation inventory (`collectEntries`) | 0.6 ms | 6.1 ms | | Reading place (`recordPlaces`; its `lineAnchor` 0.0 and 0.1 ms) | 1.7 ms | 3.1 ms | | Forced style in the press's task (trace, 22 recalcs) | 15.5 ms | 17.9 ms | - **Margin pass.** Spread over every row. Timed by phase over a send's two passes at 1,024 sections, 15.9 ms in all: seating itself is 2.5 ms, and the rest is finding held rows, carrying each row's record, writing each seat, the new pin's cover reading every child of `main`, and the layout event's listeners. Seating only the rows a new row can reach would cut the 2.5 ms and leave the rest; making the whole pass follow the change is a restructure of `layoutMountedRows`, judged not worth it for about 2–6% of a send's CPU. - **Annotation inventory.** I built keeping each item and entry by the records and label it was made from (kept.js), with the kept entries left in their order and only the remade ones placed among them. It cut a collection from 6.1 to 4.5 ms, but an interleaved five-round A/B against this branch read the send's CPU at 1,024 sections as 171.8 ms without it and 170.6 with it, for about 75 lines, so it is not here. The cost is visiting every obligation and resolving its target (`getElementById`, `targetPath`, the label, the group map), about 4.5 µs each; making entries is about 0.6 ms of it. Skipping records whose list didn't change would have to resolve targets by id and read labels from attributes the page's reading doesn't hear, and `an entry stays one object until what it is made from changes` holds that an `aria-label` change shows at the next collection. - **Reading place text search.** Gone on current main (#5875 changed that search): `lineAnchor` takes 0.1 ms. `capturePlace` still grows, 0.7 → 2.2 ms, from visiting every text block to find those on screen (`textBlocks`, `renderedBlocks`). - **Forced style.** It does not grow with the page, and no rule restyles more than the card: each of the 22 recalcs touches at most 97 elements, all in the thread card, the composer, one margin row or their ancestors (invalidation tracking in an unprofiled trace). `--lf-ring-at` is registered as non-inheriting (base.css, since #5116), so focus rules setting it restyle only the box they match. The 16–18 ms is the number of places a script reads style or layout after a write in the press's task: `scrollToEnd` in `showArrival`, `motionTime` reading a token twice, `focusBox`, `cardMinimum`. That is a question of the card's build order rather than of CSS. The margin projection's per-row work grows too: `renderNow` 2.1 → 6.3 ms, of which `readSpokenPositions` (each target's place down the page) is 2.6 and `nameMarkers` 1.8, and the Tab stop (`syncRoving`) 0.3 → 2.5. ## One record of what changed? The brief asked whether one shared record of what changed would replace `readingElements` (#5872), the `derive` steps' memo (#5899), `Footprints` (#5866) and `drawnElements` (#5871). It would not: - `drawnElements` keeps nothing between calls. It walks what the browser draws, asking `checkVisibility`, and skips the rest. - `Footprints` is an index of seats built in each margin pass and dropped at its end. The margin's record across passes is `seatings`, which the page's observers drop: a resize, a mutation, a scroll inside a box, a transition's end. - `readingElements` and the `derive` memo are records of change for different inputs. The memo compares immutable state by identity, which needs no observer because publication shares every unchanged subtree. `readingElements` keeps its answers on pieces of the page's reading, which the reading's mutation observer drops. These already compose. The page's reading exposes its state as an identity token, `pageReadingVersion`, which an identity-keyed reading takes as one more input, as `gatherConversations` (thread/placement.js) and `prepareVisualActions` (anchor-controls.js) do. Geometry is a third kind of change, reported by resize observers, scroll events and transition ends rather than by a mutation, so folding `seatings` into the same record would move it only partway. What made a cost like these hard to remove was a fault in the identity record itself, which this fixes: positional sharing broke identity for every record after one that moved, and each identity-keyed reader paid for it. ## Checked - `pnpm run test:runtime` (970 pass) and `pnpm run check`; pre-commit on both files. - The new test, `sharing a list keeps each record equal to the prior one of its name` (framework-snapshot.test.mjs), fails on main and on this PR's first commit: records lost, gained mid-list and reordered as new objects, records named by their events, a list of unnamed records, and two records sharing an id, which stay two objects. - The review's fuzz of 20,000 lists passes: every result deep-equals the new list, reuses a prior subtree only where it is equal, and in no list do two places become one object (104 to 108 lists did on the first commit). - 41 browser tests, all passing on the final head, selected with `-k` from `widgets/test_obligations.py`, `threads/test_resolving.py`, `test_render_semantic_news.py`, `margin/test_page_map.py`, `margin/test_entries.py`, `test_render_options.py`, `threads/test_panel_list.py`, `projection/test_widget_actions.py`, `projection/test_thread_replies.py` and `projection/test_live_versions.py`: obligations answered, cleared and walked; threads resolved and reopened; agent news; Page Map reconciliation; margin rows leaving; undo and refused picks; live revisions. ## Not checked - Firefox and WebKit. - The broad suite and the main-push browser tier. - Which lists besides the user's obligations shift in a send's reading; the publication time is measured, not attributed list by list. ## Calls Max may reverse - The annotation inventory's kept entries are left out, measured as above. - Where the two lists are named by different rules, `share` compares records place by place, where the server's patch treats every item as new. Both are correct; place by place can still find an equal record. - A long list of new records that loses its first one costs more than on main (the table above), in exchange for keeping every record's identity. Part of #5194.
max-sixty
added a commit
that referenced
this pull request
Nov 15, 2026
…in round_trip, and refuse assertions that rest on a sleep (#5988) Three changes to how the suite isolates tests and waits, from a review of recent flakes. **Process state.** Nothing writes the pytest process's environment directly now. `pytest_configure` sets the run-wide conditions once through a `MonkeyPatch` (failing harness programs on PATH, the headless shell as `LEAF_BROWSER_EXECUTABLE`, Linux fonts, SIGINT), and tests use `monkeypatch`. The website's `restore()` no longer sets `LEAF_PAGE_COMMIT`; the container's `main` does, so `isolated_session` drops the reset b45b8e1 added. A teardown hook fails any test that leaves the environment, working directory or SIGINT/SIGTERM/SIGHUP handlers changed, and a command a test runs through `CliRunner` keeps the signal handlers it takes (`leaf wait`, `leaf page events`) to that run. Layer caches are per test through `monkeypatch.setattr` instead of cleared after. **`round_trip`.** Since #5899 the page adopts the server's reading a task after the answer, so tests that read page state right after `round_trip` saw stale state (#5943 and #5949 fixed seven one by one). The traffic ledger now counts `received` and `applied` states, and `round_trip` also waits until every received state has finished applying. `postEvent` counts `acked` once the answer's body is read; its headers still decide at once. The two one-shot reads those PRs replaced are back. Two tests hold that application on purpose (behind a held Markdown import, and held zero-delay timers), and end their trip at the answer through a new `delivered`. **Sleeps.** `test_no_assertion_rests_on_a_sleep` refuses a sleep followed by an assertion. The 79 such sleeps in nine files now wait for `rendered`, an ordered later event, or the page clock run past the runtime's own preview timers (`PREVIEW_TIMERS`, read through `__lfCheckApi`); each pattern was checked against a product change that brings the bug back. `tests/AGENTS.md`, "Fixtures", states the isolation rule. Max asked for this. Codex reviewed it twice, and its findings are fixed. A [full-suite dispatch](https://github.com/max-sixty/leaf/actions/runs/43651852106) on an earlier commit found four failures this change caused, all fixed since: the two held applications, `leaf page events` taking SIGTERM, and a finger landing on a panel still opening (macOS). Its other failures also fail on main, in main's own runs or run locally, except three macOS ones that pass here under `--cpu-throttle 10`. Focused tests, `pnpm run test:runtime` and `pnpm run check` pass. > _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.
On the 1,024-section page
leaf-dev benchgenerates, a sent comment now draws in 93–94 ms in Chromium in two rounds of three, and 139 ms in the third, from 117–121 ms on main, so it is under the 100 ms rootAGENTS.md("Responsiveness") asks for, but not by much or in every round. A Resolve draws in 72–84 ms, from 121–130 ms; on main, every round applied the server's reading of it before the frame that drew it. The server's reading of a send shows at 174–193 ms, from 184–198 ms, and still misses 100 ms; what remains is listed at the end. The cost: on a small page the server's reading of a gesture shows about a frame later, asshownat 8 sections in the table below. In Firefox the send's main-thread time at 1,024 sections falls from 273 ms to 252, and a Resolve's from 169 to 134.Why
Timing the send at 1,024 sections on main (#5893's head) with timers around each step, unprofiled, the press's task took about 90 ms and the frame after it about 40:
publish): rebuilding the whole effective state, comparing it with the last reading, and re-deriving every widget's selectionrecordCurrentLocation→capturePlace), a hit test that forced the page's layout midway through the taskcollectEntries)The server answers a send in about 50 ms at 1,024 sections, so its answer arrived while the press's task was still running. In some rounds the browser then ran the answer's task, about 50 ms of applying the reading, before the frame that would have drawn the message, so the message painted only with the server's reading. A Resolve at 1,024 did this in nearly every round.
Changes
A publication reads again only what it changed.
derive(framework/application.js) runs each step that reads the whole page — the view, the projection and its coverage, the thread fold, widget states, widget relations and the served obligations — throughstep(key, make, ...inputs), which keeps each result by its inputs (keptReadings, kept.js) and callsmake(...inputs)with exactly those inputs, so a step can read nothing its key leaves out. A step whose inputs are the same objects as last time hands back what it made then.logCoverage,currentWidgetRelationsandnormalizedObligationsnow take only the parts they read. Sharing the fold's result (shareFold, framework/snapshot.js) remembers, for each subtree it replaced with an equal one, what it shared it as, and answers that subtree, met again against the same value, without reading it;shareitself keeps no memory, so no other caller is bound to leave a value unchanged after sharing it. Together, a publication about one thing costs what it changed rather than what the page holds. Every widget's selection now derives from one selection of the parts a widget reads (select's newfrom), so a publication that moves none of them, such as a comment's, reads no widget again; before, each of the 1,024 asks re-read its inputs on every publication. The send's publication takes 3.6 ms, from 15.The focus place is recorded in the frame only.
recordCurrentLocation(version.js) recorded the reader's place both in the input's task and in the next frame. The record in the task read the page's layout midway through the task's writes, a forced layout of the whole page, only to cover a window resized in the same frame. A frame that resized already records nothing (regionsSettled), so a shift there restores the place recorded before the input. That record took 14 ms of the send's task; without it the task is about 8 ms shorter, since the task's next read of the page's layout now lays it out instead. The frame's record stays.A reading waits for the frame a gesture is owed.
afterOwedFrame(rendering.js) resolves once the frame the page has asked for has painted, or at once where none is asked for or the document draws nothing. While a gesture of the user's is unresolved,applyState(state-application.js) waits for it before adopting a reading, so the gesture's own result paints before the server's reading is applied. With no gesture in flight, as while the page loads or when the agent's news arrives, a reading is adopted as before: waiting there too drew an extra frame of the whole page during load, about 75 ms of main-thread time in Firefox at 1,024 sections. The cost: where the reading would have fitted before the gesture's frame, it shows one frame later, as for a Resolve at 8 sections (below).The thread card's bounds no longer restyle the whole card.
measureThreadCardand the card's fit wrote the card's width and height caps as custom properties (--lf-thread-width,--lf-thread-min-width,--lf-thread-max-height) that only the card itself read, but every element in the card inherited, so each fit restyled about 220 elements. They are now the card's ownmax-width,min-widthandmax-height. The transcript's fade lengths (--lf-thread-fade-top,--lf-thread-fade-height) still inherit, and each write of them restyles the thread's elements: registered as not inheriting and taken withinherit, they stay at their first value in WebKit, the gap that already keeps the column's room inheriting.notes/browser-support.mdnow records that gap as one entry with a minimal reproduction (WebKit 27.2 keeps the first value; Chromium 158 and Firefox 159 restyle), and the fade rule names it.The annotation inventory sorts each place once and names only outline targets. Its sort read both nodes' ancestor chains and walked their siblings for every comparison;
renderedOrdering(shadow-tree.js) reads each node's chain once and each parent's children once per sort, andbyRenderedOrderuses it too.outlineSubjectForchecked, for every target, whether it was in the page's outline by scanning the outline, a walk of one collection per member of another;outlineContexts(thread/placement.js) counts the outline's labels once and reads a label only for a target in the outline, which is all the inventory used of it. Each obligation's row shares one reading of its words ("Waiting on me") rather than a copy per row.Measurements
Chromium,
uv run leaf-dev bench asks --sizes 256,1024 --input comment --input resolve --rounds 3 --base origin/main, both arms interleaved, this branch against its merge base with main (#5875); load average 3.5 at the start and 1.9 at the end. Each cell is the lowest of 3 rounds, as the bench reports, 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. Where main's paint equals its shown, the server's reading was applied before the gesture's frame. The send's three paints at 1,024 sections on this branch were 92.8, 139.2 and 93.6 ms; the slow round was not that race (its reading showed at 192.5). The bench's long-frame attribution at 1,024 sections puts the send's own task at 57 ms of script (19 forced), from 81 (24 forced), and the frame after it at 28 ms, from 35; applying the server's reading now runs in its own task after that frame (
paintedOwed).Firefox, the same command with
--browser firefox, which reads only main-thread CPU there; load average 1.8 at the start and 1.9 at the end.Firefox gains less than Chromium from these changes; I haven't profiled it to say why.
What remains at 1,024 sections
Timed in the page on this branch at 1,024 sections, unprofiled and before rebasing onto #5875, these still grow with the page:
layoutMarginRows), 9 ms in the frame against about 1.3 at 8 sections. A rows-only pass still visits every row: finding held rows by one selector over the whole layer, carrying each row's record, seating every row throughFootprints, and writing every row's seat, together about 4.5 ms; and the send's new pin reads every child ofmainfor its cover (childIndex), 1.5 ms. A change to the page's words or styles lays out only the margin rows it can move #5752 describes seating only the rows a change can move; the cover index could also be kept across rows-only passes, which by definition move nothing on the page.lineAnchor→anchorForPassage), which searches the page's text for that line's copies to choose its context; every focus move, scroll end and keystroke frame pays it. Computing the anchor only when a record is used, from the line's live nodes, would remove it. Find a selection's copies by string search, and search the page a part at a time #5875, merged since this was profiled, changed that search, which I haven't re-profiled.syncRoving), 2 ms in the frame: it reads every marker's box to find the highest one in view.data-lf-focus-within,data-lf-control-focus-visible) match rules that set the inherited--lf-ring-at; the card'svisibility, which is inherited, is cleared once it is placed; and the fade's lengths, which inherit because of the WebKit gap above. The first two are theme-wide patterns, which I left for a change that can check every surface they reach; the fade could become an element of its own with inlinetopandheight.#5752 stays open: seating only the rows a change can move is still to do.
Checked
pnpm run test:runtime(965 pass),pnpm run check(which runscheck:browser), pre-commit on every changed file.framework-application.test.mjs);shareFoldanswers a subtree from its last sharing only against the value it was shared as (framework-snapshot.test.mjs, which fails whenshareFoldanswers regardless of the current value); a task waiting on the frame already asked for runs once that frame has painted (rendering.test.mjs); a reading arriving while a gesture's frame is owed is adopted after that frame, and with no gesture pending at once (state-application.test.mjs, which fails with the wait removed and with it made unconditional); a sort's ordering answers every pair as rendered order does (page-walk-order.test.mjs, which fails with the sibling order reversed).margin/test_page_map.py,margin/test_entries.py,drafts/test_reading_place.py,threads/test_layout.py(whosetest_the_thread_card_opens_on_its_latest_message_under_its_own_namereads the fade's box),margin/test_card_placement.py,margin/test_opening_threads.py,margin/test_card_reply.py,threads/test_resolving.py,navigation/test_commenting.py,test_render_semantic_news.py,test_news_just_after_a_press_moves_nothing,widgets/test_obligations.py,widgets/test_boards.py,test_render_options.pyandtest_render_application_boundary.py(416 passed); and, before the review fixes,margin/test_pins.py,margin/test_rail.py,margin/test_clusters.py,navigation/test_threads.pyandnavigation/test_obligation_walk.py. The three,test_a_card_s_head_stands_whole_beside_news[True],test_a_margin_card_is_one_frame_that_rings_for_its_threadand a teardown error intest_a_zoomed_floating_draft_and_sent_comment_fit_a_narrow_window("ResizeObserver loop completed with undelivered notifications"), fail the same way with main's runtime.Not checked
Calls Max may reverse
Part of #5194.