Repository navigation
Keep each unchanged record of a reading when a list loses one before it - #6001
Merged
Merged
Conversation
Publishing the server's reading of a sent comment on `leaf-dev bench`'s 1,024-section asks page took 18.3 ms; it now takes 9.9 ms, and every reader that keeps what it read by identity keeps the records the send left alone. Commenting on a question hands its obligation to the agent, so it leaves `readObligations().user`. `share` (framework/snapshot.js) compared each item of a list with the item at the same index of the prior list, so each record after the one that left was compared with its neighbour's, found different and published as a new object, and every identity-keyed reader (kept.js) read all 1,023 of them again. `share` now compares a record that has an `id` with the prior list's record of that id when the item at its index has another id. Deep equality still decides whether a subtree is replaced, so only the choice of which prior record a new one is compared with changes.
…g for a list grown at its end Review of the first commit found three faults in it. A list grown at its end built an index of the prior list by id as well as the set of its items, and the lookup then missed. The event log meets this at least twice in each reading that adds events, so sharing it cost twice what it did on main, a cost that grows with the session. `share` now returns an item past the prior list's end without comparing it, as long as every item before it stood for the prior list's item at its index, by identity or by name. Sharing a 16,000-event log grown by one event takes 0.11 ms, from 0.66 on main and 1.33 at the first commit (Node, the median of 15 interleaved trials). Two records sharing an id were both paired with one prior record, so two places in the list became one object. `share` now names a list's records by the rule the server's patch protocol names them by (`src/leaf/served_state/tail.py`, `_named`): each record's string `id`, else its event's, and only where no two records share a name. Elsewhere it compares each record with the one at its index, as on main. The test's last assertion held for any implementation. It now checks the record kept against the prior list, and adds a record gained mid-list, a reorder of new objects, records named by their events, and a list where two records share an id.
max-sixty
marked this pull request as ready for review
November 15, 2026 01:40
leaf-agent
approved these changes
Nov 15, 2026
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.
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
sharenames 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 stringid, else its event'sid, 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 ofpublish(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: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:
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 7ec8751318, 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.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) withperformance.now()around each function, unprofiled, median of five sends, before the frame that draws the message:layoutMarginRows)collectEntries)recordPlaces; itslineAnchor0.0 and 0.1 ms)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 oflayoutMountedRows, judged not worth it for about 2–6% of a send's CPU.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, andan entry stays one object until what it is made from changesholds that anaria-labelchange shows at the next collection.lineAnchortakes 0.1 ms.capturePlacestill grows, 0.7 → 2.2 ms, from visiting every text block to find those on screen (textBlocks,renderedBlocks).--lf-ring-atis registered as non-inheriting (base.css, since Say where a box's marks stand in --lf-ring-at, and draw the location ring as a mark over the decision #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:scrollToEndinshowArrival,motionTimereading 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:
renderNow2.1 → 6.3 ms, of whichreadSpokenPositions(each target's place down the page) is 2.6 andnameMarkers1.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), thederivesteps' memo (#5899),Footprints(#5866) anddrawnElements(#5871). It would not:drawnElementskeeps nothing between calls. It walks what the browser draws, askingcheckVisibility, and skips the rest.Footprintsis an index of seats built in each margin pass and dropped at its end. The margin's record across passes isseatings, which the page's observers drop: a resize, a mutation, a scroll inside a box, a transition's end.readingElementsand thederivememo are records of change for different inputs. The memo compares immutable state by identity, which needs no observer because publication shares every unchanged subtree.readingElementskeeps 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, asgatherConversations(thread/placement.js) andprepareVisualActions(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 foldingseatingsinto 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) andpnpm run check; pre-commit on both files.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.-kfromwidgets/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.pyandprojection/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
Calls Max may reverse
sharecompares 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.Part of #5194.