Repository navigation
Find the owners in what a mutation adds without holding every element it added - #5372
Merged
Merged
Conversation
… it added The owner watch (`watchOwner`, arrivals.js) asks each added element whether a subscription stands on it and offers only those. Watched as the selector `*`, it offered, held and looked up every element an insertion added: 1.5 million rows on loading #4781's page of 30 text documents of 50,000 lines, 0.9 s of Chromium's main thread and 1.3 s of Firefox's. A watch now holds a kind (`is`, `within`) in place of its selector; `watchArrivals(selector, …)` builds one from the selector. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The owner watch's own walk (`ownerKind.within`) had no test: every case in `arrivals.test.mjs` inserted the owner as the added node itself, so with the walk yielding nothing the file still passed. Two cases now cover an owner inside an added subtree and one inside a shadow stage, each connecting when its ancestor is inserted, disconnecting when the ancestor is removed and reconnecting when it returns; both fail with the walk broken. The walk's comment keeps its rule and drops the measurement, which belongs to the commit that made it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
max-sixty
marked this pull request as ready for review
November 4, 2026 15:15
leaf-agent
previously approved these changes
Nov 4, 2026
# Conflicts: # browser/runtime/arrivals.js
leaf-agent
approved these changes
Nov 4, 2026
leaf-agent
pushed a commit
that referenced
this pull request
Nov 4, 2026
…very row (#5371) 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_ --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
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'sWeakSetand 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 asksowners.haswhile it walksquerySelectorAll("*").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:offerManyOn main the Gecko profiler put 1.3 s of Firefox's load under the watch's
read, 1.0 s of it inofferMany. 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'sreadfalling 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: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 intests/runtime/arrivals.test.mjscover 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 withownerKind.withinyielding nothing; before them, the file passed that way, since every case inserted the owner as the added node.tests/browser/startup/test_versions.py,tests/browser/widgets/test_boards.py,tests/browser/test_render_export.pywith-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'sbrowser/andpackages/alike (the script's appended paragraph is missing after the revision), so it isn't this change.Part of #4781