Skip to content

perf(lynx): slim protocol traffic - #40

Closed
Huxpro wants to merge 1 commit into
perf/lynx-upstream-validationfrom
perf/lynx-upstream-protocol-v2
Closed

Huxpro wants to merge 1 commit into
perf/lynx-upstream-validationfrom
perf/lynx-upstream-protocol-v2

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 11, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Upgrade the universal/Lynx transport to protocol v2 so the background derives acknowledgement handle changes from the command batch it already owns. Production acknowledgements no longer clone the full handle payload back from main; development retains that payload as a delta-for-delta cross-check.
  • Merge the common completion tail into the acknowledgement and settle post-activation zero-command batches locally. A normal applied commit therefore receives two main-thread messages instead of three, while the paced value-identical tail crosses 3 commits instead of 50.
  • Preserve attachment, adoption, worklet, native-event, failure, and disposal semantics with a two-watermark model (accepted for the root, mainAccepted for work main has actually applied).

Why

The background sent the commands that determine handle creation, generation, parent placement, attachment seeds, and list ancestry, but protocol v1 asked main to rebuild that state and structured-clone it back. Create@10k made the redundant payload visible: the exact P4 profile sends 17,184,627 bytes from main for the acknowledgement/completion/frame tail. Protocol v2 sends a 156-byte bare acknowledgement plus frame pulse instead.

This is the independently mergeable P5 replacement for #14, refetched immediately before publication at frozen head e627ca5979ed77fbaf8ef5eafbea86c482f64cf5 over source parent dcb334afa415fda63e94c09a77a31d107dea6128. The old PR remains untouched. Its env-gated web debug capture is already superseded by P0's reusable cell-aware debug path and is deliberately not duplicated here.

Changes

  • packages/octane/src/universal-core.ts, packages/lynx/src/core/protocol.ts: protocol 1 → 2; production-shape bare acknowledgements; optional development handle cross-check; complete: true validation.
  • packages/lynx/src/core/client-driver.ts: derive handle transitions/generations/snapshots/attachment/list ancestry on background. Parent placement lives as one scalar on the existing monomorphic handle rather than a second retained per-node topology graph; child indexes are transient and only built for actual list-ancestry flips. Same-parent reorders stage no topology work.
  • packages/lynx/src/main-thread.ts: compile acknowledgement-handle construction out of production, remove unchanged-update republishing, and merge completion when adoption/attachment work does not require a separate tail.
  • packages/lynx/src/core/transport.ts: maintain accepted and mainAccepted, elide zero-command batches only after activation, preserve main-watermark stamping for engine events/calls/dispose, and settle merged completion through the existing commit lifecycle.
  • packages/lynx/src/core/profiling.ts and benchmarks/lynx-table: count every outbound wire message/byte in both realms, including acknowledgements, completion, and frame pulses; inject the same observation boundary into the exact P4 export for comparison.
  • Tighten update_storm_paced_commits_1k to 0.1x; add protocol, generation, attachment, list/portal, merged-tail, elision, pacing, and after-elision engine-tap coverage; add patch changesets for @octanejs/lynx and octane.

Stack

The fork review stack is GitHub Stack octanejs#36 and is managed with the official gh stack extension. Upstream delivery remains bottom-to-top.

Simplification

  • Kept P3's current plan-wire ownership/collision/release model while resolving the historical source, rather than restoring stale transport code.
  • Reused P0's stronger benchmark diagnostics instead of carrying perf(lynx): protocol slimming — derived ack handles, merged completion, empty-commit elision ([lynx-perf 6]) #14's one-off LYNX_BENCH_DEBUG patch.
  • Replaced the first-cut retained topology Map<number, { parent, type, children: Set }> after exact heap showed +7–8%. The final representation adds only parent to the already-required handle, builds descendants transiently for rare list-ancestry flips, skips ancestry entirely when no list/list-item is live, and treats same-parent reorder as the topology no-op it is.
  • Kept envelope, generation, attachment, adoption, engine-event, and failure checks. Only duplicate state transfer and no-op traffic are removed; there is no fallback protocol, runtime flag, or alternate commit lifecycle.
  • Added generic full-message profiling instead of a P5-specific probe. Production bundles without __OCTANE_LYNX_PROFILE__ fold every counter branch out.

Performance audit

Exact comparison:

  • parent: fd2ea96d5fe7fc4d39d0d24fe5e9aee8f196b111
  • candidate: b41944e6effd65d3d967af9233e8cf6569ed8301
  • host: 32x Intel Xeon Platinum 8336C, Linux 5.15.120.bsk.3-amd64, Node 22.22.2, Chromium 149.0.7827.55
  • control bundle SHA-256: P4 a6cd897fc81277782bbf06c27f4d82a47b4b7fdfaa74a665dff5ddeb475ac916, P5 52060a5e6b439cad2011fbb71dae8b9f45f109e4810cf3cff9099cebd7f50d5f
  • profile bundle SHA-256: P4 8a91af68a6be0d633d7abf3a5a3c50eab5e71f5504f87bd2e9cd33e1c230d7f2, P5 3437f85738ed6b25d2801578e6092185ebe0e81dc4475ddcb2d1554ccfa2d17f
  • ignored raw inputs: p5-final-control.json, p5-final-profile-forward.json, p5-final-profile-storm-reverse.json, and generated summary/report under benchmarks/lynx-table/attribution/results/; deterministic output under benchmarks/results/p5-final/

All cited captures pass quiet-host preflight and use five fresh pages/workers per target. CPU wraps create@10k; cold uses five fresh realms with one cold plus four steady samples; heap uses explicit CDP GC at 1k/10k/30k and validates clear/view destroy/page-close worker release; storms use fixed retained 1k state and the real Lynx-for-Web engine event path.

Deterministic behavior and pacing

The final ratio run passes all 25 applicable guards. Normal work is unchanged: create 1 command/row; update10th 100/1,000 commands and Row renders; select 2 commands / 237 commit bytes / 2 Row renders; swap 997 commands / 0 Row renders; update storm 50 commits and 5,000/50,000 commands; select storm 30 commits / 60 commands.

Paced 1k update storm preserves 300 commands and three frame-consuming commits over three frames, while crossing 3 commits instead of 50. Commit bytes fall 22,533 → 16,666 (-26.0%) because 47 empty fold-tail envelopes settle locally. The final P5 capture observes 9 total messages for the three real commits.

Owner signal: main-to-background acknowledgement traffic

Profile medians for create@10k:

metric P4 P5 change
wall 2,876.7ms 2,764.8ms -3.9%
BTS active 875.1ms 821.8ms -6.1%
MTS active 2,222.4ms 2,092.1ms -5.9%
background outbound 1 msg / 3,298,046 B 1 msg / 3,297,883 B command payload unchanged
main outbound 3 msgs / 17,184,627 B 2 msgs / 156 B one tail removed; payload effectively eliminated
main acknowledgement 224.7ms 0.1ms -99.96%

The old PR's in-process ackMs wash mixed main payload construction with background acceptance. The durable two-realm profile measures both directions and isolates the actual owner: main no longer builds/clones the production handle payload. The remaining two main messages are the merged acknowledgement and pacing pulse.

The same structural reduction appears on retained-state storms with exact work held constant:

operation work P4 main outbound P5 main outbound
five-commit update storm 500 changed rows / 500 commands 15 msgs / 122,935 B 10 msgs / 780 B
two-commit select storm 3 changed rows / 3 commands 6 msgs / 1,154 B 4 msgs / 312 B

The real engine tap succeeds after the update storm in every repetition, proving the mainAccepted watermark path remains live after local elision; all storm semantic/oracle samples pass.

Observer-free control, cold paths, heap, and bundle

create@10k control P4 P5 change
wall 2,899.7ms 2,793.8ms -3.7%
BTS active 823.1ms 839.8ms +2.0% (noise band)
MTS active 2,195.1ms 2,087.6ms -4.9%

The observer-free result is the guard against shifting main-thread savings onto background work: BTS has no stable adverse >5% signal. Profile BTS points the other direction (-6.1%), so no BTS speedup is claimed either.

Control cold-first medians are non-adverse across all six cells: swap 82.2 → 82.5ms (+0.4%), replace 398.3 → 371.6ms (-6.7%), create 336.8 → 324.7ms (-3.6%), clear 76.0 → 74.1ms (-2.5%), select 33.3 → 32.2ms (-3.3%), update10th 33.7 → 33.4ms (-0.9%). Exact semantics and presentation counts pass in every realm.

Explicit-GC retained medians are 14,286,564 → 14,518,084 B at 1k, 142,708,372 → 144,961,832 B at 10k, and 416,582,516 → 423,298,824 B at 30k: +1.6% at every scale, below the 5% budget. Every worker releases. The first-cut second topology graph measured +7–8%; it was not published. Control bundle size is 403,331 / 108,686 gzip → 406,362 / 109,847 gzip (+0.75% / +1.07%).

Order sensitivity

Forward profiled update-storm wall was 157.9 → 171.9ms (+8.9%), but the P5→P4 repeat was 159.7 → 171.6ms (-6.9% for the candidate). Select similarly changes direction (+/- a few ms). Since bundle hashes, commits, commands, changed rows, message counts, and final state are identical and the order reverses the wall result, storm wall is classified as frame/host noise and is not claimed as either a win or regression. The stable claim is the wire reduction above.

Validation

  • scoped format check across all 20 changed files
  • pnpm typecheck — repo-wide package, typetest, example, website, and benchmark typecheck matrix
  • all Lynx tests: 27 files / 302 tests
  • attribution/stage harness Node tests: 9/9
  • node benchmarks/bench.mjs --only lynx-table --ratios --results-dir=benchmarks/results/p5-final — 25/25 applicable guards pass on final HEAD
  • reportable exact-SHA control heap/CPU/cold and profile CPU/cold/storm captures; reverse-order storm repeat
  • pnpm sync; git diff --check; final worktree clean

Risk / follow-ups

  • Production acknowledgements trust the background derivation. Development/test still computes main's full payload and fail-stops on any delta, generation, attachment, snapshot, or list-ancestry divergence; the complete Lynx suite exercises that cross-check.
  • The two-watermark model requires main-originated or locally synthesized engine traffic to use mainAccepted. The engine-tap regression from the historical first cut is fixed and pinned after an elided update.
  • Protocol v1/v2 interop is intentionally unsupported; universal and Lynx versions advance together and reject mismatches.
  • Parent placement adds a measured +1.6% retained slope. The larger second topology graph was removed; later cumulative checkpoints should retain this heap cell.
  • FCP is deliberately unclaimed here and remains a P6/P7 cumulative checkpoint.

Provenance

@Huxpro

Huxpro commented Aug 11, 2026

Copy link
Copy Markdown
Owner Author

Conclusion: close as superseded. Compact ACK and template-run settlement from upstream PRs 693 and 700 replace this protocol-v2 branch; remaining scheduling research belongs in issue 45.

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