Skip to content

Carry the page reading's context down its walk, and route text walks through it - #1334

Merged
max-sixty merged 5 commits into
mainfrom
perf/passage-walk-context
Sep 27, 2026
Merged

max-sixty merged 5 commits into
mainfrom
perf/passage-walk-context

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 27, 2026 •

Copy link
Copy Markdown
Owner

The passage walk asked every text node where it stood by climbing: uiInside and closest(silenced) per node for says, then readPage climbed again for the generated element and for the passage cell (upFrom to the body for an ordinary paragraph), readSegments and pageBlocks climbed for each segment's block, and readPage pushed one {node, offset} object per character into origin while growing raw a character at a time. On the corpus (208k characters, 8.5k text nodes, 9.3k elements) a rebuild took ~18–22 ms, most of it in closest.

One walk that carries its context (#23). The walk now carries a context down the composed tree (enter). Each element says once whether it starts chrome (a declared label nearer than .lf-ui wins), silence, generated words, a text block, a Markdown island, or a passage-cell candidate. It asks each with matches against the selectors the point readings climb with (UI_MARKS/SAID for uiInside, GENERATED for authored, TEXT_BLOCK), so a marker added to one of them reaches both; chromeMark is uiInside's rule at one element, and the watcher's speaks asks it too. Chrome, silence and the generated marks start over inside a declared shadow root, as closest does. Blocks and cells cross it, as closestAcross/upFrom do. A slotted node reads in its host's light context, and a reading rooted at a shadow root starts from its host's context with the tree-local facts crossed. contextAt folds the same enter over an element's ancestors: the walk starts from it at its root, and the watcher's pageReads asks it where a mutation landed. What the reading skips and what it ignores changing are therefore one rule, run in two directions. The composed-tree walk is otherwise unchanged: declared x-shadow roots only, slots by assignedNodes({flatten: true}), and the boundary hook that render-checks' shownVerbatim uses.

pageText() drops origin for a segment index. starts[k] is where segment k begins in raw, raw is joined from slices, and pointAt(reading, i) (a binary search) is the one way from a position to {node, offset, segment}. spanOf, neighbourhood, findQuote, findText, contextAround and capture's snapping all read through it. neighbourhood now takes the reading rather than (origin, fences). Each segment carries the block its walk knew (segmentBlock gives the unit a quote's seam space breaks on) and the generated element its words stand in (gen), so quoteFrom, pageBlocks, capture's sameRun, the target chooser's matchOwner and anchor resolution's place no longer climb. The two opaque-part sets are one passageFences.

The readings are named: textNodesUnder(root, "says" | "wrote" | "unsilenced", boundary). unsilenced is the render check's "is a settled slot still showing words" reading, which passed a predicate before. Like every reading, its chrome is bounded at the root's frame, which for a settled slot (lf-old, lf-new) is the slot itself; the predicate used unbounded inUi. They differ only for a holder outside .lf-chrome but under a bare .lf-ui ancestor, where the words the slot still shows are now reported as showing. elementReading(el, reading) keys its kept value by reading name as well as element. It keyed by element alone, so a wrote after a says would have returned the says answer. It also answers a kept value before asking where the element stands, and keeps nothing for a node of another document (a parsed revision).

Text walks outside passages.js (#27).

  • capturePlace reads a block with elementReading instead of walking it per candidate on every revision install. blocksOnScreen asks readingRegionFor once per block.
  • Drawing reads pageText().segments.
  • leadingTitle and addressableSays use elementReading, and so does domValue (projection/authored.js).
  • The version view's inline comparison uses the named wrote reading, since it needs readingFrom's units.

One walk stays: go-to-sequence's innerText names chrome controls by their rendered text, which includes chrome, leaves out CSS-hidden text and applies text-transform. The passage readings are structural by design, so that the file side can reproduce them, and none of them is that reading. Its layout is already clean by then, since the loop reads badgeBox and checkVisibility first. The omitted branch of addressableSays is already gone on main.

Measured on the corpus, on a shared machine running three other agents' suites:

base (origin/main) this branch
pageText() rebuild, in page (4 rounds, median of 25 each) 17.6 ms 6.2 ms
move, paired one_transition.py corpus move 10 (painted, median) 91 ms 68 ms
move, profile_page.py per run: closest self / pageText inclusive 14.1 / 23.5 ms 0.5 / 8.3 ms
revision, profile_page.py per run: closest self / pageBlocks inclusive / activateRevision inclusive 46.2 / 65.6 / 208 ms 3.4 / 14.3 / 152 ms

The paired revision runs (2 × 4) are dominated by noise at load ~40 (1.3–5.0 s per run on both arms): base median 2.6 s, head 2.3 s. The profile rows above are what attributes the change.

Tests. passage-boundaries.test.mjs gains cases for the carried context: chrome stops at a declared root, a slotted node reads in its host's chrome, and a declared label is read to its last word. It also covers a reading rooted at a shadow tree reading in its host's block, pointAt across empty text nodes and edges, and says and wrote kept apart; its fence case moves to the new neighbourhood signature. Each new case fails with its mechanism reverted. Run locally: npm run test:runtime, test_render_anchors, test_revision_delivery, test_render_drawing, test_render_aim, test_render_widgets, test_render_projection, test_render_gate, and test_render_navigation. test_render_navigation::test_a_delayed_thread_reveal_reports_that_new_user_focus_cancelled_it fails locally, and fails the same way on origin/main (ad29d53); so do test_render_anchors::test_a_diff_surface_keeps_the_complete_thread_lifecycle_inline[light|dark].

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

🤖 Generated with Claude Code

max-sixty and others added 4 commits September 27, 2026 12:07
…through it

The passage walk asked every text node where it stood by climbing: `uiInside` and
`closest(silenced)` per node for `says`, then `readPage` climbed again for the
generated element and for the passage cell (`upFrom` to the body for an ordinary
paragraph), `readSegments` and `pageBlocks` climbed for each segment's block, and
`readPage` pushed one `{node, offset}` object per character into `origin` while
growing `raw` a character at a time. On the corpus (208k characters, 8.5k text
nodes, 9.3k elements) that made a rebuild ~20 ms, most of it `closest`.

The walk now carries a context down the composed tree (`enter`): each element says
once whether it starts chrome (a declared label nearer than `.lf-ui` wins), silence,
generated words, a text block, a Markdown island, or a passage-cell candidate.
Chrome, silence and the generated marks start over inside a declared shadow root,
as `closest` does; blocks and cells cross it, as `closestAcross`/`upFrom` do. A
slotted node reads in its host's light context. `contextAt` folds the same `enter`
over an element's ancestors: the walk starts from it at its root, and the watcher's
`pageReads` asks it where a mutation landed, so what the reading skips and what it
ignores changing are one rule run in two directions.

`pageText()` drops `origin` for a segment index: `starts[k]` is where segment k
begins in `raw`, `raw` is joined from slices, and `pointAt(reading, i)` (binary
search) is the one way from a position to `{node, offset, segment}`. `spanOf`,
`neighbourhood`, `findQuote`, `findText`, `contextAround` and capture's snapping all
read through it; `neighbourhood` takes the reading rather than `(origin, fences)`.
Each segment carries the `block` its walk knew (`segmentBlock` for where a quote
puts a seam space), so `quoteFrom`, `pageBlocks`, capture's `sameRun` and anchor
resolution's `place` no longer climb.

The readings are named: `textNodesUnder(root, "says" | "wrote" | "unsilenced",
boundary)`. `unsilenced` is the render check's "is a settled slot still showing
words" reading, which passed a predicate before. `elementReading(el, reading)` keys
its kept value by reading name as well as element (it keyed by element alone, so a
`wrote` after a `says` would have returned the `says` answer), answers a kept value
before asking where the element stands, and keeps nothing for a node of another
document (a parsed revision). The two opaque-part sets are one `passageFences`.

Text walks outside passages.js move to the owner: `capturePlace` reads a block with
`elementReading` instead of walking it per candidate on every revision install,
and `blocksOnScreen` asks `readingRegionFor` once per block; drawing reads
`pageText().segments`; `leadingTitle` and `addressableSays` use `elementReading`;
`domValue` (projection/authored.js) uses `elementReading`; the version view's
inline comparison uses the named `wrote` reading.

Two walks stay. `addressableSays`'s `omitted` branch subtracts a subtree that varies
per call, so it walks the owner's `says` segments and filters them rather than keep
a cache keyed on the pair. go-to-sequence's `innerText` names chrome controls by
their rendered text (chrome included, CSS-hidden text excluded, text-transform
applied); the passage readings are structural by design, so the file side can
reproduce them, and none of them is that reading.

Tests: `passage-boundaries.test.mjs` gains cases for the carried context (chrome
stops at a declared root; a slotted node reads in its host's chrome; a declared
label is read to its last word), for `pointAt` across empty text nodes and edges,
and for `says`/`wrote` kept apart; its fence case moves to the new `neighbourhood`
signature. Each new case fails with its mechanism reverted.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	skills/leaf/assets/runtime/anchor-resolution.js
…ce once

An element whose attributes start nothing (a class, an id) now returns its parent's
context rather than a copy of it, and a childList record asks pageReads of its
target once rather than once per added or removed node.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
leaf-agent previously approved these changes Sep 27, 2026
A reading rooted at a shadow root started from nothing, so its words lost the host's
block: `says(host.shadowRoot)` over `<span>12</span><span>%</span>` inside a `<p>` read
"12 %" where it read "12%" before (render-checks' x-says check reads this way). It now
starts from the host's context with the tree-local facts crossed, as the walk does
when it enters that tree.

The walk's marker tests are the selectors the point readings climb with, asked with
`matches`: `UI_MARKS` (now exported beside `SAID` for `uiInside`), `GENERATED` (which
`authored` climbs with), `GEN`, `ISLAND`, `TEXT_BLOCK`. `chromeMark` is `uiInside`'s
rule at one element, and the watcher's `speaks` asks it instead of
`uiInside(node, node)`. Segments carry the generated element their words stand in
(`gen`) beside their block, so capture's `sameRun` and the target chooser's
`matchOwner` read the segment instead of climbing. `unsilenced` states that its chrome
is bounded at the root's frame.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 8fbb2ac into main Sep 27, 2026
5 checks passed
@max-sixty
max-sixty deleted the perf/passage-walk-context branch September 27, 2026 20:19
max-sixty added a commit that referenced this pull request Sep 27, 2026
)

Activating a revision took every authored attribute, class token and
inline declaration off `html` and `body` and put the arriving revision's
back on, including the ones both revisions write. A class taken off
`body` and put back restyles the whole document, so every corpus
revision paid a full restyle for attributes that hadn't changed. This
came out of re-profiling revisions after the recent performance PRs
(#1321, #1324, #1334).

`replaceAuthoredAttributes` now takes off only what the outgoing
revision wrote and the arriving one doesn't, and writes only what
differs, through the layer's identical-write rule (`keeps`).
Declarations are compared by name, so an empty custom property (`--x:
;`, which reads back as `""`) stays, and a newly declared empty one is
written as the single space that parses to it, since `setProperty` with
`""` removes; the old code dropped both. Runtime-owned attributes and
inline properties survive, as before; the existing live-revision test
covers adding, retiring and the runtime-owned `--lf-thread-panel-width`.

Measured on the corpus with `scripts/profile_page.py corpus revision` (3
runs each, current main, load ~20):

| | main | this branch |
|---|---|---|
| style per revision | 149.5 ms | 54.6 ms |
| install task | 313–357 ms | 160–188 ms |

Most of what's left in that task is `reachScrollers`, which #1340 takes
down separately; the two together bring style per revision to about 15
ms.

New test: a revision that changes only the title makes no authored
attribute write on either root. It fails on the old code.

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

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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