Skip to content

Present a page of large text documents in Firefox without restyling every row - #5371

Merged
leaf-agent merged 6 commits into
mainfrom
grind/firefox-large-pages
Nov 4, 2026
Merged

leaf-agent merged 6 commits into
mainfrom
grind/firefox-large-pages

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

Served, #4781's page of 30 tabs, each a text document bound to 4 MB of 80-character lines (1.5 million lines in all), now presents in Firefox at 2.2–2.7 s instead of 26.5–32.5 s and draws every document by 7.6–8.7 s instead of 26.6–32.6 s. Its longest frame drops from 6.3–10.4 s to 1.1–1.4 s, and its peak memory from 15.0–17.2 GB to 5.8–7.9 GB. With a comment on the page anchored by its words, every document has drawn by 11.2–13.5 s instead of 27.7–38.0 s. Chromium presents at 1.4–1.6 s instead of 5.8–6.3 s, and its longest frame drops from 2.5–2.8 s to 0.24–0.28 s. With the comment, Chromium draws every document by 6.2–6.8 s instead of 37–40 s; its longest frame stays at 2.8–3.0 s, now once rather than after every document.

Why

Firefox styles every element inside content it skips: a content-visibility: auto run out of view, and a closed tab's hidden="until-found" panel. Chromium leaves that content unstyled until it is drawn. So each restyle that reaches a listing styles every row and its line number, 1.4 to 2.4 µs an element on this page (the Firefox Profiler's Styles marker counts them). Three of Leaf's own steps reached every row during a load:

  • Presentation. Every document drew before the page presented, closed tabs' too, and presentation flips the startup guards on body (body:not([data-lf-presented]) * in base.css, and the inherited --lf-before-presentation), which restyle every element in the page: on the export, 2.1 million elements and a 2.6 s frame in Firefox, after 22 s of waiting for the documents. A closed tab's document now draws once the page has presented, from one queue, one a task (drawLater), and the page counts the queue as an arrival, so pageReadiness still waits for it. Presentation waits for the document in view only.
  • The scroll mark. Once a listing draws, the runtime marks its pre as a box that scrolls (data-lf-scrolls), and the mark's rule (state.css) restarts the sticky-header slot with four inherited custom properties. The listing stated only --lf-top, so the other three changed under every row: 250 to 330 ms in Firefox for 97,000 rows, 25 to 45 in Chromium. The listing now states all four from the first paint (text-document.css), the same values the mark sets, and the mark changes nothing the rows inherit: 12 to 16 ms.
  • Inserting a listing. Firefox checks every element an insertion adds against the page's :has() rules. The obligation ring's rule (options.css) excluded quoted groups as :not(:where([data-lf-exhibit]) *) inside its :has(), and the * there made every inserted row a candidate: 515 ms of each closed document's 660 ms draw. Keyed on the tag, as :not(:where([data-lf-exhibit] lf-options)), with the same meaning and specificity, inserting 20,000 rows into a small page takes 15 ms instead of 86.

Drawing closed tabs after presentation exposed what each draw costs once the page has presented. A draw's announcement (drawn, which stamps its data's provenance) sends the page through a document pass, and the pass did more than it needed after each one:

  • The margin's points (placePoints) took the page's reading on every pass, and every draw had changed the page, so each pass walked all of it. They now take it only for a point to find again. Served, this branch before the change took 37.5 s to draw every document in Chromium, 32.7 s of it in pageText (independent review).
  • A comment anchored by its words is found again on each pass, which needs the reading. Closed tabs' documents now report their draws, marks and drawn in one turn as module-state.md asks, together once the queue is empty, or each as soon as it shows, so the page reads itself once. Reported one at a time, the served page with one such comment took 31.7 s to draw every document in Firefox, with frames up to 4.9 s. The queue is a stopgap: a page reading that keeps what an unchanged part of the page read would make each report cheap, and the queue can be deleted then.
  • The quiet-word pass queried the page for its three provenance marks as one selector list, 35 to 39 ms a pass on the drawn page; it now asks once a mark, 0 to 1 ms (independent review).

A document that has yet to report its draw shows no revision, so a comment on its data can't be on an earlier one. projectMarked marks the widget root as having reported a draw (data-lf-draw-reported), and until that mark stands resolution keeps a data anchor on the widget with no outdated status. Without it, a current comment read "Earlier data" while the queue ran.

notes/browser-support.md records the Firefox behaviour ("Styling content Firefox skips"), with a reproduction and the restyles that remain.

Evidence

Served from each tree with leaf server run --lifetime temporary on loopback, alternated on one host; each arm loads a copy of the same page directory (#4781's page, with or without one user comment on Doc 23's first line). Main is ee79d7e, which holds #5372. Firefox 157 (Playwright build 1555) is warm: a small page loaded and 15 s waited first, so the font list a newly started Firefox loads, which restyles every page once or twice, has loaded. "Longest frame" is the longest gap between animation frames from navigation until every document has drawn plus 5 s; memory is the peak resident size of the browser's largest process over the same window.

Ranges are over five rounds: three at e45e9b7 on a quiet host (mean load 3) and two at this branch's head on a busy one (mean load 16). The busy rounds raised both arms alike and account for the top of each range: on the page with no comment, every document drawn rose 13–20% on main in Firefox and 4–14% on this branch, and 7% and 8–11% in Chromium, so moving the document's marks to the report shows no cost beyond the host's. Firefox's peak memory on that page is the exception I can't explain: 7.9 GB in both busy rounds against 5.8–6.0 GB in the quiet ones, while the page with a comment read 5.8–6.0 GB in all five. Peak readings in Firefox vary between rounds on the export too (below).

Engine Page Arm Presented Every document drawn Longest frame Peak memory
Firefox no comment main 26.5–32.5 s 26.6–32.6 s 6,284–10,445 ms 15.0–17.2 GB
Firefox no comment this branch 2.2–2.7 s 7.6–8.7 s 1,078–1,447 ms 5.8–7.9 GB
Firefox one comment main 27.6–37.8 s 27.7–38.0 s 6,837–12,138 ms 13.8–14.5 GB
Firefox one comment this branch 2.2–2.7 s 11.2–13.5 s 3,898–4,617 ms 5.8–6.0 GB
Chromium no comment main 5.8–6.3 s 5.9–6.4 s 2,521–2,752 ms 3.0 GB
Chromium no comment this branch 1.4–1.6 s 3.6–4.1 s 240–284 ms 1.7–1.9 GB
Chromium one comment main 37.2–40.2 s 37.3–40.3 s 2,348–2,790 ms 3.8–4.1 GB
Chromium one comment this branch 1.4–1.6 s 6.2–6.8 s 2,801–2,984 ms 2.8–3.0 GB

With the comment, main's longest frame recurs: the page read itself again after each document drew, about 30 frames of 2 to 2.6 s in Chromium. This branch reads it once, after the last closed tab's document has drawn, which is its one long frame.

Exports of the same pages (leaf page export), three alternated rounds at e45e9b7 against main at ee79d7e; "1.5M lines" is the page above and "long lines" 30 tabs of 4 MB with a paragraph a line:

Engine Page Arm Presented Every document drawn Longest frame Peak memory
Firefox 1.5M lines main 20.7–20.8 s 23.1–23.3 s 2,442–2,514 ms 13.8 GB
Firefox 1.5M lines this branch 1.2–1.3 s 6.6–6.7 s 669–698 ms 4.4–6.0 GB
Firefox long lines main 3.0–3.1 s 3.3–3.4 s 328–345 ms 4.1–4.2 GB
Firefox long lines this branch 0.7–0.8 s 1.6 s 209–240 ms 3.2–3.3 GB
Chromium 1.5M lines main 2.4–2.5 s 2.5 s 245–255 ms 2.1 GB
Chromium 1.5M lines this branch 0.7 s 2.5–2.6 s 239–248 ms 2.0 GB
Chromium long lines main 0.9 s 0.9 s 209–210 ms 1.2 GB
Chromium long lines this branch 0.5–0.6 s 1.1 s 210–220 ms 1.2 GB

Firefox's peak memory on the 1.5M-line export varies between rounds (4.4, 6.0 and 6.0 GB here, 4.5 to 6.4 GB in the review's ablations), so read it as a range. In Chromium the branch changes when the page presents, not when every document has drawn or how much memory it peaks at.

Two journeys on the served page, one run at each of those two commits:

  • A click on Doc 15 two seconds after navigation shows its text at 5.7–6.5 s in Firefox (main 13.4–13.9 s) and 3.7–3.9 s in Chromium (main 3.6–3.7 s).
  • The comment on Doc 23's first line, a closed tab, stands on its section from presentation until every closed tab's document has drawn and the page has read itself again, then on its passage: from 2.3–2.7 s to 10.9–11.9 s in Firefox, and from 1.6–1.8 s to 6.1–6.8 s in Chromium. Its thread shows the quote with no status meanwhile, and never reads "Earlier data". On main it stands on its passage when the page presents, at 27.5–31.0 s and 37.6–39.2 s.

leaf-dev scaling document asks --base (Chromium, sizes 32 to 256) at e45e9b7: no exponent above 1.5 on either arm. At size 256, document load 237 ms against main's 266 ms (exponents 1.00 and 1.27), asks load 1,529 ms against 1,548 ms (1.06 both), and clicks, keys and scrolls within the run's noise.

What remains

  • The page reads itself again in one long frame once the closed tabs' documents have drawn, when a comment on the page is anchored by its words: 2.8–3.0 s in Chromium and 3.9–4.6 s in Firefox on the served page. The reading walks every element in the page (passages.js, readPage), and any change to the page forgets it. Main pays the same walk after every document; making it once is as far as this branch goes. A reading that keeps what an unchanged part of the page read would remove the long frame, and with it the queue.
  • The document in view is styled twice in Firefox, 160 ms as its rows arrive and then 250 ms recascading all 136,000 elements with 4 rematched. A likely cause, read but not tested: the host wears the source face until it takes lf-rendered (reading.css, [data-lf-content="data"]:not(.lf-rendered)), and of what that rule sets, the listing doesn't restate the inherited font-variant-ligatures: none, so taking the class changes a value every row inherits.
  • Presentation still restyles the document in view in Firefox, about 500 ms for 50,000 lines: the transition: none guard rematching every element, and --lf-before-presentation recascading them.
  • Adding an element near the top of main restyles every later sibling's subtree in Firefox: 3.6 s on the 1.5M-line page, 280 to 310 ms over 97,000 rows. Gecko does this for an insertion into any element whose children a +, ~ or :nth-*(… of …) selector was matched against, and the frame-edge trims in reading.css (:nth-child(1 of :not(.lf-ui, [data-lf-gen])) and its :nth-last-child twin), .lf-inspection-body :is(h2, h3) + * and the reading theme's .eyebrow + :is(h1, h2, h3) are matched against every element or heading. With the trims written as :first-child/:last-child and the two sibling rules removed, the same insertion took 24 ms. The trims need a design, since :first-child doesn't skip generated edge children.
  • A newly started Firefox restyles every page once or twice for font-info-updated in its first seconds, 1.4 s each on the 1.5M-line page.

Calls Max may reverse

  • Closed tabs' documents draw after presentation, and report together. Find, selection and copy reach a closed tab's text once its draw lands, and a comment on a passage inside one stands on its passage once every closed document has drawn, or as soon as its tab opens.

Checks

  • test_the_page_presents_without_waiting_for_a_closed_tab_s_document records the order of presentation, each document's draw and each report; it fails with main's lf-text-document.js and with reports made one at a time. test_a_tab_opened_while_closed_documents_draw_reports_its_document_at_once and test_a_comment_on_a_closed_tab_s_document_never_reads_as_earlier_data hold the queue open from presentation; each fails with its branch removed (the report when a tab opens, the report for a queued draw that is shown, the resolution rule). test_a_listing_s_scroll_mark_changes_nothing_its_rows_inherit compares the listing's code's whole computed style, custom properties included, with and without the mark; it fails with main's listing and with a fifth property added to the mark's rule (tests/browser/widgets/test_code_and_documents.py).
  • Document, comment-target, data provenance, export and bounds tests (test_code_and_documents.py, drafts/test_comment_targets.py, threads/test_targets.py, startup/test_projected_data.py, test_render_export.py, widgets/test_workspaces_and_bounds.py, projection/test_workers.py, projection/test_code_review.py, -k "document or listing or tab or source or data or datum or comment or outdated or revision or worker"): 101 pass, Find in both engines included.
  • Pointed comments (test_render_aim.py -k pointed), the quiet words (test_a_board_says_which_column_each_card_is_in, test_restating_a_widget_is_how_a_version_takes_the_pen_back, test_a_workers_report_paints_live_and_ends_at_the_version_that_answers_it, two Page Map origin tests) and the obligation ring (test_current_location.py, test_render_options.py -k "ring or location or obligation"): pass.
  • pnpm run test:runtime (812 pass), pnpm run check:browser, and the pre-commit hooks on the changed files.

The independent review ran the stills (55 of 56 unchanged; on-me's proxy group reordered, 0 px) and checked the ring in both engines. Not verified here: WebKit.

Part of #4781

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

…very row

Firefox styles every element inside content it skips, a `content-visibility: auto`
run out of view and a closed tab's panel included, so each restyle that reaches a
text document's listing styles every row. Three of Leaf's steps did during a load:

- Presentation flips startup guards on `body` that restyle every element. A closed
  tab's document now draws after the page presents (`afterPresentation`), counted as
  an arrival, so presentation waits for the document in view only.
- The runtime's scroll mark on a listing changed three inherited custom properties.
  The listing now states every value the mark sets from the first paint.
- The obligation ring's `:has()` excluded quoted groups with a `*`, which made every
  inserted row a candidate. It names the group by its tag.

Drawn after presentation, each closed document is followed by a projection repaint,
whose quiet-word pass queried the whole page; it now takes the elements the repaint
marked. notes/browser-support.md records the Firefox behaviour and what remains.

On #4781's 1.5M-line page in a warm Firefox, the page presents at 1.3 s instead of
22.6 s, the longest frame drops from 3.2 s to 0.7 s and peak memory from 13.9 GB to
6.3 GB; Chromium presents at 0.7 s instead of 3.3 s with no slower frame.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
max-sixty added a commit that referenced this pull request Nov 4, 2026
… it added (#5372)

The runtime finds the elements a subscription stands on (`watchOwner`)
in what a mutation adds by asking each added element whether it is one,
and offers only those. It used to watch them as the selector `*`, so
every element an insertion added was offered, held in the watch's
`WeakSet` and looked up for subscriptions it never had. A text document
draws one element a line, so loading #4781's page of 30 documents of
50,000 lines offered and held 1.5 million rows.

`watchArrivals(selector, …)` keeps its signature; inside, a watch now
holds a kind (`is`, `within`) rather than a selector string, and the
owner watch's kind asks `owners.has` while it walks
`querySelectorAll("*")`.

## Evidence

Each arm is an export of #4781's page built from that tree (30 tabs of 4
MB; "1.5M lines" has 80-character lines). Chromium's main-thread CPU
over the load of the 1.5M-line page, from a V8 profile from navigation
to settle + 3 s, and the time under the watch's `offerMany`:

| Arm | Chromium main-thread CPU | of which `offerMany` |
|---|---|---|
| main | 3.20 s | 493 ms |
| this branch | 2.56 s | 4 ms |
| #5371 | 3.15 s | 509 ms |
| #5371 with this branch | 2.49 s | 5 ms |

On main the Gecko profiler put 1.3 s of Firefox's load under the watch's
`read`, 1.0 s of it in `offerMany`. On this branch the owner walk
(`ownerKind.within`) takes 115 ms of Chromium's. These Chromium figures
come from the author's host. An independent review on another host
measured the time under the watch's `read` falling from 2.54 s to 0.66
s: about three times larger in absolute terms, in the same direction.

Load in Firefox 157 (Playwright build 1555), warm (a small page loaded
and 15 s waited first), arms alternated on one host over two rounds,
from navigation until every document has drawn plus 5 s
(`.tmp/perf/measure.py`), 1.5M lines:

| Arm | Presented | Every document drawn | Longest frame | Peak memory |
|---|---|---|---|---|
| main | 22.6 s, 22.0 s | 25.8 s, 24.7 s | 3,163 ms, 2,620 ms | 13.9 GB,
14.0 GB |
| this branch | 21.3 s, 21.2 s | 24.1 s, 23.9 s | 2,689 ms, 2,582 ms |
13.9 GB, 13.9 GB |
| #5371 | 1.28 s, 1.31 s | 8.0 s, 7.9 s | 703 ms, 805 ms | 6.3 GB, 6.3
GB |
| #5371 with this branch | 1.28 s, 1.22 s | 7.0 s, 6.8 s | 710 ms, 674
ms | 4.4 GB, 4.3 GB |

On its own the branch saves about a second of the load; main's longest
frame and peak memory come from the presentation restyle #5371 removes.
Beside #5371 it saves a second of drawing and 2 GB of peak memory.

## Checks

- `pnpm run test:runtime` (785 pass). Two cases in
`tests/runtime/arrivals.test.mjs` cover the owner walk itself: an owner
inside an added subtree and one inside a shadow stage, each connecting
when its ancestor is inserted, disconnecting when it is removed and
reconnecting when it returns. Both fail with `ownerKind.within` yielding
nothing; before them, the file passed that way, since every case
inserted the owner as the added node.
- Browser selections touching owner lifetimes, run with #5371's changes
beside this one: `tests/browser/startup/test_versions.py`,
`tests/browser/widgets/test_boards.py`,
`tests/browser/test_render_export.py` with `-k "revision or restat or
move or drag or replace or version or export"`: 37 pass;
`test_the_diff_marks_what_the_author_changed_and_no_word_a_script_wrote`
(both arms) fails here and on main's `browser/` and `packages/` alike
(the script's appended paragraph is missing after the revision), so it
isn't this change.

Part of #4781

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
max-sixty and others added 2 commits November 4, 2026 08:22
…ce mark alone

On a served page, each closed tab's document drawing after presentation runs a pass
of the margin's points, and `placePoints` read the page on every pass, whether or
not a point needed finding: the draw had just changed the page, so each pass walked
all of it. Loading #4781's page of 30 documents of 50,000 lines served from this
branch took 37.5 s to draw every document in Chromium, against 6.5 s on main, 32.7 s
of it in `pageText` (independent review). The pass now reads the page only for a
point whose element no longer stands.

The projection repaint's quiet-word pass is back to `renderQuiet(document.body,
originTargets)`, with one query a mark instead of `renderQuietOn`: on the drawn page
of 2.05 million elements the selector list over the three attributes took 35 to 39
ms, and the three single-attribute queries 0 to 1 ms (independent review).

The scroll-mark test compares the listing's `code`'s whole computed style, custom
properties included, with and without the mark, so a value the mark's rule gains
fails it too; it fails with main's listing restart and with a fifth property added
to the rule.

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

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description no longer matches the head commit, and on merge it becomes main's commit message. It says the marks' repaint "now hands that pass the elements it marked or unmarked (renderQuietOn)", and gives 25 ms a repaint and 550 ms over 29 draws for that approach. But 6389b04 replaced it: renderQuietOn is gone from the tree. renderQuiet (declared-words.js) now runs one query per provenance attribute instead of one selector list, and placePoints (pointed-place.js) reads pageText() only when a point has to be found again. The description mentions neither change. It also has no measurement for the new renderQuiet comment's claim that a single-attribute query is "far faster" than the three-way list. When you settle the description, please describe the two mechanisms that actually shipped and give their timings. Or, if the per-attribute split isn't what saved the time, drop it and keep the lazy pageText read.

Each document drawn after presentation announced its draw (`drawn`) as it drew, and
each announcement sent the page through a document pass. With a comment on the page
anchored by its words, each pass read the whole page again to find them: served,
#4781's page of 30 documents of 50,000 lines with one such comment took 31.7 s to
draw every document in Firefox, with frames up to 4.9 s, and 21.5 s in Chromium.

Closed tabs' first draws now run from one queue, one a task once the page has
presented, and each document announces its draw once the queue is empty, together
with the others, or as soon as it shows. The same page now draws every document in
11.3 s in Firefox, with one 3.9 s frame as the comment's words are found, and in 6.2 s
in Chromium (main: 28.4 s and 37.3 s). The order test records the announcements.

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

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5568da8 batches drawn inside lf-text-document to work around a cost the runtime causes, so only this widget avoids it. Every drawn reaches projectMarked (projection/data.js), whose applyProjection merges invalidations only within one microtask. Each closed tab's document draws in its own setTimeout task, so each one gets a separate document pass. That pass then rebuilds pageText(), because the insertion invalidated it. The widget-level fix adds a module queue (drawingLater/drawingAfterPresentation), an unannounced field, and an announce() that list, setup and show each call under a different condition. An lf-diff, lf-trace or package widget in closed tabs still pays one whole-page reading per draw. Thirty such draws make the cost grow with documents × page size, which AGENTS.md, "Responsiveness", rules out.

The runtime already knows these draws are a single arrival: afterPresentation wraps them in deferredArrival. If the data projection stamped provenance on each drawn as it does now, and held its invalidateDom until the pending deferred arrivals settle, every widget would get the same single pass. lf-text-document could keep dispatching drawn straight from show, and the queue would only order the draws. That fix costs about the same as this commit, sits in the layer that owns the pass, and removes the widget-side announce protocol instead of adding one. If it doesn't hold up, please say why in the module header.

This commit also changes a claim in the description. "Calls Max may reverse" says a comment on a passage in a closed tab "anchors then", meaning once that tab's draw lands. With this commit, a document drawn early in the queue keeps its DOM unstamped (data-lf-source and the rest) until the last closed document draws: 6.8 to 8.0 s into the Firefox load on the 1.5M-line page. Opening the tab announces it earlier through list. Please update the call (and the evidence, if the timings moved) to the behavior that ships.

max-sixty and others added 2 commits November 4, 2026 09:33
Until a closed tab's document reported its draw, its root carried no source stamps,
and resolution read the missing stamp as another revision: a current comment on its
text said "Earlier data" while the queue ran, from 2.66 s to 7.42 s in Chromium and
10.1 s to 14.5 s in Firefox on #4781's page (independent review). `projectMarked` now
marks the widget root as having reported a draw (`data-lf-draw-reported`), and until
that mark stands resolution keeps a data anchor on the widget with no outdated status.

The document sets its marks in `announce`, in the turn that dispatches `drawn`, as
module-state.md asks of a widget, so it reports its whole draw later rather than
marking at draw and dispatching seconds on.

A tab opened while the queue runs reports its document at once, whether it opened
before the draw or after. The announce on reconnect is gone: no test protected it,
and a document that returns with a draw unreported still reports when it shows.

New tests hold the queue open from presentation by stretching its zero-delay
timeouts. Each fails with its branch removed: the resolution rule, the announce when
a tab opens, and the announce for a queued draw that is shown.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@max-sixty
max-sixty marked this pull request as ready for review November 4, 2026 19:56
@leaf-agent
leaf-agent merged commit 0a22a8c into main Nov 4, 2026
5 checks passed
@leaf-agent
leaf-agent deleted the grind/firefox-large-pages branch November 4, 2026 20:05
leaf-agent added a commit that referenced this pull request Nov 5, 2026
`test_a_wait_takes_the_suites_deadline` refuses a literal timeout
anywhere in the suite. A deadline sized to the author's machine fails a
correct product on a busy runner (`tests/AGENTS.md`, "Functional results
do not depend on execution speed"). It has failed in the last two
scheduled runs and on current main because of seven new literal
timeouts:

- #5359: the two pin-clearance `wait_for_function` calls in
`tests/browser/margin/test_pins.py`, plus Copy's `click` and the
`lf-withheld` expectation in `tests/browser/margin/test_scrollers.py`
(`timeout=5000`)
- #5399: the motion study's shared-clock wait in
`tests/browser/widgets/test_motion.py` (`timeout=10_000`)
- #5371: the two closed-tab `data-lf-source` expectations in
`tests/browser/widgets/test_code_and_documents.py` (`timeout=15_000`)

None of these waits measures how long its subject takes, so each now
takes `SERVED_TIMEOUT_MS`, the default that `render_harness` gives every
wait that names none.

The lint test fails on main `e0c0f9c5f` and passes with this change.
These tests also pass with it:
`test_a_control_an_authored_anchor_name_moves_into_a_pin_s_seat_moves_the_pin`,
`test_a_page_s_reaction_to_a_runtime_mark_moves_a_pin_clear`,
`test_a_pin_on_a_code_block_s_first_line_leaves_copy_pressable`,
`test_a_row_in_content_skipped_until_near_stands_once_the_page_scrolls_to_it`,
`test_recordings_a_revision_adds_join_the_studys_clock` and
`test_a_tab_opened_while_closed_documents_draw_reports_its_document_at_once`.
`test_a_comment_on_a_closed_tab_s_document_never_reads_as_earlier_data`
fails with and without this change: its thread quote is never found, the
same failure as in push run
[41976158322](https://github.com/max-sixty/leaf/actions/runs/41976158322).

Refs #4225 — automated triage

Co-authored-by: leaf-agent <[email protected]>
leaf-agent added a commit that referenced this pull request Nov 5, 2026
…n the page is read (#5569)

A page whose x-shadow widget stages bare text into its shadow root is
supposed to be refused before it presents: the readable fallback shows,
the notice says the page has a problem, and the agent gets one error
naming the widget (#2594). That refusal only fired because some walk of
the page's words met the root first, and before #5371 the margin's
points (`placePoints`) read the whole page on every document pass. #5371
made that read lazy, which was the point: a pass where every point still
stands reads nothing. Now a page with no comment to find again presents
without reading itself at all, so the module's bare text is never
refused, the page presents, and the console stays silent. That is why
`test_a_module_that_stages_bare_text_is_refused_in_its_own_name` timed
out waiting for the error.

This change makes the check explicit. Just before the page marks itself
upgraded, startup asks every declared shadow root the page reading would
cross into (`refuseBareText` in `passages.js`, called from `leaf.js`).
That is the moment the refusal's contract already names. Like the
reading's walk, it crosses into each root it admits and on into the
stages inside that one, so a malformed widget nested in another widget's
root is refused too. It skips hosts inside Leaf's own surfaces, as
`readPage` does. #5371's lazy reading stays as it is. The added startup
work is one look at each stage's direct children.

**Verification**
- Restoring the eager `pageText()` in `placePoints` makes the test pass
on main, which confirms the cause.
- With this change the test fails on main and passes on this branch.
- A runtime case in `tests/runtime/passage-boundaries.test.mjs` stages
bare text inside another stage's root; it fails with a sweep of the
body's stages alone and passes with this change.
- `tests/browser/projection/test_widget_actions.py` and
`tests/browser/test_shadow_stage.py` pass (17 tests), as do `pnpm run
test:runtime` (822), `pnpm run check:browser` and the pre-commit hooks.

The issue's other test,
`test_a_comment_on_a_closed_tab_s_document_never_reads_as_earlier_data`,
is already fixed on main. #5371 added it with the `.lf-fp-quote`
locator, while #5454 renamed that quote's class to `.lf-thread-quote`
and updated the test. It failed through run
[42010431285](https://github.com/max-sixty/leaf/actions/runs/42010431285),
has passed in every `ci` push run since
[42029761182](https://github.com/max-sixty/leaf/actions/runs/42029761182),
and passes locally.

Closes #5487 — automated triage

---------

Co-authored-by: leaf-agent <[email protected]>
max-sixty added a commit that referenced this pull request Nov 12, 2026
…e documents it needs (#5570)

On #4781's page, 30 tabs each holding a 4 MB text document with one
comment on Doc 23's text, and on the same page with a paragraph of prose
under its title, no load and no gesture reads more than the frame (the
page's words outside its documents, under 2 ms) and the one document it
touches: Doc 23 for the comment at load, Doc 0 for the first gesture
over it or with it in view, 58–80 ms in Chromium and 71–105 ms in
Firefox. The load's longest frame is 0.81–0.87 s in Chromium and
1.04–1.16 s in Firefox, against 5.3–5.7 s and 8.5–9.0 s on main. The
first scroll pause and click cost within 30 ms of main, which read the
whole page at load instead. A small scroll that brings the place to rest
on the prose line, and a double click on the title, take 0.12–0.29 s,
where main takes 2.2–6.4 s. A triple click holds it 0.59 s in Chromium
and 1.0–1.3 s in Firefox, against 27–28 s on main in Firefox; most of
that is the selection's capture.

This combines #5570, which finds a comment on a datum by reading that
datum alone, with the reading Max chose for it: the page's reading is
kept by part, so a change re-reads only the part it touches, and each
reader reads only the parts it needs. Since the reviews, prose is read
in the frame alone, so nothing puts the documents' words together with
it any more; the quote index is kept for each reading a search asks;
each change drops exactly the pieces it moves, found from what it
changed; and a selection finds the parts it touches by binary search
(below, "What the reviews changed").

## The reading kept by part

`passages.js` keeps the page's reading in pieces (`Piece`). Each
outermost datum is a part, read alone. The frame is the rest of the
page, read with each part left out where it stands and a fence there. A
heading, header or hgroup is never a part, since a heading in it heads
what stands outside it, and neither is a datum that runs inline with the
words around it.

`pageText()` is the frame's reading and `pageText(part)` a part's.
Nothing reads the two together, because a quote in prose never has a
copy in a part: every datum the projection draws carries `data-lf-gen`,
which makes it a passage cell of its own, fenced at both edges, so a
copy across its edge is fenced and found by no search, and a selection
whose words all lie in one datum is captured on that datum. I checked
the premise in Chromium on every example that draws datums
(`pr-walkthrough`, 32 datums; `github-discoveries`, 8; `review-a-fix`,
5; `command-hub`, 5; `live-progress`, 1) and on the reviewer's
two-document fixture: every datum is fenced at both edges, and no search
matches across one. One capture broke it on main: a selection starting
in the newline before a document and ending in its first line was
captured as a prose anchor whose words stand inside the document. A
selection's whitespace-only ends are no part of its passage now, so that
selection is captured on the document; a selection whose words cross a
part's edge is captured detached, which it already was in effect, since
its copy is fenced.

The owner of each change drops exactly the pieces it moves:

- The watcher's records go through `touch`. Words edited inside a part
drop that part. A node put into or taken out of the frame drops the
frame and any kept part inside it. A change to the markers the walk
reads on an element (chrome, a datum's own marks) drops the piece it
stands in and every part under it, and the frame where the element is a
part's root. Anything that changes which slot shows a host's child drops
everything under the host: the host's children, a slot put into or taken
out of its tree, a node's `slot`, a slot's `name`. A batch of records
finds the kept parts it moved from the nodes it changed down, through
the declared trees under them; a node that holds a slot of its declared
tree stands over the host's children the slot shows, so the parts go
from that host down, and on up while the host holds a slot in turn
(`forgetPartsBeneath`). So hearing a change costs what it changed,
however many parts are kept.
- The two doors for changes no record reports, `fencePassageParts` and
`watchPassageRoot`, go through `changedAt`, which drops what a marker
change at that node would.
- A new vocabulary or settlement drops every piece, as before.

What an element inside a part answers (`elementReading`, `keptAnswer`)
is kept under that part's token, so it stands while other parts change.

Each reader reads only the pieces it needs:

- **A quote in prose** is captured and found in the frame; **a quote in
a datum** in its part.
- **The quote index** is kept for each reading a search asks: the
frame's, and each datum's own, whether the datum is a part, stands in
one, runs inline or is a heading. A reading's copies of every quote the
threads name that it lacks are found by one pass over it when a search
first asks it for one, and carried from one reading of the same words to
the next, so a rewritten line re-places only the threads quoting it.
- **The outline** is the frame's, with the headings of each part that
holds one spliced in. A part with no heading in it, in a declared tree
under it, or among what its slots show, needs no walk for the outline.
What stands over an element in a part joins the part's own record to the
frame's at the part's root, so a part is walked for its outline only
when someone asks about an element in it.
- **The reading place** reads the frame and the parts that may show in
the window (`mayShow`). It asks a part the page skips, as in a closed
tab, nothing beyond `drawn`: asking such a part for its box or style had
Chromium style everything in it, 240 ms for the 29 closed documents
here. A box holding a part holds text wherever the part stands.
- **A selection** is captured in the reading of the piece it stands in,
and each end snaps in its own piece's reading. Where a range stands
among the parts is a binary search over the frame's marks, which are in
reading order, so it compares a few parts however many the page holds; a
range across a part's edge takes its segments from the frame and each
part it touches.
- **A search** (`pageFind`) finds matches in the frame and in each part,
in reading order, since a match stands in one passage cell. The first
search reads every part.
- **A drawing** reads the parts that may show; a match's or a control's
context reads the piece it stands in (`readingHolding`).

Against main the change adds 806 production lines and removes 308 (509
and 195 outside comments), 693 and 230 of them in `passages.js`: the
pieces and their invalidation, the outline put together from them, the
per-piece quote index, the part-aware readers above, and #5570's datum
reading. It adds no option. The first review round added 399 lines and
removed 303 (252 and 191 outside comments), and the second 122 and 105
(63 and 56). By my count of the diff, reading prose in the frame alone
added about as much as it deleted: it deleted the splice, the per-part
record of datum quotes and anchor placement's prose rule, and added the
frame's fences, the search across pieces, the segments of a range across
an edge and the capture fix. The fixes for B, D, E and F added the rest.

## What the reviews changed

The first review:

- **A. Many comments on one large document.** A change to a part marked
every quote found in it changed, and each re-placement then scanned the
whole part again, once per quote. The quote index is now kept per piece:
one pass over a piece finds the copies of every quote it lacks, when a
search first asks it for one, and a change carries them through what it
changed, so a rewritten line re-places only the threads quoting that
line. This deletes the per-part record of datum quotes (`foundUnder`,
`changedUnder`) and anchor placement's rule naming which anchors are
prose, which restated `resolveAnchor`'s branch order. Test: `a line
rewritten in a part changes only the quotes standing on it`. On the
reviewer's repro (a 2.5 MB document with 50 comments, one line
rewritten, four runs each), the longest task is 397–402 ms in Chromium
and 426–451 ms in Firefox, against 289–466 ms and 495–526 ms on main and
2,053 ms and 3,036 ms in the review.
- **B. Hearing a change grew with changed nodes times parts.** A batch
of records first forgot the parts under the nodes it changed once,
climbing from each kept part; the second review's 3 replaced that with
finding them from the changed nodes down. On the reviewer's repro,
hearing 500, 1,000 and 2,000 replaced rows took 25, 88 and 345 ms in
Chromium and 34, 127 and 471 ms in Firefox in the first review; measured
below.
- **C. Prose near the top brought the whole read back.** Prose is now
read in the frame alone (above), so the reading place on a prose line, a
double click on the title and a prose comment read the frame. The splice
that put the whole reading together is gone. Tests: the pieces test
holds the frame to a fresh walk's words outside the parts; `a selection
from the space before a datum into its line is captured on the datum`
and `a selection across a datum's edge is captured detached` hold the
one capture that broke the premise. Measured below on the page with
prose under its title.
- **D. A chart beside a document out of view lost its place.** A box
holding a part now holds text wherever the part stands. Test:
`test_a_drawing_beside_a_document_out_of_view_stays_the_place`
(browser); without the rule, restoring moves the chart 132 px.
- **E1, E2. A slot put into or taken out of one part moved a child out
of or into another part's slot.** Anything that changes which slot shows
a host's child now drops everything under the host. Test:
`test_a_slot_moving_a_child_between_parts_changes_both`, both cases
(browser, since happy-dom assigns a child to every slot that would take
it); without the rule, the kept reading holds the child's words twice,
or not at all.
- **E3. The outline missed a heading a part's slot shows.** Whether a
part holds a heading counts the headings its slots show. Test: the
pieces test's first case, whose page has a slotted heading in a part.
- **E4. A datum that came to stand inside a newly marked datum stayed a
part.** A change to an element's markers now forgets every part under
it, whether or not the element is itself a part. Test: the change `a
part comes to stand inside a new part`, then `words edited in the part
that stands inside it`, which checks every element's kept words against
a fresh reading.
- **F.** `mayShow` asks `drawn`, which `skipper` now exports from
shadow-tree.js, rather than repeating it; `pageRuns` and `pageBlocks`
always take their part filter, and the tests that called `pageBlocks()`
pass one.

The second review:

- **1. A selection asked every part whether it covered it.**
`segmentsIn` ran on every selection change and tested each of the
frame's marks against the range, 7.9 ms in Chromium and 14 ms in Firefox
with 5,000 datum rows below the prose. The marks are in reading order,
so the parts a range covers now run from the first mark not before its
start to the first not before its end, found by binary search, with the
part its start stands in just before them; a range across a part's edge
gathers the frame's segments and each touched part's, each clipped by
its own binary search, rather than every run of the page. Test: `a
selection compares a few parts' places however many the page holds`,
which counts the steps up the reading's tree: 170 for a selection in
prose beside 100 parts and 230 beside 1,000; scanning the marks fails
it. `a selection across parts reads the frame's words and theirs in
order` holds the gather.
- **2. Quotes in a datum that is no part were never reported changed.**
Anchor placement finds a datum's quote in that datum's own words, but
only a part's reading kept an index. Every reading of an element now
registers with that element, and the index brings it to the element's
reading now. Tests: `a quote in a datum inside a part / standing in a
line / that is a heading changes when its words move`, the reviewer's
three cases.
- **3. Hearing a change in the frame climbed from every kept part.** A
batch now finds the kept parts it moved from the nodes it changed down:
each node's datums and those in the declared trees under it, and for a
node holding a slot of its declared tree, from the slot's host down, and
on up while that host holds a slot in turn. Tests: `hearing a paragraph
put in the frame costs the same however many parts are kept` (3 steps
beside 100 kept parts and beside 1,000; climbing from every kept part
fails it), which replaces the first review's B test; the pieces test's
new changes, `a slot that shows a part made a part` and `words edited in
the part it shows`; and `a change over a slot reaches the parts another
slot passes on to it`.
- **4.** `partOf` and `readingOf` are now `readingPart` and
`readingHolding`.

## Measurements

Each arm served a fresh copy of #4781's commented page directory with
`leaf server run --lifetime temporary` and a throwaway state home: main
at b14fa1e, and this branch at f90bcc6, before the second review's
fixes. Those fixes change no cost these gestures pay on this page (with
30 parts, the selection's scan of the parts was already a few
comparisons; the triple click stays in one document; the redraw changes
one document), which I read off the code and did not re-measure. The
prose variant adds one paragraph under the page's title, as the
reviewer's `perf-page3` does at a tenth the size. Each runtime logged
the page readings it took. Three rounds alternated the arms on one
shared host (load average 3–5), one browser per round, engine and page,
warmed 15 s, each load in a new context. Each gesture had its own load,
made 5 s after the comment's mark stood on its passage and every
document had drawn:

- the first scroll: a 400 px wheel over Doc 0's listing;
- the first small scroll over the prose: a 40 px wheel over the
paragraph, which brings the place to rest on its line;
- the first click: on the listing's fifth line;
- the first double click on the title;
- the first triple click: on the listing's fifth line;
- a redraw: after a wheel to warm the reading place, `leaf data set`
rewrites a line of Doc 5's source, a closed tab, and 2 s after Doc 5
redraws another wheel reads the place.

Each gesture's window opens before the pointer moves onto its target,
since resting there starts a preview. The longest frame is the longest
gap between animation-frame callbacks; the longest task is the longest
gap in a chain of zero timeouts, which only main-thread work holds back.
The page's view checks (`user-view.js`), which walk every element every
10 s, were stubbed in every arm, so a window holds only its gesture's
work ("Found along the way"). Times are in milliseconds; each cell is
the range over three loads (twelve for the load rows). The triple click
and redraw rows come from three more rounds after the last change to the
quote index. Chromium 156 headless and Firefox 157, through Playwright.

#4781's page:

| | Chromium, main | Chromium, this branch | Firefox, main | Firefox,
this branch |
|---|---|---|---|---|
| Comment on its passage, from navigation | 7,594–7,923 | 2,876–3,064 |
16,030–16,567 | 8,356–8,691 |
| Load: longest frame | 5,346–5,661 | 813–844 | 8,513–8,832 |
1,039–1,091 |
| First scroll pause: longest task | 109–113 | 127–129 | 288–305 |
292–314 |
| First click: longest task | 150–163 | 169–177 | 177–187 | 184–209 |
| First triple click: longest frame / task | 5,831–6,025 / under 50 |
437–459 / 585–589 | 5,576–5,812 / 27,335–28,148 | 679–789 / 1,001–1,263
|
| Redraw of Doc 5: longest task | 4,031–4,305 | 809–837 | 5,596–6,241 |
1,104–1,490 |
| Scroll after the redraw: longest task | 58–71 | under 50 | 104–159 |
under 50 |

The page with prose under its title:

| | Chromium, main | Chromium, this branch | Firefox, main | Firefox,
this branch |
|---|---|---|---|---|
| Comment on its passage, from navigation | 7,539–7,836 | 2,905–2,970 |
16,005–16,878 | 8,651–8,914 |
| Load: longest frame | 5,320–5,539 | 823–873 | 8,514–9,012 |
1,043–1,162 |
| First small scroll over the prose: longest task | 2,402–2,511 |
121–146 | 3,563–3,616 | 279–292 |
| First double click on the title: longest frame / task | 2,220–2,286 /
under 50 | 143–149 / 180–186 | 2,989–3,021 / 6,202–6,412 | 149–154 /
155–226 |
| First scroll pause: longest task | 110–118 | 126–137 | 295–307 |
313–327 |
| First click: longest task | 142–157 | 158–173 | 173–198 | 191–208 |

What each arm read: main read the whole page at load (2.6–2.8 s in
Chromium, 4.3–4.5 s in Firefox) and again on the redraw (2.9–3.0 s and
3.5–3.6 s). This branch read the frame (0–2 ms) and Doc 23 (61–66 ms in
Chromium, 71–87 ms in Firefox) at load, and Doc 0 (58–80 ms and 82–105
ms) on the first gesture over it or with it in view; the double click on
the title, the redraw and the scroll after it read nothing.

The first scroll and click cost Doc 0's reading on top of main, which
read the whole page at load instead; that is the 10–30 ms these rows
show. A triple click's remaining cost is mostly the selection's capture,
not the reading: in a Chromium profile, its 0.59 s task held the
selection's capture (0.28 s, of which scanning Doc 0's 4 M characters
for copies of the line took 0.19 s and comparing their context 0.09 s)
and the reading place (0.11 s, Doc 0's reading among it). Searching one
document for a quote without scanning all of it is the next lever. On
main, a triple click held Firefox's main thread 27–28 s, and in Chromium
drew no frame for 5.8–6.0 s with no task over 50 ms, which I didn't
trace. Main's small scroll over the prose, profiled in Chromium, spent
2.0 s in the place's capture scanning the whole page for the line's
copies.

The second review's cases, on the reviewer's fixture with 5,000 datum
rows added below its prose, through `leaf-dev probe --base`: main
(4b0bdd7), the reviewed head (f90bcc6) and this head, three rounds
interleaved per engine. Times in milliseconds; each one-shot cell is the
median of seven runs, and each cell the range over rounds.

| | Chromium, main | Chromium, reviewed | Chromium, now | Firefox, main
| Firefox, reviewed | Firefox, now |
|---|---|---|---|---|---|---|
| One `segmentsIn` in prose (1) | 0 | 7.8–7.9 | 0–0.1 | 0 | 14–15 | 0 |
| One `anchorForRange` in prose (1) | 0.1 | 7.8–7.9 | 0.1 | 0 | 14 | 0 |
| A drag over the prose: longest task (1) | 86–91 | 175–177 | 89–103 |
47–51 | 221–224 | 47–53 |
| A drag over the prose: time in tasks over 16 ms (1) | 91–112 | 232–310
| 89–103 | 66–70 | 583–607 | 64–72 |
| A paragraph put in the frame, every part kept: hearing it (3) | 0–0.1
| 2–2.1 | 0–0.1 | 0 | 4 | 0–1 |

Firefox reports whole milliseconds. The drag is the reviewer's
`drag-many.py` as a probe journey: 30 pointer moves across the first
paragraph, timed by a chain of zero timeouts; the reviewed head held 2–3
tasks over 16 ms in Chromium and 10 in Firefox, main and this head 1–2
and 2.

The first review's cases, main against this branch through `leaf-dev
probe --base`:

- **A**, a 2.5 MB document with 50 comments and one line rewritten
(`redraw-e2e.js`, four runs): longest task 289–466 ms on main and
397–402 ms here in Chromium; 495–526 ms and 426–451 ms in Firefox.
- **B**, 500, 1,000 and 2,000 datum rows replaced at once
(`redraw-parts.js`), two rounds: hearing them takes 2, 2–3 and 5 ms on
main, 2, 3 and 5–6 ms at the reviewed head and 2–3, 3 and 6–7 ms here in
Chromium; 10, 19 and 48–49 ms on main, 9–10, 19–20 and 48–49 ms at the
reviewed head and 10–11, 20–21 and 50–51 ms here in Firefox. Finding a
batch's parts from its 4,000 changed nodes down costs 1 to 2 ms more at
2,000 rows than climbing from the kept parts did.
- **D** (`drawn-restore.js`): the chart stays where it was after the
restore in both engines, on main and here.
- **E3, E4** (`slot-probe.js`): the outline holds the slotted heading
and the inner datum's words follow its edit in both engines, on main and
here. The probe's E1 and E2 cases compare `pageText()`, which is now the
frame and holds no part's words, so the browser test above checks those
in the parts.

## #5371's queue stays

The queue draws closed tabs' documents after the page presents and
reports their draws together. With the reading kept by part, a report
reads only the frame. Taken out, so each document reported its draw as
it landed, the 29 reports re-walked only the frame (32 walks, about 0 ms
in all) and Doc 23 once, but each report's document pass still held the
main thread about 420 ms in Chromium and 580–680 ms in Firefox, in work
other than the reading that grows with the whole page. Every document
then drew by 5.7–6.5 s in Chromium and 11.9–12.2 s in Firefox, against
3.0–3.1 s and 8.7 s batched (measured against the previous head, four
loads per arm in Chromium and two in Firefox). The batching stays, and
its comment in `lf-text-document.js` still gives the reason.

## Found along the way

The view checks (`user-view.js`, reading
`src/leaf/render-checks/view.js`) walk every element of the page every
10 s, and when the window, scheme or revision changes, calling
`checkVisibility` on each (`scrollbarClearance`). On this page each run
held the main thread 490–610 ms in Chromium and about 770 ms in Firefox,
the same in every arm. It is probably the 750 ms frame #5570's earlier
measurement saw on main about 0.5 s after a gesture. It is a whole-page
pass the reading doesn't own, so this change leaves it alone; the
measurements stub it in every arm.

## Checks

- `tests/runtime/reading-pieces.test.mjs`, at `pageText`,
`documentOutline`, `elementReading` and the quote index. After each kind
of change it holds the frame and each kept part to a fresh walk of the
whole page (its words outside the parts, a fence where each stands, each
part's words under it), every element's kept words to a fresh reading,
and the outline to one read afresh. The changes: words edited inside a
part, a break or a heading put in one, a part replaced, added and
removed, prose edited, a part's own mark taken off, prose made a part
and then edited, a part coming to stand inside a new part and then
edited, the outer mark taken off, words a part's slot shows edited, a
child given to the host whose part's slot shows it, a child moved to a
slot in another part, a part moved under chrome, chrome put over parts
and taken off, a fence put around parts, and a slot outside the declared
tree's parts that shows a part made a part and then edited. It also
holds every datum's own reading to the fresh walk. Further cases: the
outline put together from parts against one walk of `main`, a slotted
heading and a part's heading with none before it included; a change
inside one part asking no element of another anything; a rewritten line
changing only its own quote; a quote in a datum inside a part, inside a
line or that is a heading changing with its words; a change over a slot
reaching the parts another slot passes on to it; a selection in prose
and one across two parts taking about as many steps beside 1,000 parts
as beside 100 (170 and 230 in prose), and one across parts reading the
frame's and their words in order; and a paragraph put in the frame
costing the same 3 steps beside 1,000 kept parts as beside 100.
- `datum-quotes.test.mjs`: capturing a selection inside a datum reads no
words outside it; a selection from the newline before a datum into its
line is captured on the datum; a selection across a datum's edge is
captured detached.
- `tests/browser/test_reading_pieces.py` (new): a slot put into or taken
out of one part, moving a child between parts, both in a browser; a
search finding each match in prose and in every part, in reading order.
`test_reading_position.py` adds the chart beside a document out of view.
- Breaking each rule in turn turns a test red, and restoring it turns it
green: the six forgetting rules (characterData, a host's children, nodes
put in or taken out, a node's slot, a marker on a part's root, parts
under a marker change), parts under a new part (E4), a slot put in or
taken out (E1, E2, browser), forgetting the batch's parts at all,
forgetting per node rather than per batch (5,750 against 21,500 climbs),
the frame's fence where a part stands, the outline's join, its part
headings and slotted headings (E3), the piece index for a quote, a datum
reading's index and `pieceReading` for any element (2), the binary
search over the marks (1), the datums under a changed node, the declared
trees under it, the climb over a slot and its second step, and finding
parts from the changed nodes rather than climbing from every kept part
(3), the selection's whitespace trim, the detached capture across an
edge, and a box holding a part holding text (D, browser).
- `pnpm run test:runtime` (935 pass), `pnpm run check:browser`, and the
pre-commit hooks on the changed files.
- The 76 browser tests whose bodies touch a quote on projected data or a
text document, with the new ones (107 cases), by node id: 105 pass. Two
fail identically on main's tree (b14fa1e):
`test_call_diff_source_paths_do_not_alias_durable_rename_coordinates`
and
`test_visual_review_keeps_its_inline_comment_editor_in_view_after_phone_resize[760]`.

## Calls Max may reverse

- **Prose is read in the frame alone.** A prose anchor no longer counts
copies inside documents. Where main would let a prose comment move onto
a copy inside a document once its own words changed, it now detaches, as
Python's reading of the page's files, which holds no datum, already
reads it.
- **A selection's whitespace-only ends are no part of its passage**, so
a selection from the newline before a document into its first line is
captured on the document. A selection whose words cross a part's edge is
captured detached at once, with no context, where main reached a
detached anchor with context through its search.
- **Each end of a selection snaps in its own piece**, so a selection
inside one document no longer snaps past its edges, and one across an
edge gets no sentence snap, as on main.
- **What a part is.** Only the outermost datum the walk meets is a part.
Nested datums are read with their part; a datum that is a heading,
header or hgroup reads with the frame, and so does one that runs inline
(a `span`). Data drawn without datum marks stays in the frame.
- **A search reads every part** the first time it runs, since it
searches the whole page.
- **A change at a node holding a slot** forgets every part under the
slot's host, not only those the slot shows, so the rule needs no
assigned-node lists and covers slots that pass on what they show.
- **Memory.** Each part read keeps two records per text node (the walk's
and the indexed reading's), so a page whose every part is read, as by a
search, keeps about twice what main kept for its whole reading (read off
the code, not measured). On #4781's page only Doc 23 and Doc 0 are read.

## Not verified

- WebKit.
- A prose comment on the large page, end to end; by construction its
search covers the frame, and the prose variant's place capture shows
that cost.
- A search's first run on the large page, which reads all 30 documents;
not measured.
- A real drag across a document's edge in a browser; the capture and
snap across an edge are tested in the runtime's DOM.
- The browser tests beyond those that touch a quote on projected data or
a text document.

Part of #4781

Part of #5753: a change inside a datum now re-reads only that part. A
change in prose still drops and re-walks the whole frame, and placement
still compares the frame's old and new readings; that is what remains of
it.

> _This was written by Claude Code on behalf of max-sixty_

https://claude.ai/code/session_01GQAnFBpRfi8Gh5cgPofNzs

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
max-sixty added a commit that referenced this pull request Nov 12, 2026
…ts its draw as it lands (#5872)

After a closed tab's document draws, the document pass that follows
takes 5–10 ms in Chromium and, at the median, 6–12 ms in Firefox,
whether the page holds 3 text documents of 4 MB or 30. On main it took
340–410 ms in Chromium and 380–960 ms in Firefox, most of it re-reading
documents that hadn't changed. With the pass that cheap, #5371's
batching of closed tabs' draw reports goes: each document reports its
draw as it lands. On #4781's page the longest task while Doc 5 is
rewritten drops from 847–968 to 494–576 ms in Chromium and from
1,364–2,044 to 815–1,021 ms in Firefox, and the longest frame while the
documents draw from 882–985 to 624–738 ms in Chromium. Load times move
less: in Chromium the comment on Doc 23 stood on its words 0.2–0.9 s
sooner round for round, and in Firefox the closed tabs' times overlap
between arms, so no Firefox load-time win is claimed.

## What re-read the page after each draw

A document's draw report (`drawn`, which stamps its data's provenance)
starts a document pass. On #4781's page (30 tabs, each a 4 MB text
document, one comment quoting a line of Doc 23), three parts of that
pass read far more than the document that drew:

- **The annotation inventory** keyed the comment's margin row by reading
all of Doc 23 again (`passageRows`): 198 ms in Chromium. The key depends
only on the target's words and the passage, so it is now kept under the
target's piece of the page's reading (`keptAnswer`, from #5570), by
where the passage starts and what it says. A collection reads a target
again only when its words change or a passage in it is new.
- **Two labels** in the same collection, the outline subject and the
row's title, each collapsed and split all of Doc 23's words to cut a
60-character excerpt: 23 ms each. `excerptWords` now reads only as much
of a value as holds more than its cap once collapsed, doubling the read
until it does. On 200,000 random values (whitespace runs, surrogate
pairs, caps 1–80) it cuts the same as the whole-value rule.
- **The visual action plan** queried every element of the page for
pictures (`svg, img, figure` and declared visuals): 57 ms on 30
documents. It now asks `readingElements(visualTags())`, new in
`passages.js`, for the elements with those tags that stand where the
page reading reads its words, in reading order. Each piece's are kept
until that piece changes. The frame's are among the elements its walk
enters, which its outline already records (`over`); a part's come from
native queries of its trees and of what their slots show, keeping those
the walk reaches: 2 ms for one document. It takes tag names rather than
a selector because the watcher drops changes to `id` and `class`, so a
selector on them would go stale. On all 24 shipped examples it returns
the same candidates in the same order as the old query.

The Layout's header was found by `:scope > header` on the layout box,
which walks every element under it, 6 ms a layout read here. It is now
read off the box's children, as `passages.js` already does for `main`.

## The report batching goes

#5371 made closed tabs' documents report their draws together once the
last had drawn, because each report's pass grew with the page; its
comment called the batching a stopgap until a pass costs what the change
it follows does. With the pass at 5–12 ms, the batching only holds a
comment on a closed document back until every other document has drawn.
Each document now marks its text and dispatches `drawn` in the turn it
draws. The queue that draws closed tabs after presentation, one a task,
stays: it keeps presentation from waiting on them.

A third arm kept the batching on top of this branch's passes ("batched"
below). It placed the comment later than this branch in two of three
Chromium rounds and drew every document no sooner. Without the batching,
Firefox drew the last document 0.2–0.5 s later than main in each of
these rounds, about the 29 passes of 8–12 ms that now run as documents
draw rather than none until the last; an independent review's own
Firefox loads put the closed tabs' medians at 9.2 s and 9.8 s,
overlapping, and saw no extra long frame per document.

## Measurements

These numbers are from the first commit. The second changes only which
elements `readingElements` keeps and their order; timed again on the
30-document page, two loads per engine, its pass after a closed
document's report reads 6.3–6.7 ms median in Chromium and 8.0–10.5 ms in
Firefox, and Doc 5's rewrite 5.5–5.9 ms and 7–11 ms.

Each arm served a fresh copy of #4781's page directory from its own tree
(`leaf server run --lifetime temporary`, throwaway state home): main at
ce24dda, this branch, and this branch with main's
`lf-text-document.js` ("batched"), each on the 30-document page, and
main and this branch on a copy holding only Docs 0, 5 and 23. Rounds
alternated the arms in an order that rotated each round, one warmed
browser per round and engine (Chromium 156 headless, Firefox 157,
through Playwright), each load in a new context, load average 8–26 from
other sessions. After every document drew and the comment stood on its
words, a wheel over Doc 0 warmed the reading place, then `leaf data set`
rewrote one line of Doc 5, a closed tab. Times are milliseconds on the
page's clock; each cell is the range over three loads.

The document pass, timed by wrapping each region's paint in the arms'
runtimes (`semantic-state.js`) and summing paints that run back to back.
Main reports every closed document in one task, so it has no pass per
document; its passes over the load follow that one task.

| Chromium | main, 30 | this branch, 30 | main, 3 | this branch, 3 |
|---|---|---|---|---|
| Pass after a closed document's report, but Doc 23's: median | – | 6.4
| – | 6.5–7.9 |
| Same, longest | – | 7.5–10.3 | – | 6.5–7.9 |
| Pass after Doc 23's report, which places the comment | – | 599–610 | –
| 592–641 |
| Passes over the load after presentation, summed | 796–860 | 782–794 |
662–726 | 599–649 |
| Doc 5 rewritten: passes | 373–414 | 5.7–6.7 | 338–371 | 4.9–6.1 |

| Firefox | main, 30 | this branch, 30 | main, 3 | this branch, 3 |
|---|---|---|---|---|
| Pass after a closed document's report, but Doc 23's: median | – | 8–12
| – | 6–11 |
| Same, longest | – | 9–35 | – | 6–11 |
| Pass after Doc 23's report, which places the comment | – | 190–364 | –
| 178–1,237 |
| Passes over the load after presentation, summed | 984–1,321 |
825–1,723 | 855–1,430 | 617–3,524 |
| Doc 5 rewritten: passes | 563–961 | 6–182 | 383–610 | 6–36 |

Firefox's ranges follow the host's load average: the 182 ms rewrite and
the 1,237 ms placement are single loads at 24–26, whose arms' other
loads read 6–12 ms and 178–230 ms.

Load and rewrite as the page shows them. The longest task is the longest
gap in a chain of zero timeouts, which only main-thread work holds back.

| Chromium | main, 30 | this branch, 30 | batched, 30 | main, 3 | this
branch, 3 |
|---|---|---|---|---|---|
| Every document drawn | 3,341–4,349 | 3,179–4,203 | 3,126–4,541 |
1,251–1,634 | 1,207–1,612 |
| Comment on its words | 3,341–4,349 | 2,753–3,725 | 3,127–4,541 |
1,251–1,634 | 1,208–1,612 |
| Load: longest frame | 882–985 | 624–738 | 815–872 | 720–754 | 645–673
|
| Doc 5 rewritten: longest task | 847–968 | 494–576 | 474–522 | 667–738
| 339–379 |

| Firefox | main, 30 | this branch, 30 | batched, 30 | main, 3 | this
branch, 3 |
|---|---|---|---|---|---|
| Every document drawn | 9,367–12,465 | 9,840–13,005 | 10,402–16,421 |
2,560–4,097 | 2,567–5,266 |
| Comment on its words | 9,367–12,465 | 8,240–11,085 | 10,402–16,421 |
2,560–4,097 | 2,567–5,266 |
| Load: longest frame | 1,099–1,588 | 997–1,397 | 1,187–2,912 |
987–1,379 | 864–1,658 |
| Doc 5 rewritten: longest task | 1,364–2,044 | 815–1,021 | 812–1,744 |
1,113–1,866 | 587–1,034 |

In Firefox the time until every document has drawn is mostly the
documents' own draws: 29 frames over 150 ms, 7.4–9.9 s together, in
every arm.

Where Chromium's main thread went in the rewrite of Doc 5, from a CPU
profile of each arm, two loads each, alternated:

| ms | main, 30 | this branch, 30 | main, 3 | this branch, 3 |
|---|---|---|---|---|
| The document pass | 314–320 | 6–7 | 275–280 | 6 |
| Doc 5's own draw | 283–284 | 293–294 | 293 | 283–309 |
| Decoding the state answer | 101–105 | 103 | 10–11 | 11 |
| Garbage collection | 147–150 | 46–47 | 153–174 | 19–33 |
| Native, unattributed | 132–162 | 131–137 | 51–59 | 56–63 |
| Total | 1,084–1,128 | 680–689 | 839–862 | 422–472 |

The rewrite still costs 210–270 ms more on 30 documents than on 3, none
of it in the pass. The state answer that follows any data change carries
every source's value, since `Leaf-Data-Version` names the data as a
whole (`http.py`): 124 MB here against 12 MB. Decoding it took 108 ms
against 10 in Chromium and 143 against 24 in Firefox, besides the copy,
its comparison with the held data (`share`) and its garbage. That is the
data delivery, which this change leaves as it was.

## Checks

- `tests/runtime/reading-pieces.test.mjs`: after each kind of change it
already applies, `readingElements` returns every element of the page
with the asked tags outside chrome, each once, compared by identity,
slotted and staged ones included; its order matches the outline's; a
part's elements are those the walk reaches, in its order, leaving out a
light child no slot shows; and a change inside one part asks nothing of
another part's elements. The `elements` helper now reaches a declared
tree inside another. Keeping a part's or the frame's matches past a
change, or removing the reach filter, the reading-order sort or the
frame's read filter, turns a test red.
- `tests/runtime/annotation-inventory.test.mjs`, new test: a collection
after a change elsewhere reads none of the quoted target's elements and
keeps its key; a change to the target's words reads it again and
renumbers the key. Removing the keeping turns it red.
- `tests/runtime/words.test.mjs`, new: an excerpt of a long value cuts
as one of all of it would, past a run of whitespace and a surrogate pair
split where the first read ends.
- `tests/browser/widgets/test_code_and_documents.py`: the drawing-order
test now expects each closed document to announce as it draws, and the
test of a tab opened while documents draw becomes one that a document
reports its draw while later ones still wait. Both fail with main's
`lf-text-document.js`.
- `pnpm run test:runtime` (950 pass), `pnpm run check:browser`,
pre-commit on the changed files.
- Browser tests at this head, by `-k`: the text-document tests in
`test_code_and_documents.py` (25), the visual-target tests in
`test_render_reactions.py`, `test_render_semantic_selection.py` and
`test_render_pages.py` with
`startup/test_readiness.py::test_visual_comments_arrive_with_the_initialized_document`
(26), and the quoted-passage rows, revisions and sticky headers in
`margin/`, `test_render_anchors.py` and `test_workspaces_and_bounds.py`
(13). Three fail, each the same way on main's tree here (c5739b8):
`test_render_pages.py::test_a_marked_scrolling_visual_keeps_its_keyboard_focus_ring`
(the diagram has no `tabindex`; it also fails at ce24dda),
`test_render_semantic_selection.py::test_dense_selection_hints_stay_short_and_reach_an_atomic_visual`,
and
`test_code_and_documents.py::test_a_text_document_update_keeps_a_selection_it_carries_into_another_run[browser]`,
which passed here before the rebase onto c5739b8.

## Calls Max may reverse

- **The batching goes.** A page of many closed documents now runs a pass
per document as each draws, 5–12 ms each here, where it ran one at the
end; in Firefox the last document drew 0.2–0.5 s later than on main.
- **The plan's pictures are the page reading's.** `readingElements`
keeps the elements the walk reaches where the page reads its words, so a
picture among a declared widget's light children that no slot shows,
which nobody sees, or inside silenced words, no longer gets a "Respond
to" proxy; candidates come in reading order rather than the light tree's
followed by each shadow tree's. On the shipped examples nothing differs.

## Not verified

- WebKit.
- A comment quoting prose whose block is in the frame and holds parts,
such as words directly in a `section` of documents: its target is read
again after every change, as on main.

Part of #5194. All four costs that issue names stay open after this:
per-input work growing with the square of the widgets, images refetched
on every load, `/api/state` resending the whole state on every change
(here 124 MB after a one-line data change on the 30-document page), and
forced layout while scrolling past comment threads. This PR cuts a
neighbouring cost, the passes after a closed tab's document draws.
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