Skip to content

perf(lynx): announce a batch's hosts from what composing already knows - #132

Merged
Huxpro merged 3 commits into
new-lynxfrom
perf/lynx-announce-first-batch
Aug 21, 2026
Merged

Huxpro merged 3 commits into
new-lynxfrom
perf/lynx-announce-first-batch

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 21, 2026

Copy link
Copy Markdown
Owner

Summary

The first screen stops paying for selectors nothing can query.

rows arm element nodes before after
1,000 before-render 4,029 0 0
1,000 after-render 4,029 4,028 0
10,000 before-render 40,029 0 0
10,000 after-render 40,029 40,028 0

after-render is the order a production Lynx bundle starts in. The numbers come
from the harness this PR's parent (#131) added; nothing else about it changed.

Why

A nodes-ref selector is installed only where a commit announced it would query
the host, and the announcement waited on the negotiated lazy-public-instance
capability. A background does not have that capability when it composes its
first batch — the batch is built before the main-ready reply reaches it — so the
largest tree a root ever mounts named nothing and the main thread installed on
every node of it.

Whether a batch named its hosts is a property of the background that composed
it, not of the session, and a background knows it while composing. That is the
whole change.

Changes

  • universal-core.ts — a new static capability,
    publicInstanceAnnouncements, joins lazyPublicInstances as a reason to emit
    ensure-public-instance. The two are separate reasons: a peer deferring
    public-instance metadata cannot produce a handle without being asked, and a
    peer that announces always is one whose mount-time decisions depend on being
    told before the batch ends. Drivers that declare neither are unaffected.
  • client-driver.ts — the Lynx driver declares it, from an exported
    LYNX_PUBLIC_INSTANCE_ANNOUNCEMENTS so the fact has one home.
  • transport.ts — commit.announces now comes from that fact.
    deferPublicInstances keeps reading the negotiated capability captured at
    compose, which is the coupling perf(lynx): let a commit say whether it announced its public instances #130 introduced and this must not undo.
  • main-thread.ts — drops the "unnegotiated announced public instances"
    rejection. The announcement is answerable without a session, which is the
    point; commit.instances keeps both of its rejections.
  • host-driver.ts — first-screen adoption accepts an
    ensure-public-instance operation while replaying. It creates and mutates
    nothing, and adoption stamps every adopted record unconditionally for the
    identity reason recorded at the transfer site, so the announcement is already
    answered by the time it would be replayed.
  • Docs in protocol.ts, nodes-ref.ts, and host-driver.ts now say what the
    session decides (deferral) and what the commit decides (naming).

Validation

  • pnpm format:files on the changed trees
  • pnpm sync — no generated changes
  • tsgo --noEmit -p packages/lynx/tsconfig.json,
    packages/lynx/tsconfig.testing.json, packages/octane/tsconfig.json —
    all clean. (pnpm typecheck:files on the single test file reports
    narrowing errors at lines this diff does not touch; they reproduce with
    the file reverted, so they are an artifact of typechecking one file out of
    its project.)
  • vitest run --project lynx — 32 files, 445 tests, all pass
  • vitest run --project octane — 439 files, 6,795 tests, all pass
  • vitest run packages/rspeedy-plugin-octane/tests/browser/web-host.test.ts
    — 3/3 pass. This is the real Lynx-for-Web harness, where the background
    really does compose before the reply, and it holds the gallery
    auto-scroll case perf(lynx): let a commit say whether it announced its public instances #130 fixed.
  • node benchmarks/bench.mjs --quick --ratios --only lynx-table — 13/13
    applicable guards pass, every count byte-identical to the pre-fix run
    (select=2 (252B, 2r), swap=2 (395B, 0r)), which is the evidence that a
    tree naming nothing pays nothing new.
  • node benchmarks/lynx-table/first-screen-selectors.mjs --reps 2 — both
    arms 0 at both scales
  • pnpm test — not run in full. The two projects this diff can affect are
    green above; the remaining failures in this container are the four
    attributed on docs(bench): measure what the L5 main-thread repayment is worth #125.

Red-green. The oracle is "addresses a ref the background asked for before
the main thread was there"
, now asserting both halves: the ref'd host addresses
its own node and drives setNativeProps, and #summary, #rows, #healthy
carry no attribute. Setting LYNX_PUBLIC_INSTANCE_ANNOUNCEMENTS to false turns
that assertion red, and takes the sibling demand test with it — which is the
right shape, since the constant is what both rest on.

A defect this surfaced. milestone-8-integration failed on the first run:
adoption rejected ensure-public-instance as an operation it cannot replay, so
a first screen that adopts and holds a ref would have faulted. That is the fix
in host-driver.ts above, and it is exactly why announcing unconditionally
needed the whole suite rather than the selector tests.

Risk / follow-ups

  • The first batch speaks unnegotiated wire, and cannot do otherwise. It
    carries commit.announces and its ensure-public-instance commands before
    any reply could have granted them — there is nothing to negotiate with before
    the first message. So a background at this version needs a main thread at this
    version; an older one rejects the first commit at validation with a message,
    rather than failing quietly. Today both threads ship from one build of one
    package, which is what makes that acceptable; if mixed-version pairing ever
    becomes supported, this needs LYNX_TRANSPORT_PROTOCOL_VERSION, and that is
    shared with the universal transport. Worth a maintainer's explicit call.
  • The saving is still per node nobody queries. A row carrying a ref, a host
    lifecycle, or a main-thread callback is announced and pays one write.
  • First-screen direct emission and first-tree adoption stay eager by
    construction, unchanged, for the identity reasons recorded at those call sites.

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

A `nodes-ref` selector is installed only where a commit announced it would query
the host. That announcement waited on the negotiated lazy-public-instance
capability, which a background does not have when it composes its first batch:
that batch is built before the main-ready reply reaches it. So the largest tree
a root ever mounts installed a selector on every element node whether or not
anything could ever query it — 4,028 writes for a 1,000-row first screen, 40,028
for 10,000, measured by the harness this commit's parent added.

Whether a batch named its hosts is a property of the background that composed
it, not of the session, and a background knows it while composing. A driver now
declares `publicInstanceAnnouncements` as a static capability, universal-core
emits `ensure-public-instance` from that rather than from a negotiated reply, and
`commit.announces` travels on every Lynx commit. Both arms of the harness now
read 0.

The negotiated capability keeps its own job. `commit.instances` — deferring a
commit's handle deltas — still comes from it, captured at compose, and the main
thread still rejects that flag from a peer that did not negotiate. What it no
longer gates is the announcement, so the main thread's rejection of an
"unnegotiated" announcement is gone: the flag is answerable without a session.

Adoption learns to accept `ensure-public-instance` while replaying a first-screen
batch. It creates and mutates nothing, and adoption stamps every adopted record
with a selector unconditionally for the identity reason recorded at the transfer
site, so the announcement is already answered by the time it would be replayed.
`milestone-8-integration` caught this: adoption rejected the operation outright.

The regression is the pre-handshake oracle in `background-root.test.ts`, now
asserting both halves — the ref'd host addresses its node, and the hosts nothing
can obtain a handle for carry no attribute. Reverting the driver's declaration
turns both halves red.

One consequence to name rather than bury: the first batch of a root now carries
`commit.announces`, and its `ensure-public-instance` commands, without having
negotiated them. It cannot be otherwise — there is nothing to negotiate with
before the first message — so a background at this version needs a main thread at
this version, and an older one rejects the first commit at validation rather than
failing quietly. Today both threads ship from one build of one package.

Refs #103, #66.

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy

Huxpro commented Aug 21, 2026

Copy link
Copy Markdown
Owner Author

pnpm test in full — 2192/2196 files, 21053/21057 tests, no new failure

The body's last Validation box says this was not run in full. It has been now, and it supersedes that line.

Test Files  4 failed | 2192 passed (2196)
     Tests  4 failed | 21053 passed (21057)
  Duration  2550.68s

All four are the container failures already attributed on #125 and #66 §2.3, each still failing for its own recorded reason rather than anything this diff touches:

file test why
octane/tests/browser/suspense-hydration/suspense-hydration.test.ts restores focused input and its selected text after a keyed DOM reorder expected [ +0, +0 ] to deeply equal [ 2, 9 ] — headless selection restore, reproduces in isolation
drei/tests/browser/upstream-e2e.browser.test.ts should match previous one container cannot fetch potsdamer_platz_1k.hdr; the page.waitForFunction timeout is downstream of that
dropzone/tests/probes/hydration.test.ts adopts root/input nodes and remains interactive without diagnostics 5000ms timeout; already filed as its own issue
rspeedy-plugin-octane/tests/native-demo.test.ts escalates cleanup for a detached descendant after its leader exits pre-existing here per #66 §2.3 — macOS Lynx Explorer path

Two things worth recording beyond the pass count.

One failure from the previous run is gone, and that is informative rather than lucky. #130's run reported five failing files; the fifth was octane-events-browser native-change, 12 page.waitForFunction timeouts, which passed 12/12 in isolation at the time. This run started on an idle host and native-change passed inside the full run. That is the load-induced reading confirmed, so it should not be carried forward as a standing container failure — the four above should.

Provenance of the run. It executed against this PR's head with two additional working-tree files, benchmarks/lynx-table/prototype/run-fcp.mjs and benchmarks/lynx-table/web/driver-client.mjs, which were committed afterwards as #133. Neither is in any Vitest project — vitest.config.js names no benchmarks path — so no test imports them and the run stands as evidence for this diff and for #133 alike. Recording it because the tree was not byte-identical to the pushed commit, not because it changes the result.


Generated by Claude Code

Huxpro commented Aug 21, 2026

Copy link
Copy Markdown
Owner Author

Correction and measurement: this fix does not reach a plugin-default first screen, and does not move first paint

Measured on #133, recorded there in full and in benchmarks/lynx-table/README.md §4 (2957245c7). Two things this PR's body gets wrong or leaves unbounded.

1. The summary table's after-render rows do not describe a plugin-default build. packages/rspeedy-plugin-octane/src/main-thread-entry.js installs the main thread with firstScreen: true unconditionally, so an app the plugin builds paints its first screen through applyLynxFirstScreenDirect and the background adopts it — the two sites this PR deliberately leaves eager by construction, neither of which reads commit.announces. At 10,000 rows in Chromium a plugin-default build reads 40,028 selector attributes with this fix and 40,028 without it, at the same FCP to within 0.2 ms. The fix is correct and does what it claims; it just does not reach the first screen of an app built the default way. It reaches every commit the background owns.

2. What it is worth in first paint, where it does apply: nothing detectable. With the background owning the first commit, 40,028 → 0 moves median view-attach FCP from 2,134.9 ms to 2,102.2 ms — ~1.5%, n=5, ranges overlapping, the eager arm's fastest sample beating every announcing sample.

That does not change my view that this should land. The case for it is the wire contract — a commit rather than a session carrying the promise, which is what closed the gallery regression and the latent #129 defect — plus the per-node work removed. The case is not first paint, and I would rather say so here than let a "40,028 → 0" headline get cited as a startup win.

Consequence for the obvious follow-up. Teaching direct emission and adoption to install selectively is the slice that would reach the production first screen. This run argues against it on first-paint grounds: removing exactly those writes on the background path bought nothing measurable. NO-GO unless a different reason appears — retained attribute memory, or native attribute-selector matching cost. Scope is Lynx for Web in headless Chromium; native __SetAttribute is unmeasured.

Body left unedited deliberately; this comment and the README are the record.


Generated by Claude Code

claude and others added 2 commits August 21, 2026 21:26
Adoption dropped every operation of the adopting batch, including
ensure-public-instance. The transfer-site selector stamp only reaches
hosts that own a physical node, and a native list row owns none until a
cell materializes it, so a row named by the first batch kept
selectorWanted=false forever and its ref addressed nothing. Adoption now
replays exactly the ensure-public-instance operations.

Also folds the always-true announces branch in the transport: the
announcement is an invariant of this background, every commit carries
it, and the constant's literal type keeps any future branch on it
visibly dead.

Co-Authored-By: Claude <[email protected]>
@Huxpro
Huxpro changed the base branch from test/lynx-first-screen-selectors to new-lynx August 21, 2026 22:18
@Huxpro
Huxpro marked this pull request as ready for review August 21, 2026 22:18
@Huxpro
Huxpro merged commit df9b393 into new-lynx Aug 21, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants