Repository navigation
perf(lynx): let a commit say whether it announced its public instances - #130
Merged
Merged
Conversation
A `nodes-ref` selector is now installed only for hosts the peer announced, on ordinary create, recreate, and template-run as well as native list cells. Measuring first inverted the question #129 left open. The same 1,000 rows mounted as the first commit went out compact + lazy and cost 28 selector writes for 7,042 nodes; mounted by a later commit the identical mount-template-run went out eager and cost 4,000. Two of the run's 87 commits were compact, because transport.ts sets `instances: lazy-v1` only on a compact first or post-first-tree commit — and the main thread was reading that per-commit flag to answer a session-level question. The session had negotiated lazyPublicInstances and stayed there throughout. So the prize was never the first screen. It was every ordinary commit after it, at four writes per row: 4,000 at 1k rows and 40,000 at 10k, against zero `ensure-public-instance` announcements. One `bindNodesRefSelector` now decides every path that hands a host a physical node. The per-commit deferral stays layered above it, since the driver API admits `prepareBatch({ lazyPublicInstances: true })` without the container flag. First-screen direct emission and first-tree adoption stay eager by construction, with the reason written down: the first screen paints before a peer exists, and adoption must overwrite what that container wrote because its root id can equal the accepted root's. The lynx-table chassis counts installs, clears, and selectable nodes, and records the regime every commit went out under — an install count is unreadable without knowing whether the peer was announcing at all. `create_ref_installs_{1k,10k}` guard it against a new eager-selector-model reference at 0.01x; both measure 0. Co-Authored-By: Claude <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
The demand rule from #129 covered only native list cells. Extending it to ordinary create, recreate, and template-run mounts drops the benchmark table from 4,000 nodes-ref selector writes to 0 at 1,000 rows, and from 40,000 to 0 at 10,000. Reading the session's negotiated lazyPublicInstances capability to decide it is unsound. A background composes its first batch before the main-ready reply granting the capability reaches it, and dispatches it after, so that batch names none of the hosts it will query however the session was negotiated. The main thread, reading the reply it had already sent, skipped their selectors: the gallery example's <list ref> mounted unaddressable and its auto-scroll invoke failed with native code 2. Commits now carry the promise themselves in a new optional `announces` field, stamped from the capability captured when the batch was composed. The main thread latches its container into demand installs on the first commit that makes it, which is sound because delivery is FIFO. `instances` is decided from the same compose-time capability rather than re-read at dispatch, closing the same silent ref loss for a compact template-only first batch. Co-Authored-By: Claude <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
This was referenced Aug 21, 2026
Resolved `host-driver.ts` in the first-screen walk: new-lynx moved the create-side work into `emitHostNode` and added the `insideList` early exit for rows that own no element yet, so the eager `ensureNodesRefSelector` call this branch introduced now lives in that helper, carrying its rationale with it. Co-Authored-By: Claude <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
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.
Summary
The demand rule from #129 now applies to every mount path, not only native
<list>cells — and a commit, rather than the session, carries the promise thatmakes it safe.
The last column is why zero is correct rather than lossy: the app holds no
ref, no host lifecycle, and no main-thread callback, so the backgroundannounces no public instance and nothing can ever query those nodes.
Why
#129 left four eager install sites and called the remaining prize unmeasured,
turning on "how much of a first screen mounts through templates." Measuring it
first changed the answer.
I added a
nodes-refinstall counter and a wire-regime summary to thelynx-tablechassis and ran the same 1,000 rows two ways:cost 28 installs. The first screen was already almost free.
mount-template-runcost 4,000.So the prize was never on the first screen. It was on every ordinary commit
after it, and it scales with the tree: 4 writes per row, 40,000 at 10k.
The session flag was not the fact the main thread needed
The obvious generalization — read the negotiated
lazyPublicInstancescapability instead of the per-commit
instancesflag — is unsound, and it brokethe gallery example's auto-scroll:
<list ref={galleryRef}>mounted with noselector, so
useEffect'sinvoke('autoScroll')failed with native code 2 andthe list never moved.
web-host.test.tscaught it; instrumenting the Web hostgave the sequence exactly:
A background composes its first batch before the main-ready reply granting
the capability reaches it, and dispatches it after. So that batch names none of
its hosts however the session was negotiated, while the main thread — reading
the reply it had already sent — believed every host would be announced. This is
the exact failure
protocol.tsalready warned about abovelynxLazyPublicInstancesNegotiated: "a main thread that skips the selector whilethe background skips the announcement strips refs with no error anywhere."
The same compose/dispatch split is a latent defect in #129 as shipped:
deferPublicInstancesreads the negotiated capability at dispatch, so acompact template-only first batch composed before the reply could go out flagged
instances: lazy-v1while carrying no announcements — and lose its refs thesame silent way. This PR fixes that too.
Changes
protocol.ts— new optional commit fieldannounces: 'announced-v1',present only when the batch was composed while the capability was already live.
Validated for shape; an older main thread never negotiates the capability, so
it never receives the field.
transport.ts— the capability is captured once at compose time and usedfor both the new flag and
deferPublicInstances, instead of being re-read atdispatch.
main-thread.ts— the container's announce mode comes from the commit, andlatches on: FIFO delivery means no un-announced commit can follow an announced
one. Two new rejections:
announcesfrom a peer that did not negotiate, andinstanceson a commit that never announced.host-driver.ts— onebindNodesRefSelector(state, record)decides everypath that hands a host a physical node: install if the host already asked, or
if the commit announces nothing. The native-list paths call it instead of
repeating the condition, and ordinary
create,recreate, andmount-template-runuse it too. The per-commit deferral stays layered aboveit, because
prepareBatch({ lazyPublicInstances: true })is reachable withoutthe announcement through the driver API.
first-screen direct emission paints before any peer exists, and first-tree
adoption must overwrite what that container wrote — its root id can equal the
accepted root's, so a skipped install would leave a node answering an address
that names a different host.
benchmarks/lynx-table— the fake Element PAPI countsnodes-refinstalls and clears and the selectable nodes it creates; the wire snapshot
keeps each commit's
ack/instances/announcesand the onereadyreply'scapabilities.
run.mjsreportscreate_ref_installs_*against a neweager-selector-modelreference target, prints0/4000 refson the run line,and records the negotiated regime in
meta.rows_*. An install count isunreadable without knowing whether the commit announced at all.
ratios.json—create_ref_installs_1kand_10katmaxRatio0.01.Not zero, because an app that does hold refs legitimately pays for those
nodes; what it catches is a return to installing on every node, which reads as
1.00x.
Validation
pnpm format:checkpnpm typecheckpnpm test— 2191/2196 files, 21041/21057 tests. Five failing files, nonefrom this diff, each checked in isolation on a quiet host:
dreiupstream-e2e(container cannot fetchpotsdamer_platz_1k.hdr),dropzoneprobes/hydrationandrspeedy-pluginnative-demo(bothalready recorded as pre-existing here),
octane-events-browsersuspense-hydration > restores focused input …([0, 0]vs[2, 9],reproduces in isolation, headless selection restore), and
octane-events-browsernative-change(12page.waitForFunctiontimeouts under full-run load — 12/12 pass in isolation).
rspeedy-plugin-browserweb-hostpasses.vitest run --project lynx— 32 files, 445 tests, all passvitest run packages/rspeedy-plugin-octane/tests/browser/web-host.test.ts— 3/3 pass (this is the suite that caught the regression; it fails on the
intermediate commit and passes on the base)
node benchmarks/bench.mjs --quick --ratios --only lynx-table—13/13 applicable guards pass,
create=1 (1000r, 0/4000 refs)Two oracles in
background-root.test.ts, both over the real transport:creates" — a ref'd host and a ref'd row created by a later commit each
address their own node through
createLynxNodesRefSelector, the row's handlestill drives
setNativeProps, and#summary,#rows,#healthy,#detailscarry no attribute. Checked against two broken implementations: installing
eagerly regardless goes red on the "carries no attribute" assertions; letting
ensure-public-instancerecord the request without installing goes red onboth addressing assertions, which pins the ordering that makes a fresh create
safe.
renders the root, then installs the main thread, then awaits. Reverting the
container flag to the session-level capability turns it red, which is the
gallery failure in one jsdom test.
One existing test changed for a reason worth naming:
native-event-deliveryread
#target'soctane-refattribute to discover the live root id for aforged event token. Under this contract that node has no attribute — correctly,
since the fixture holds no ref. It now reads
main.activeIdentity()!.root,which is what it actually wanted.
Risk / follow-ups
pays one write per announced node. The saving is per node nobody queries.
the handshake completes — it announces nothing, so eager is the only sound
answer. Closing that needs the background either to compose after readiness or
to re-announce once the capability lands; both are separate slices, and both
trade against first-paint overlap. The bench harness is synchronous end to
end, so all 87 of its commits announce and it does not exercise this.
instances: lazy-v1either, since both flags come from the same compose-time capability. That
gives up deferred handle deltas on exactly the batches that were claiming them
falsely, and is the price of the flag being true.
first-tree adoption. Both are bounded by the shell rather than the content —
28 nodes for a 1,000-row screen here — and adoption cannot defer without
clearing, which costs the same write.
Provenance
agent-authored)Generated by Claude Code