Skip to content

Repaint only what a publication moved, and keep a page's readings while its samples live - #2798

Merged
max-sixty merged 28 commits into
mainfrom
selection-keyed-repaint
Oct 14, 2026
Merged

max-sixty merged 28 commits into
mainfrom
selection-keyed-repaint

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

A gesture on the corpus page now repaints only what its publication moved, and the server answers its own POST without re-reading the page's source. Measured with leaf-dev bench-latency --page corpus against main (5 alternating runs, medians, painted / Sent in ms): comment 239 / 704 → 131 / 199, card move 130 / 640 → 65 / 113, agent reply Sent 664 → 140, status Sent 494 → 82. The triage board is unchanged.

Server answers. A Leaf process keeps the readings of the eight pages it read most recently, and a sample is a page of its own. The corpus opens sixteen, so its own page was evicted continually and every state answer re-checked and re-captured the whole source (0.6–1.4 s). A sample now holds its parent's memory beside its own, so a page is kept while its samples live. Work readings read registry.$work in place instead of structured-cloning it per element (about 55 ms per presentation).

Selection-keyed repaint. A publication shares unchanged subtrees with the previous one (snapshot.ts), so identity means unchanged. A document region claims a presentation only when the part of the root its reading selects moves; keys and button availability reflect only where their inputs moved; thread cards redraw only those a pass changed. Watcher paints (watchProjection and the named watchers built on it) collect the parts of the root they read and run again only when one of those moves; a whole-root read inside a watcher's paint throws, so a paint names what it draws. Runtime readers on paint paths (undo, todos, receipts, revisionLabel, approval's blocking asks) are selections of what they return. skills/leaf/assets/AGENTS.md, "Working on the runtime", states the rule.

Bench tooling. leaf-dev bench-latency narrows to a page, transition and run count; --tree times the working tree alone; it reports when the gesture's own POST was answered and who held the main thread until the last goal. leaf-dev profile reads its window through the last goal and attributes forced recalculations.

Not yet cut over. The four document regions (projection, threads, asks, the Questions panel) still declare their readings by hand because their paints span awaits; the floating panel and banner status keep hand-listed selections; the clock, projection deferral and presentation proof remain separate wake-up signals. notes/browser-reactivity.md records these and the Lit / SignalWatcher considerations. After this change, a corpus comment spends about 35 ms of its 131 ms in repaints; the rest is the gesture's forced style and layout and the server round trip.

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

max-sixty and others added 27 commits October 12, 2026 15:01
…und trip

A Leaf process keeps the readings of the eight pages it read most recently, and a
sample is a page of its own. The corpus now opens sixteen, so a server's own page
was pushed out continually, and every state answer, the event POST's included,
checked and captured the whole source again: about 0.6-1.4 s per answer on the
corpus, where the same POST to an idle server takes 27 ms. Durable servers held
their page's memory already; temporary ones (`leaf server run --temporary`, plain
previews, the suite and the latency bench) and the website's multiplexed server
did not. A sample now holds its parent's memory beside its own, so a page is kept
while its samples live, whichever server serves it.

Work readings asked `layerFact("$work")` once per element walked, and `layerFact`
structured-clones the declaration for package modules. On the corpus that was
about 55 ms of every presentation. `work.js` reads `registry.$work` in place, as
it already reads `registry.$states`.

`leaf-dev bench-latency` narrows to a page, transition and run count, and `--tree`
times the working tree alone without building arms, so one corpus comment takes
under a minute. It reports when the answer to the gesture's own POST (matched by
attempt) arrived beside painted and Sent, and who held the main thread until the
last goal, from the page's long animation frames clipped to that window. `leaf-dev profile` now reads its window through the last goal,
so a gesture's profile covers the answer's application as well as the local draw.

Measured with `bench-latency --page corpus` against main (5 runs, load 9-13),
medians: comment Sent 1187 -> 409 ms, move Sent 1168 -> 335 ms, agent reply
1044 -> 227 ms, status 850 -> 210 ms, revision 2574 -> 1893 ms; painted within
noise (comment 238 -> 202 ms, move 126 -> 139 ms). The triage board, which has no
samples, was unchanged in an earlier full run.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…nged

The publisher shares every subtree of a candidate that is deep-equal to the standing
reading's, and a selection shares its derived value against its previous one. A
selection of one part of the reading now hears only that part move, the epoch
advances by identity, and the JSON signatures that stood in for it (the epoch's,
selectWidget's memo, the traffic ledger's guard) are gone.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
applicationPresenter takes the region's reading as a selection of the semantic root
and claims inside each publication that changes it. A publication that leaves it
unchanged, such as a widget's own action for the thread, Questions and queue regions,
claims nothing, and the coordinator carries the region's standing commit into the new
epoch. Mechanical changes still claim through present.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
watchProjection selects its reading from the semantic root and paints when the
selection changes, a drag holds the projection, or PRESENTATION fires, instead of on
every semantic epoch. watchQuestions, watchQueues, watchThreads, watchHistory and
watchReports select the reading they are named for; the annotation inventory, the
reaction offer and the approval control name theirs. A return after an absence
compares the selection by identity. module-authoring.md states the narrower rule.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Shortcut reflection and native button availability ran over every scoped element
and every command button on any key paint, and every publication painted keys. On
the corpus that was ~550 elements and every button predicate per frame. Each scoped
element's reflection and each button's availability now runs as a Preact effect: a
publication that moves a signal it read marks that element or button alone. What a
predicate reads beyond signals is a mechanical change its writer reports:
paintKeys() for the page, and paintKeysWithin(root) where a renderer rewrote part of
it (a widget render or gesture resume, the composer's controls, a disclosure toggle).
Publication-driven paintKeys() calls are gone. Renderer-private state that command
predicates read is a signal: drag hands, a thread card's and the narrowing view's
models, the committed unread threads, lf-trace's cursor. widget-api exports
`signal` so a package can do the same; module-authoring.md says so.

The rest of the selection conversion:
- watchWork(owner, callback) follows what readWork reads (widget states, threads,
  asks, reports, publication time); widgets that count their children's work
  (lf-test-task, Atlas's plan) use it instead of watchReports, whose reading now
  includes the publication time saidAt answers with.
- The annotation inventory also selects the projection and waits for its chrome to
  commit, since it lists the marks that chrome paints.
- The thread region reads only its fold and the document; the margin's own watcher
  follows Questions and workflows.
- Banner status, the queue walk and the floating panel follow selections, not every
  epoch.
- Widget readings come from a per-publication index of each widget's entries, and a
  widget recomputes only when one of its inputs changed by identity.
- The visual "Respond to" plan is keyed on the page reading, presentDocument calls,
  the shown document, and visual-part layout signals rather than rebuilt on every
  thread pass.
- share() defines copied fields, so a JSON field named __proto__ stays an own field.

Behavior changes: a watcher callback that reads beyond its named reading must use
the watcher for what it reads (documented); module-authoring.md and the root
AGENTS.md invariant describe selection-keyed claims. Tests: the projection
subscription test uses the new watchProjection signature; the resolve-recovery test
also asserts the button is not aria-disabled; a sharing test covers __proto__.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	build/browser/application.ts
#	skills/leaf/assets/runtime/anchor-controls.js
#	skills/leaf/assets/runtime/application.js
#	skills/leaf/assets/runtime/asks/view.js
#	skills/leaf/assets/runtime/banner.js
#	skills/leaf/assets/runtime/floating-panel.js
#	skills/leaf/assets/runtime/keyboard/scopes.js
#	skills/leaf/assets/runtime/projection-watch.js
#	skills/leaf/assets/runtime/questions/model.js
#	skills/leaf/assets/runtime/queue-walk.js
#	skills/leaf/assets/runtime/thread/presentation.js
#	skills/leaf/assets/runtime/thread/thread-card.js
#	skills/leaf/assets/runtime/work.js
#	skills/leaf/assets/vendor/browser-runtime/application.js
#	skills/leaf/references/module-authoring.md
Key and button reflection track what they read, so an accessor that reads the whole
root (runtime's getters, readAsks, readQueues, threadState, currentProjection,
agentName, and main's new savedReadingSettled) made every reflection calling it read
again on every publication: after merging main, a card move re-reflected ~470 of the
corpus's scoped elements. readPart(derive) is a reader of one part through its own
selection; those accessors use it, and a move reflects 7-18 again.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…g is a signal

After merging main, a comment's thread pass rebuilt the page outline from a whole-page
query and placed every thread under its heading again (~20 ms), and the annotation
inventory did the same. The outline is a reading of the page's own nodes, so it stands
until the page reading moves or presentDocument says the document changed; a thread's
section stands while its record, its place and the outline do.

Where the user stands is now a signal that focused() reads, so a command whose
liveness asks where the user stands is tracked like any other input, and button
availability no longer re-reads every button on each focus move.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ands under

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A comment's thread pass re-presented every card in the panel. A card now keeps its
drawing when the list hands it the reading it last drew, compared by content with
share, and its outside inputs (a reply being written, a held draft, its open state)
stand. Cards mid-fold, holding news or owing a release draw on every pass as before.
The card's recency moved into its reading, so a card that keeps its drawing still
ages on the clock's pass. share is exported from the browser facade.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	build/browser/application.ts
#	examples/command-hub.page/widgets/lf-atlas-plan.js
#	examples/corpus.page/widgets/lf-atlas-plan.js
#	skills/leaf/assets/runtime/anchor-controls.js
#	skills/leaf/assets/runtime/asks/model.js
#	skills/leaf/assets/runtime/reactions.js
#	skills/leaf/assets/runtime/thread/presentation.js
#	skills/leaf/assets/runtime/widget-elements.js
#	skills/leaf/assets/runtime/work.js
#	skills/leaf/assets/vendor/browser-runtime/application.js
#	skills/leaf/packages/playwright/widgets/lf-trace.js
#	tests/fixtures/packages/work/widgets/lf-test-task.js
# Conflicts:
#	skills/leaf/assets/runtime/keyboard/disclosure.js
canZoomIn read the scroller's clientWidth, so every reflection of the zoom command's
liveness forced a layout of the whole page (~18 ms on a corpus comment).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	build/browser/application.ts
#	examples/command-hub.page/widgets/lf-atlas-plan.js
#	examples/corpus.page/widgets/lf-atlas-plan.js
#	skills/leaf/assets/runtime/anchor-controls.js
#	skills/leaf/assets/runtime/asks/model.js
#	skills/leaf/assets/runtime/floating-panel.js
#	skills/leaf/assets/runtime/reactions.js
#	skills/leaf/assets/runtime/registry.js
#	skills/leaf/assets/runtime/thread/presentation.js
#	skills/leaf/assets/runtime/widget-elements.js
#	skills/leaf/assets/vendor/browser-runtime/application.js
#	skills/leaf/packages/playwright/widgets/lf-trace.js
#	tests/fixtures/packages/work/widgets/lf-test-task.js
Main's offline export sets the thread presentation unavailable, and its
`current` answers null there. This branch's presenter also claims from its
`reading` selection, which ignored `available`, so an offline export painted
the margin before the overlay mounted and failed presentation
(test_linked_images_zoom_and_return_to_the_report[True]). The reading is now
null where the presentation is unavailable.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`applicationPresenter` took a `current` beside `reading`: publications
claimed from `reading`, `present` from `current`. The thread region used it
to answer while its reading stood still at "waiting", and the two disagreed
when main's offline export switched the thread presentation off. A claim
always paints, so `present` now claims `reading(root)` too and the
override is gone.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A timeline the size observer has not measured, such as one in a closed
disclosure, fell back to reading the scroller's clientWidth, so the zoom
command's liveness still forced a layout of the whole corpus page on every
reflection (~8 ms of forced style per comment). The observer's first report
clamps the zoom to the box, as it already did.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The forced-style table counted recalculations per call site and listed them by
count, so a site forcing many small recalcs outranked one forcing a few of the
whole page. Each site now reports its milliseconds per run, and the table is
ordered by them.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	tests/browser/test_render_startup.py
Unbuilt and untested: the vendored bundle is not regenerated, and the browser
suite has not run against the collected-reads watcher. Paused while the host is
on battery.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	skills/leaf/assets/runtime/floating-panel.js
The collected-reads watcher (71269c0) subscribes a paint to every selection it reads,
so how narrowly a reader selects now decides how often its callers repaint. On the
corpus page a card move took Sent from 126 to 280 ms: each of seven lf-atlas-worker
paints (~10 ms) ran on every publication, because `HeldReading.hold` read the phase
from the whole root and `passages.js` derived settlements from every widget's state.

- `collectReads` throws on a read of the whole publication, the one reader that moves
  on every publication; the phase is read through `runtime.statePhase` everywhere it
  was read whole or through a second selection, and `authoredStates` is a selection.
- Settlements are a selection per registry, so they move only when a decision does.
- `readPart` is typed from the publisher's root.
- The ask-walk test waits for the walk's landing scroll before the next walk measures
  from the screen; it failed about one run in three on the base too.

The vendored runtime bundle is rebuilt, which the WIP commit left stale. The bench
against the declared-reading baseline is now at parity (corpus comment 135/205 vs
135/202, move 64/121 vs 67/126, at load 13). notes/browser-reactivity.md records why
an effect could not track paints (the annotation paint wrote the focus signal it read
and re-ran itself without end) and the rule both regressions broke.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…wn publication

Review of the collected-reads watcher found readers that select a broad part and
narrow it afterwards, so a paint calling them repaints for changes they never return,
and one that read the whole root on a paint path, which now throws:

- Answering a question in the floating panel threw: its undo lookup read the whole
  root inside the queues watcher's paint. The undo list, to-dos, receipts and
  revision labels are now runtime getters over their own selections, and undo.js,
  floating-panel.js, annotation-inventory.js and drafts.js read them there.
- `readThreads` selects the thread collection rather than all thread state.
- A watcher whose paint publishes a change to a part it already read now repaints:
  a part's first subscriber call is compared with the value the paint read instead of
  being skipped.

skills/leaf/assets/AGENTS.md states the rule for readers a paint can call.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ey return

Both read every ask and narrowed afterwards, so the banner's approval paint ran again
for a change to any ask, such as a nonblocking reply ask's prompt.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	dev/leaf_dev/bench_latency.py
#	skills/leaf/assets/runtime/annotation-inventory.js
leaf-agent
leaf-agent previously approved these changes Oct 14, 2026
Nothing outside snapshot.ts names SnapshotReading, and the unused-exports test refuses an export no other file reads.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 439b696 into main Oct 14, 2026
3 checks passed
@max-sixty
max-sixty deleted the selection-keyed-repaint branch October 14, 2026 02:03
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