Skip to content

perf(lynx): protocol slimming — derived ack handles, merged completion, empty-commit elision ([lynx-perf 6]) - #14

Closed
Huxpro wants to merge 4 commits into
lynx/validation-dietfrom
lynx/protocol-slim
Closed

Huxpro wants to merge 4 commits into
lynx/validation-dietfrom
lynx/protocol-slim

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 9, 2026 •

Copy link
Copy Markdown
Owner

Closes #7. Stacked on #13 ([lynx-perf 5], base lynx/validation-diet), which stacks on #12 → #11 → #10 → #1.

Summary

  • Transport protocol version 2. The background now derives every acknowledgement handle delta locally from the batch it sent — creates/recreates/destroys from its own command transitions, generations by main's exact staged-bump rules, root-connectivity and list-ancestry from a topology mirror — so a production acknowledgement carries only {identity, adoption?, complete?} and no handle payload at all. Development acknowledgements still carry main's full payload, demoted to a cross-check that must match the derivation delta-for-delta (any divergence fail-stops the root).
  • complete merges into the acknowledgement (complete: true) whenever main has no post-acknowledgement work (no adoption round trip, no queued host attachments), collapsing the common per-interaction tail from three messages to two.
  • Empty-commit elision: a prepared transaction that emits zero commands settles on the background without crossing the wire, once a first batch has been accepted. The version still advances; a two-watermark model (accepted = the root's version line, mainAccepted = the newest batch main actually applied) keeps main-originated events, attachments, faults, calls, and dispose validated against what main knows, with events re-stamped to the root's accepted version on delivery.

Why

Changes

  • packages/octane/src/universal-core.ts, packages/lynx/src/core/protocol.ts: UNIVERSAL_TRANSPORT_PROTOCOL_VERSION / LYNX_TRANSPORT_PROTOCOL_VERSION 1 → 2 (both slices still assert agreement). LynxTransportAcknowledgement.handles becomes optional (development cross-check), and the type gains complete?: true; validation accepts a bare ack, requires complete === true when present, and rejects merging completion into an adopting acknowledgement (repaired may merge; adopted still needs its round trip).
  • packages/lynx/src/core/client-driver.ts: prepareLynxHandleDeltas derives instead of installing. It mirrors main's staged generation bumps per create/recreate command (a destroy never clears the counter; entries netted away in-batch still commit — pinned by the batch-final-state test), synthesizes pure-identity snapshots ({$$kind, renderer, root, id, type, generation, selector}, exactly main's handle shape), maintains a topology mirror (parent/children/type) to derive root-connectivity attached and listDescendant, seeds new/recreated native-list cells as detached (cell materialization stays owned by the host-attachment channel), and replays main's exact list-ancestry flip walk. The development comparator tolerates attached divergence only for native-list descendants (cell-materialization timing).
  • packages/lynx/src/main-thread.ts: the acknowledgement builds the handle payload only in development on a non-faulted apply; the per-update republish loop is deleted (an update preserves identity, generation, and snapshot; its attachment bit is owned by the host-attachment channel); mergeComplete short-circuits the post-ack tail to attachment-drain → native-event drain → open background calls.
  • packages/lynx/src/core/transport.ts: two watermarks (accepted vs mainAccepted); a zero-command batch (after the first accepted batch — the first always crosses so the root activates main and the dispose handshake stays valid) settles locally inside the pace-gate dispatch through the normal entry lifecycle (finalize worklets, core acknowledge, main-call publication stamped with main's identity, synthetic completion); message.complete === true settles the commit without a separate complete message.
  • Engine-event watermark fix (5851cfc0, found by the real-browser harness): the engine tap path (dispatchNativeEventBatchNow) synthesized its event envelope with the root's accepted version, but handleEvent validates main-originated events against mainAccepted. Once an elided batch put the watermarks apart, every subsequent engine-delivered tap was dropped as stale — in the web bench the select storm froze after the update storm's elided fold tail. The envelope now carries mainAccepted (the watermark handleEvent validates) and is restamped up to accepted on delivery as before. Regression test drives the engine's own publishEvent path: a no-op state update settles locally, then the next tap must still run its handler (red-checked: fails on the unfixed line).
  • Tests: protocol/background-root/main-thread-events/commit-pacing updated to the two-message tail and derived handles; the scripted-main harness now sends production-shape bare acks; the portal-target test builds real list-cell topology instead of scripted flags; new envelope cases pin complete validation; the paced-storm test pins that the empty tail never crosses; native-event-delivery gains the after-elision tap test above.
  • benchmarks/baselines/ratios.json: update_storm_paced_commits_1k tightened 1.0× → 0.1× — the 47 empty fold-tail envelopes no longer cross (50 → 3 commits), and the old note had already named elision as the expected follow-up.
  • benchmarks/lynx-table/web/run-web.mjs: env-gated LYNX_BENCH_DEBUG console/pageerror capture (DNFs previously reported nothing; this flag is how the tap-drop regression was traced).
  • Docs: universal-renderer-architecture.md identity sketch protocol: 1 → 2. Changeset: @octanejs/lynx + octane patch.

Measured

Deterministic rig (benchmarks/lynx-table, same instrument as every cell in this stack):

  • Value-identical re-renders cross 0 bytes: paced 50-tick storm now crosses 3 commits instead of 50 — the 47 empty fold-tail envelopes (~100 B each plus a two-message reply each) are elided. Guard tightened to pin it. All other deterministic counters byte-identical (create/update/select/swap/storm commands and bytes unchanged; 174 commits / 304,416 commands / ~9.35 MB @10k whole-run).
  • Messages per interaction 3 → 2: pinned deterministically in main-thread-events/background-root (ack arrives with complete: true; no separate completion) for every non-adopting, no-attachment commit.

In-process stage timers (whole-run @10k, NODE_ENV=production build, 3 interleaved reps, medians) — reported for honesty, not as a win:

whole-run @10k before (#13 head) after change
ackMs 2,119 2,293 wash (within rep spread)
dispatchMs 4,648 4,878 wash
prepareMs 1,725 1,736 unchanged
applyMs 689 762 wash
commits / paced / commands 174 / 87 / 304,416 174 / 87 / 304,416 byte-identical

Lynx-for-Web Chromium harness (real postMessage structured clone; medians of n=3, same host, baseline = #13 head dcb334af built and run from a clean worktree; octane columns baseline → after):

op (median ms) octane @1k octane @10k vue-vdom @1k (after run) vue-vdom @10k
create 336 → 357 2,569 → 2,579 164 1,315
update10th 42 → 41 260 → 276 29 116
select 30 → 29 134 → 134 29 72
updateStorm 120 → 131 916 → 891 137 1,373
selectStorm 251 → 248 3,324 → 3,147 50 594

Every baseline→after delta is within rep spread (±6–±227 depending on cell): the real-thread-boundary wall clock is a wash too. The single-select ack payload was already small (~237 B in the deterministic rig), so removing it never had 10 ms of structured-clone to reclaim on this host. Select @1k sits at parity with vue-vdom (0.98×); updateStorm stays ahead (0.65× @10k). selectStorm's ~5× is commit pacing's one-commit-per-frame throttle on a 30-tick storm — present identically in the baseline, untouched by this PR.

Acceptance vs issue #7:

  • messages 3 → 2 common case: met (deterministic pin).
  • value-identical re-render crosses 0 bytes: met (elision + tightened guard).
  • ackHandles stage → ~0: the payload build is compiled out of production main (LYNX_DEVELOPMENT-folded), so its cost is structurally 0 on main; the rig's ackMs timer also charges the in-process background acceptance work and stays flat — reported as a wash above.
  • select tail −10 ms: not demonstrated — select wall-clock is 30 → 29 ms @1k and 134 → 134 ms @10k, within an n=3 spread that could not resolve a 10 ms delta anyway. The tail was never 10 ms of payload on this host; the realized wins are the message count and the bytes, not select latency.
  • ref/attachment/worklet suites green: met (full lynx project, 27 files / 301 tests, including the new engine-tap regression).
  • main-thread.ts line count and bundle bytes down: modest — main-thread.ts −14/+34 lines (the cross-check build is retained for development by design; production builds fold it out, taking acknowledgementHandles, publicHandleUpsert, and the getLynxHostPublicState ack-time walks with it).

The web harness also caught a real interaction-freeze regression in the first cut of this PR (octane all-DNF; see the engine-event watermark fix above) that neither the in-process rig (fake synchronous main, no engine tap path) nor the two-realm unit suites could reproduce — it is now fixed and pinned by a unit test on the engine's own delivery path.

Validation

  • pnpm format:check (scoped format:files across every changed file)
  • pnpm typecheck
  • pnpm test — full root run on this head: 1,556/1,576 files, 16,917 tests passed; 19 failing files are byte-identical to the perf(lynx): validation diet — dev-deep, prod-fast commit validation ([lynx-perf 5]) #13 baseline's pre-existing environmental set (Playwright-dependent browser suites, macOS-only rspeedy demo, website SSR e2e), plus one streamdown type-exports flake that passes in isolation
  • targeted tests: packages/lynx/tests — 27 files / 301 tests green (two-realm rig, validation on)
  • node benchmarks/bench.mjs --only lynx-table --ratios → PASS (including the tightened paced-commit guard) — rerun on the final head
  • Lynx-for-Web harness end-to-end: octane completes all ops at 1k and 10k with zero DNFs (3 reps), baseline and after
  • red-checked, each restored after going red: elision disabled → paced-storm tail test fails; merged completion disabled → 5 tests fail across background-root + main-thread-events; per-command generation staging reverted to per-transition → batch-final-state test fails (netted create+destroy and double-recreate generations); attached derivation broken → 11 tests fail, including the development cross-check catching it through real-main suites; comparator's unchanged-handle check removed → terminal-close test fails; engine-event watermark fix reverted → after-elision tap test fails

Risk / follow-ups

  • The production ack path now trusts the derivation alone. The development cross-check runs main's full payload against it on every acknowledgement in every dev/test run (the entire lynx suite exercises it), which is where a derivation/main divergence would surface first.
  • The two-watermark model creates a new bug class: anything locally synthesized on the background but validated against main's watermark must stamp mainAccepted, not accepted. The engine-event path was the one missed spot (fixed here); queued main calls and dispose already stamped mainAccepted, and the remaining accepted stamps are root-facing only.
  • The separate-complete path still exists for adopting acknowledgements and commits with queued host attachments; the completion-delivery-failure branch for that narrower path no longer has a dedicated test (the old one was repurposed to ack-delivery failure, the live common path) — residual, noted rather than hidden.
  • The elision intentionally skips the first batch even when empty, so an all-empty root still activates main and can dispose; pinned by background-root tests.
  • snapshot on public handles is now pure identity in all builds (it always was on main's real handles; only hand-scripted test mains ever attached props there).

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code

https://claude.ai/code/session_013br9KPN1riTSP683xEvUuU


Generated by Claude Code

Huxpro and others added 2 commits August 9, 2026 08:55
…mpletion, and empty-commit elision

Protocol version 2: the background derives acknowledgement handle deltas
locally (production acks carry no handle payload; development acks carry a
cross-check payload that must match the derivation), main merges completion
into the acknowledgement when it has no post-ack work, and a value-identical
re-render settles on the background without crossing the wire once a first
batch has been accepted.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013br9KPN1riTSP683xEvUuU
Huxpro and others added 2 commits August 9, 2026 10:50
…he root's

Protocol 2's empty-commit elision advances the root's accepted version
without main ever seeing those batches. The engine tap path synthesized
its event envelope with that root watermark, so handleEvent's
main-origin staleness check rejected every tap that arrived while the
two watermarks diverged — freezing all interaction after an idle
(value-identical) re-render. Real-web repro: the bench app's select
storm never delivered its first tap after the update storm's elided
fold tail.

Stamp the synthesized envelope with mainAccepted — the watermark
handleEvent validates — and let it restamp the delivery up to the
root's accepted version as before. Regression test drives the engine's
own publishEvent path: a no-op state update settles locally, then the
next tap must still run its handler.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013br9KPN1riTSP683xEvUuU
…rness

Gated page console/pageerror passthrough plus mount and rep-error
markers. DNFs previously reported nothing; this flag is how the
select-storm event-drop regression was traced.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013br9KPN1riTSP683xEvUuU
@Huxpro

Huxpro commented Aug 11, 2026

Copy link
Copy Markdown
Owner Author

Conclusion: close as superseded. Compact ACK and incremental template runs from octanejs/octane PRs 693 and 700 replace derived command handles; any remaining pacing question belongs in Huxpro/octane issue 45.

@Huxpro Huxpro closed this Aug 11, 2026
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.

1 participant