Repository navigation
Find a selection's copies by string search, and search the page a part at a time - #5875
Merged
Merged
Conversation
…t at a time On #4781's page (30 tabs, each a 4 MB text document), a triple click on a line of the open document held the main thread 460-600 ms in Chromium and 0.8-1.4 s in Firefox, and a page search held it for the whole search: about 3 s in Chromium and 5-15 s in Firefox for one word, 10 s a key in Firefox and minutes in Chromium for a common word typed. Now a triple click holds it 180-300 ms in Chromium and 220-270 ms in Firefox, and the search's own tasks each read at most one document: 220-260 ms in Chromium and 350-570 ms in Firefox on a loaded host, under 110 ms a key for a common word typed. Capture. A selection's anchor is checked unique in its datum's words, and most of that check read the whole document again, several times a gesture: - A quote's copies were found by a JavaScript pass of an automaton over every character, 85-125 ms over 4 MB in either engine. A reading's letters (its characters less whitespace and edges) are now kept with it (`spell`), taken out by the platform's own replace and marked every 32 letters, and a few quotes are found in them by the platform's string search, under 1 ms a quote; a batch of more than 32 still takes one automaton pass, so placing many comments stays linear in the page and the quotes (`eachPlace`, which `findEach` uses too). Each place is held to its quote's spaces where it stands in raw (`copyAt`), as before. - Telling a common word's 17,000 copies apart read the words around every copy. `holds` now compares a side's letters outward through raw first and refutes at the first that differs, recording that span as what it read, so only a copy whose letters all match has its words read. - Each copy was checked to stand under the datum by two binary searches and two climbs of the tree, 0.7 s in Firefox for the word's copies. A copy in an element's own reading stands under it, unless a slot of the element's own tree shows it words from outside. - The comment button's placement, the command bar and the response target each asked for the anchor again. `findQuote` keeps its answer with the reading it answered for. Page search. `pageMatches` (was `pageFind`) is a generator: it reads a part when the search reaches it, and yields null before each part and for each match the page hides. The target picker takes matches 8 ms at a time, the first slice in the input's own task and each later one in a task of its own. Matches arrive in reading order and the search lands where it did; until it lands the count slot shows an ellipsis, and after, the count grows where it stands ("so far" to a screen reader). A step past the last match or before the first stays put until the search has found them all. Tests: `tests/runtime/datum-quotes.test.mjs` holds capturing a word a datum repeats 2,000 times to reading the words beside the selected copy alone, and a datum's quote to counting no copy among the words its slot shows from outside it; each fails with its mechanism removed. `test_a_search_finds_each_match_in_prose_and_every_part_in_reading_order` also holds a search to reading no part ahead of the matches taken. The shared quote cases cover the letters and the letter check.
leaf-agent
reviewed
Nov 12, 2026
leaf-agent
left a comment
Collaborator
There was a problem hiding this comment.
One thing about how the sliced search behaves once it has landed and the picker has closed; see the inline comment.
…e index kept it From the review of the first push: - Tab past the second match across closed tabs came back to the first. Landing on a match in a closed tab changes the page's reading, so the next step searched again and stepped from no match before the new search's first slice found the old one. A step or a choice (Tab, Enter, `n`) now takes matches at once until it can be answered as it would be with every match in: the search has landed where it stood, and the match the step goes to has arrived, or the search has ended (`settle`). Main found every match before each step; this stops at the one the step goes to. A step past the last match found or before the first therefore waits for its match rather than staying put. - A quote first answered before anchor placement kept it never joined the quote index, since `findQuote` returned its kept answer before asking `copiesOf`, so a change to its words went unreported. `findQuote` asks the copies first. - The count in the search's `role="status"` changed every slice, which a screen reader may say each time. The status is now busy (`aria-busy`) while the search runs, so it is said once the search ends, and the count still grows where it stands rather than showing a total the search has passed. Tests: `test_a_walk_through_search_matches_in_closed_tabs_reaches_each_in_turn` walks four matches in closed tabs and back one, with the page's clock run fast so each slice takes one step, then Enter and `n`; it fails on the first push. "a quote first answered before the index kept it is heard when its words are redrawn" fails with the answer asked before the copies.
From the re-review: Shift+Tab from the first match while a common word's search still ran waited for the whole search, 6.8 s in Firefox for `heap` and over 15 minutes in Chromium, which Escape couldn't stop. A step back past the first match is the one step whose match comes last, so while the search runs it stays put and says "Searching"; every other step and choice still waits only for its own match. `settle` also searches again whenever the page changed under a running search, not only once it stood on a match, so a step before the search lands takes no matches from the old reading. Test: `test_a_step_back_past_the_first_search_match_stays_while_the_search_runs` holds the page's zero-delay timers, so the search stands unfinished, and checks that Shift+Tab from the first match stays and says so and that Tab goes on to the next; it fails on the previous push.
max-sixty
marked this pull request as ready for review
November 12, 2026 09:49
After Enter on a match the search field closes, but a search still finding kept running, and each page change before it ended started it again: an agent revising the page kept a common word's search going for minutes after the user was done with it. A search the field no longer shows now stops at the first page change, and only the open field's readers search again where they stood (`refreshMatches`); once it has closed, `n` searches again when the page has changed (`repeatSearch`). The closed-tab walk test's waits take the suite's deadline rather than a literal, as `test_a_wait_takes_the_suites_deadline` requires.
leaf-agent
approved these changes
Nov 12, 2026
leaf-agent
left a comment
Collaborator
There was a problem hiding this comment.
The description ends with Part of #4781, but #4781 is closed, and its follow-ups moved to #5194 ("Large pages become slow"), the open backlog issue for per-input costs on large pages. Consider Part of #5194 instead. If the three costs under "Left as it was" are added there (Firefox's first-open restyle of the search field, claimPaintedRoots walking a revealed tab, and the Chromium common-word search with its cap-or-skipper choice), they stay on the backlog after this merges. Otherwise they survive only in the squashed commit message.
max-sixty
added a commit
that referenced
this pull request
Nov 12, 2026
…ng page, and make a publication cost what it changed (#5899) On the 1,024-section page `leaf-dev bench` generates, 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 root `AGENTS.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, as `shown` at 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: | 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 `step(key, make, ...inputs)`, which keeps each result by its inputs (`keptReadings`, kept.js) and calls `make(...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`, `currentWidgetRelations` and `normalizedObligations` now 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; `share` itself 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 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`) still inherit, and each write of them restyles the thread's elements: registered as not inheriting and taken with `inherit`, they stay at their first value in WebKit, the gap that already keeps the column's room inheriting. `notes/browser-support.md` now 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, 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.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. | Input | Sections | Paint, main → branch (ms) | Shown, main → branch (ms) | CPU, main → branch (ms) | | --- | ---: | --- | --- | --- | | Send | 8 | 48.5 [48.5–52.9] → 43.7 [43.7–46.2] | 79.4 [79.4–88.6] → 89.5 [89.5–92.5] | 78.7 [78.7–82.6] → 69.8 [69.8–73.1] | | Send | 256 | 65.9 [65.9–112.5] → 54.4 [54.4–80.3] | 103.2 [103.2–112.5] → 99.0 [99.0–99.8] | 93.7 [93.7–99.8] → 84.8 [84.8–87.5] | | Send | 1,024 | 117.0 [117.0–121.4] → 92.8 [92.8–139.2] | 184.2 [184.2–197.6] → 173.7 [173.7–192.5] | 189.5 [189.5–196.3] → 152.1 [152.1–158.4] | | Resolve | 8 | 20.4 [20.4–29.3] → 18.2 [18.2–26.2] | 30.8 [30.8–44.6] → 39.3 [39.3–64.0] | 41.5 [41.5–49.8] → 41.5 [41.5–52.0] | | Resolve | 256 | 60.9 [60.9–64.7] → 39.3 [39.3–50.8] | 60.9 [60.9–64.7] → 61.1 [61.1–71.5] | 64.7 [64.7–78.4] → 51.8 [51.8–74.5] | | Resolve | 1,024 | 121.0 [121.0–130.4] → 72.3 [72.3–83.8] | 121.0 [121.0–130.4] → 118.6 [118.6–127.3] | 142.5 [142.5–149.6] → 116.7 [116.7–132.5] | | Load | 1,024 | | | 4,340 [4,340–4,373] → 4,333 [4,333–4,379] | 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. | Input | Sections | CPU, main → branch (ms) | | --- | ---: | --- | | Send | 8 | 67.1 [67.1–71.9] → 65.1 [65.1–71.3] | | Send | 256 | 111.3 [111.3–116.3] → 106.4 [106.4–115.7] | | Send | 1,024 | 272.6 [272.6–286.2] → 251.8 [251.8–258.3] | | Resolve | 8 | 38.7 [38.7–56.3] → 38.8 [38.8–48.0] | | Resolve | 256 | 84.0 [84.0–116.1] → 68.5 [68.5–88.2] | | Resolve | 1,024 | 168.9 [168.9–184.0] → 133.8 [133.8–151.6] | | Load | 1,024 | 4,077 [4,077–4,149] → 4,047 [4,047–4,068] | 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. Three kinds restyle the whole card or thread: 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`; the card's `visibility`, 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 inline `top` and `height`. #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 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`); `shareFold` answers a subtree from its last sharing only against the value it was shared as (`framework-snapshot.test.mjs`, which fails when `shareFold` 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 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). - Browser tests on the final head, all passing but three: `margin/test_page_map.py`, `margin/test_entries.py`, `drafts/test_reading_place.py`, `threads/test_layout.py` (whose `test_the_thread_card_opens_on_its_latest_message_under_its_own_name` reads 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.py` and `test_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.py` and `navigation/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_thread` and a teardown error in `test_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. - An independent review compared a live tab with a fresh load of the same log over 16 steps (picks, undo, a suggestion, reply, resolve, reopen, an agent's reply, a new version, a refused pick, a second tab), on main and on this branch. The two differ in one way, the same on both: after a pick the server refused with 422, the live tab still draws it. That difference predates this change; no other step differed. ## 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. - The thread card's fade lengths inherit, as on main, rather than being registered as non-inheriting: that version restyled only the thread and its fade, but in WebKit the fade kept its first place whenever nothing else restyled it. The note on the gap already prescribes inheriting for the column's room, and the cost is a restyle of the thread's elements per write, about 1 ms of the send's task. Part of #5194.
leaf-agent
added a commit
that referenced
this pull request
Nov 13, 2026
…till runs (#5910) After Enter closes a page search and the page then changes, `n` or Shift+`n` searches again from the match it selected. On a page whose search outlasts its first 8 ms slice, a step back from the first match could lose that place: the next Shift+`n` stepped back to match 1 instead of coming round to the last match. This keeps the place, and a new browser test fails before the change and passes after it. **Cause.** [`repeatSearch`](https://github.com/max-sixty/leaf/blob/fa76e28e332795412e71990388dbe5a50cc11093/browser/runtime/composing/target-picker.js#L675-L682) called `find` with a new query's landing ("the first match at or below the top of the window"), then cleared it. But `find` takes its first slice at once, and that slice can land before the clear. Landing with the field closed writes the match into the repeated search's position in `take`. The normal step overwrote that position again, but a step that stays put while the search runs (Shift+`n` from the first match, which says "Searching") kept the stray one. **Change.** `find` now takes its landing as one optional argument. `repeatSearch` passes none, so the search it starts lands nowhere. That removes the stray landing, the line clearing it, and an `index` argument nothing read. **Test.** `test_a_step_back_after_the_page_changed_keeps_the_match_it_stood_on` searches ten text documents, selects match 1 with Enter, scrolls it above the window and changes the page. It holds the page's zero-delay timers and lets the first slice take a dozen steps, so the search is still running when Shift+`n` says "Searching". Once the search ends, the next Shift+`n` must select the last match. On main it selects match 1. The test and the existing search and match tests in `test_render_anchors.py` (31) pass, and `pre-commit` and the browser type check pass. #5875 introduced this; the nightly review of recent commits found it. Co-authored-by: leaf-agent <[email protected]>
This was referenced Nov 13, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 14, 2026
…pace run can't freeze the tab (#5843) Page search froze the tab on some multi-word queries. `findText` joined the query's words with `(?:[ws]+|edge)+`, a nested quantifier, so wherever the page's raw text held the first word followed by a long whitespace run and then something other than the next word, the regex engine tried every split of the run. On the Using guide, "card It opens" was still stuck in `findText` when a five-minute probe gave up; a CDP pause showed the stack. The gap is now the single class `[ws edge]+`, built from `COLLAPSE_CHARS` as `GAPS` already is, which matches the same strings in one pass. Searching a part at a time (#5875) doesn't help, since the backtracking happens inside one `exec`: the new test still times out on main. The docs caption test gets back the How it works case #5836 dropped when it hit this. A new Chromium case on a small page with an 80-space run times out on the old pattern and passes on the new one. Found while landing #5836 (Ref #4052); Max asked for it to land. Tests run: the page-search browser tests in `tests/browser/test_render_anchors.py`, the passage runtime tests and `pnpm run check:browser`. > _This was written by Claude Code on behalf of max-sixty_
This was referenced Nov 15, 2026
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.
leaf-agent
added a commit
that referenced
this pull request
Nov 15, 2026
…arts it (#6042) In page search, Enter and Tab could be lost when the page changed while a search was still running. This happened when a step opened a match's closed tab, or when a revision landed. The change restarts the search with no matches in until its next slice finds one (`restart`, from #5875). The two keys were bound only while `matches` held a match, so a key pressed in that window fell through to the field. Enter then selected nothing and left the search open. `chooseMatch` and `moveMatch` already finish a running search synchronously (`settle`), so both keys now stay bound while a search is still finding matches (`searchStands`). This is why `test_a_walk_through_search_matches_in_closed_tabs_reaches_each_in_turn[browser]` timed out on main's push run [43692164348](https://github.com/max-sixty/leaf/actions/runs/43692164348). Its failure picture shows the search still open at "3 of 4" after Enter. Locally, a probe shows Shift+Tab reading "3 of 4" and the restart ("…") following, sometimes after the test has already read the count. The test passed in the two earlier push runs and locally under `--cpu-throttle` 6 to 20 and 18 concurrent copies, so the window opens only on CI's timing. **Verification:** - The new test `test_enter_selects_the_match_while_a_change_to_the_page_searches_again` holds the page's zero-delay timers, changes the page's words while the search runs, and presses Enter during the restart. Without the change it fails at the Enter assertion in Chromium and Firefox. With it, it passes 18 of 18 copies per engine under `leaf-dev suite flake`. - The 35 search tests in `test_render_anchors.py`, `pnpm run test:runtime` and `pnpm run check` pass. Refs #3985 — automated triage --------- Co-authored-by: leaf-agent <[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.
On #4781's page (30 tabs, each a 4 MB text document, one comment), a triple click on a line of the open document held the main thread 450–580 ms in Chromium and 0.9–1.5 s in Firefox, and a page search held it for the whole search: 2.6–2.7 s in Chromium and 4–4.3 s in Firefox for a word the page doesn't hold, and for a common word typed a key at a time, 6–11 s a key in Firefox and minutes in Chromium. Now a triple click holds it 185–270 ms in Chromium and 210–380 ms in Firefox, and each of the search's own tasks reads at most one document: under 200 ms in Chromium and under 380 ms in Firefox, for a word the page doesn't hold or a common word typed. Find returns the same matches in the same order, a walk through them steps as main's does, and a stored anchor resolves or detaches as before.
Two costs on Find's path are not the search and stay, both on main too: opening the search field the first time restyles the whole page in Firefox (6 s here), and landing on a match in a closed tab reveals it (1.4 s in Chromium, 1.6–5 s in Firefox). See "Left as it was".
The triple click
A selection's anchor is checked unique in its datum's words (root
AGENTS.md, "Validate once and share readings"). Profiles in both engines showed most of the gesture was that check reading the 4 MB document again, several times:spell), taken out by the platform's own replace and marked every 32 letters, 15–30 ms once a reading. A few quotes are found in them by the platform's string search, under 1 ms a quote; a batch of more than 32 still takes one automaton pass, so placing many comments stays linear in the page and the quotes (eachPlace, whichfindEachuses too). Each place is held to its quote's spaces where it stands in raw (copyAt), as before.holdsread the words around every copy. It now compares a side's letters outward through raw first and refutes at the first letter that differs, recording that span as what it read, so the index still re-places a quote when a change there could complete its context. Only a copy whose letters all match has its words read.findQuotekeeps its answer with the reading it answered for; a change makes a new reading. It still asks the quote's copies first each time, since that is what brings a quote the index has come to keep into it, so a change to a quote first answered for a selection is heard once its draft is placed.What a triple click still pays beyond its cost on the same page with 40 KB documents (89–110 ms in Chromium, 74–99 ms in Firefox): the datum's indexed reading on its first capture (14 ms in Chromium, 30–50 ms in Firefox), its letters (15–30 ms), the list of the word's 17,000 copies, which anchor placement keeps for the draft's quote, and the garbage those leave. In Firefox the three clicks run as two tasks; the second holds 120–250 ms on this branch and 180–230 ms on main.
Page search
pageMatches(waspageFind) is a generator: it reads a part when the search reaches it, and yields null before each part and for each match the page hides. The target picker takes matches 8 ms at a time, the first slice in the input's own task and each later one in a task of its own, so a search waits on at most one document's reading. Matches arrive in reading order, and the search lands where it did: the first match at or below the top of the window, else the first; after a page change, where it stood. Until it lands, the count slot shows an ellipsis; after, the count grows where it stands. The status is busy (aria-busy) while the search runs, so a screen reader says the count once, as it ends, rather than at each slice ("Searching" and "Match 3 of 120 so far" are its name meanwhile).Main searched once, as the query was typed (and again before a step after the page changed), so a step after that took 20–48 ms. Here a step or a choice (Tab, Shift+Tab, Enter,
n) waits only when its target hasn't arrived: it takes matches at once until the search has landed, where it stood if the page changed under it, and the match the step goes to has arrived, or the search has ended (settle). That matters most after a match in a closed tab: bringing it into sight opens the tab, which changes the page, so the next step searches again from where it stood. A step back past the first match is the one step whose match comes last, so while the search runs it stays put and says "Searching" rather than wait for all of it. Once Enter has closed the field, a search still finding stops at the first page change rather than start again, andnsearches again from there; only the open field searches again where it stood after a change, as a reveal makes.Measurements
#4781's page, served by
leaf server run --lifetime temporarywith a throwaway state home: main at b3387f1, the merge base, against this branch, each arm a snapshot of its tree. One browser per engine and round, warmed 15 s; each gesture on a fresh load, 5 s after the comment's mark stood and every document drew, with the page's view checks stubbed in both arms. The longest task is the longest gap in a chain of zero timeouts, which only main-thread work holds back. Arms alternate within each round; load average 3–13. The branch arm is this PR before its last change, the busy status, which redraws the count each slice as the first push did. Chromium 156 headless and Firefox 157 through Playwright. Milliseconds, one per round.heaptypedEach Find opens and closes the search once before its window, so Firefox's first-open restyle stays out of it, then pastes or types its word. "Nowhere" reads every document;
heapmatches 530,000 times. In Chromium the typed search is still running 12 s later: whether a match shows is read from its styles, and a match in a run of a text document the browser hasn't drawn makes it style that run to answer, 26 ms a run here, in 15,900 runs. The page stays live meanwhile; main's arm isn't run, sincepageFind("widget asks")had not returned after 14 minutes. On the first push, at load 12–30, a word in a closed tab held 4.1 s in Chromium and 8.7–15 s in Firefox on main; on the branch its search tasks held at most 206 ms and 349 ms, and the reveal on landing 1.4 s and 4.3–5 s. WalkingFINDTOP's 30 matches, one a document, Tab goes 1 to 6 in both engines, andnafter Enter selects the next.Steps right after typing
heapin Firefox, while the branch's search still runs (main's has ended, since it searched as the key was typed): each key's time from its keydown to the next paint, by Event Timing, three rounds per arm, alternating, load 13–31.heapMain's wrap lands on the last of the 529,957 matches, in a closed tab, and reveals it; the branch's stays on the first and says "Searching".
Profiles: Chromium through CDP's profiler, Firefox through the Gecko profiler (
MOZ_PROFILER_STARTUP), for each arm's triple click and search.Left as it was
:has()and focus rule only to 2.7 s, so I didn't find the rule. Stop every focus move restyling the page in Chromium #5844 fixed focus restyles in Chromium.claimPaintedRoots(keyboard/scopes.js) walking every element of the revealed document; 1.6–5 s in Firefox, mostly the tab's activation. A click on the tab pays the same.skipper) would end it in seconds but find words CSS hides inside a run or closed tab the browser hasn't drawn; capping the count, as Firefox's find bar does at 1,000, would too. Either changes Find's results, so it's yours to choose. The text document's line-number counters make each run's forced style 26 ms rather than 4 ms.Calls you may reverse
Tests
test_a_walk_through_search_matches_in_closed_tabs_reaches_each_in_turn(both engines): Tab walks four matches in closed tabs and Shift+Tab back one, with the page's clock run fast so each of the search's slices takes one step; then Enter selects the match andnthe next. It fails on the first push of this PR.test_a_step_back_past_the_first_search_match_stays_while_the_search_runs(both engines): with the page's zero-delay timers held, so the search stands unfinished, Shift+Tab from the first match stays and says "Searching", and Tab goes on to the next. It fails on the second push.tests/runtime/passage-boundaries.test.mjs, "a quote first answered before the index kept it is heard when its words are redrawn": fails with the kept answer asked before the copies.tests/runtime/datum-quotes.test.mjs: capturing a word a datum repeats 2,000 times reads only the words beside the selected copy (fails without the letter check, reading every line), and a datum's quote counts no copy among the words its slot shows from outside it (fails without the slot guard).test_a_search_finds_each_match_in_prose_and_every_part_in_reading_orderalso holds a search to reading no part ahead of the matches taken (fails when the search reads every part first).findEach's cases, and 42 quotes in "a line rewritten in a part changes only the quotes standing on it".Ran:
pnpm run test:runtime(951 passed),pnpm run check:browser, pre-commit on the changed files, and browser selections-k "search or find or match"(62 passed) and-k "quote or capture or selection or select or repeated or twice or datum or comment_on"(87 passed, 3 failed) overtest_render_anchors,test_render_semantic_selection,test_render_floating_panel,test_render_aim,test_reading_pieces,test_command_reference,test_render_diff_controls,test_render_gate,test_code_reviewandtest_code_and_documents. The 3 failures fail the same with main's runtime files at the merge base:test_a_text_document_update_keeps_a_selection_it_carries_into_another_run[browser],test_dense_selection_hints_stay_short_and_reach_an_atomic_visualandtest_target_hints_name_only_addressable_elements_shown_by_a_disclosure. Not run: the whole suite (CI), journeys, Safari.#5843 (open) adds the same
COLLAPSE_CHARSexport and builds the same class of gaps, whitespace and edges, infindText's pattern that this builds asGAPS. Whichever lands second should take the other's:findTextcan join its words withGAPS.source, orGAPScan move besideCOLLAPSEinkernel-facts.js.Part of #5194.