Skip to content

perf(lynx): make commit wire cost proportional to change size, not tree size - #662

Merged
trueadm merged 2 commits into
octanejs:mainfrom
Huxpro:lynx/wire-payload-change-size
Aug 9, 2026
Merged

trueadm merged 2 commits into
octanejs:mainfrom
Huxpro:lynx/wire-payload-change-size

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Depends on #660 (the instrument that measures this change) — review the last commit only.

Fixes the P0 that #660 pins: on a transported root every object-valued host prop is re-encoded through cloneSerializableValue per render, so the identity-based shallowPropsEqual can never certify sameness — a one-row select over 10,000 rows shipped ~30,000 commands / 2.4MB, and every fresh bindtap closure re-announced its (stable) listener. Three cuts, ~three small sites, no architecture changes:

  1. Value-semantic prop diff — exported sameUniversalHostPropValue: Object.is fast path, then depth-2 structural equality over arrays and plain records from any realm (via a universal-side hasCrossRealmPlainPrototype, the twin of packages/lynx/src/core/plain-object.ts); deeper or exotic values stay identity-compared. Used by shallowPropsEqual, so the compact-leaf, stable-leaf, and general diff sites fix together. cloneSerializableValue accepts cross-realm plain objects through the same predicate.
  2. Events re-announce only what the host can observe — a re-created equivalent handler keeps its stable listener ID and the background dispatch table always rebinds to the newest closure, so only a new listener, priority change, or owner change emits a command. Host callbacks (attach) deliberately keep closure-identity announcement: their re-run on handler replacement is an observable contract (pinned by universal-event-scope.test.ts).
  3. Compiler: identity-stable slot values — class={[…]} arrays whose elements are statically string-or-falsy lower to their clsx-composed string (all-literal arrays fold to a static plan prop); string-literal children and literal attribute values fold into the frozen plan.

The transport's backpressure coalescing ("renders scheduled while a commit awaits acknowledgement fold into one commit carrying the latest state; intermediate states never cross") is now an explicit, tested contract — it previously held only as a side effect of acknowledgement timing and becomes load-bearing for storm throughput once commits stop saturating the main thread.

Measured (deterministic, same harness as #660)

op before after floor
select@10k 30,000 cmds / 2,406,468 B 2 cmds / 225 B 2 / ≤2,048 B
update10th@10k 31,000 cmds 1,000 1,000
updateStorm@10k 50 commits / 1,550,000 cmds 50 / 50,000 50 / 50,000
selectStorm@10k 30 / 900,000 30 / 60 30 / 60
create@10k 160,000 160,000 (unchanged) —

All 12 lynx-table guards tighten from KNOWN GAP ceilings (31×–15,000×) to 1.0×–1.5× floors; baselines re-recorded. Wall clock on the measurement host: select@10k 1374→857ms, selectStorm@10k reaches parity with Vue vdom. Honest trade, disclosed: updateStorm wall clock regresses ~25–30% (the old number rode accidental backpressure coalescing — a busy main thread folded 50 ticks into ~19 commits; with 30× smaller commits every tick commits and lays out). The coalescing contract plus the storm command gates prevent silent decay; recovering that number needs deliberate frame-aligned commit throttling, which is a protocol change left as follow-up. The remaining select wall-clock gap vs Vue is background replay breadth — a separate P1, not attempted and not regressed here.

Validation

  • pnpm format:check
  • pnpm typecheck (ran tsc -p packages/octane and -p packages/lynx clean)
  • pnpm test (targeted below)
  • targeted tests: universal-transport / universal-renderer / universal-composition / universal-event-scope / universal-host-sdk / universal-host-attachments — 220 passed across the octane and octane-prod projects; new regression tests red-checked against reverted implementations (comparator reverted to Object.is → suppression test fails; event handler-identity term restored → suppression and replacement tests fail)
  • node benchmarks/bench.mjs --quick --ratios --only lynx-table → PASS at the tightened floors

Risk / follow-ups

  • A value-identical re-render still crosses an empty commit envelope (~100B, version advances); elision would shift acknowledged-version sequences — follow-up.
  • One pre-existing test adjusted: universal-transport.test.ts fetched the third occurrence of a re-announced listener command; the listener ID is now announced once, and the updated assertion (same ID must dispatch to the newest closure) is the stronger contract.
  • updateStorm wall-clock trade above.

Provenance

  • An agent produced this diff (agent-authored)

Note

High Risk
Changes universal transported-root prop diff, event wire semantics, and compiler slot lowering on the Lynx dual-thread hot path; incorrect equality or listener behavior would break updates or dispatch silently.

Overview
Transported Lynx commits no longer fan out across the whole table when only a few rows change. Prop diffing switches from reference equality to exported sameUniversalHostPropValue (depth-2 structural compare aligned with wire cloning), so unchanged class/style-shaped props stop generating spurious update commands. The compiler folds common per-row shapes—class={[…]} to clsx strings and literal children/attrs into the frozen plan—so slots stay primitive-stable across renders. Event handlers keep stable listener IDs and rebind locally without re-emitting event commands on every fresh closure; attach callbacks still follow closure identity.

A new lynx-table benchmark (Node wire gates + optional lynx-table-web Chromium timings) drives the krausest-style app through the real dual-thread path with __OCTANE_LYNX_PROFILE__ counters. CI ratio guards vs a changed-rows-model floor pin select at 2 commands / ~225 B at 10k rows (down from ~30k / ~2.4MB) and tighten storm/update guards to ~1.0×. Baselines, bench manifest entries, and changesets document the wire profiler and payload fix.

Reviewed by Cursor Bugbot for commit 12d44ea. Bugbot is set up for automated code reviews on this repo. Configure here.

Huxpro and others added 2 commits August 8, 2026 22:36
…rows floor

A point update's commit currently ships the whole tree: selecting one row in
the 10,000-row cross-framework table serializes ~30,000 commands / 2.4MB —
identical in size to a commit where every tenth row actually changed —
because every row's re-encoded class array and both bindtap closures cross
the wire on every commit. This adds the instrument that makes that cost a
tracked, gateable number before any fix lands:

- @octanejs/lynx gains a permanent __OCTANE_LYNX_PROFILE__-gated wire
  profiler (globalThis.__OCTANE_LYNX_PROF): per-thread commits, commands,
  serialized bytes, and pipeline-stage milliseconds. Compiled away when the
  define is absent.
- benchmarks/lynx-table drives the krausest-style table app (mirrored
  operation-for-operation from the Vue Lynx unified benchmark matrix)
  through the real background root, transport, main-thread receiver, and
  host driver via real tap tokens, and reports deterministic per-operation
  command counts and commit bytes against the changed-rows semantic floor.
- benchmarks/lynx-table/web is the Lynx-for-Web wall-clock harness: the
  same app for Octane and vendored ReactLynx / Vue Lynx vdom / Vue Lynx
  vapor reference bundles under one byte-identical Chromium page driver.
- ratios.json gains 12 lynx-table guards pinned at today's measured
  waterline (select = 1500x the floor, update10th = 31x, storms likewise),
  each marked KNOWN GAP with the instruction that fixes must tighten them.
  CI now fails on any further regression and visibly tracks the gap itself.

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

On a transported root every object-valued host prop is re-encoded through
the wire clone per render, so the identity-based prop diff could never
certify sameness: a one-row select over 10,000 rows shipped ~30,000
commands / 2.4MB. Three cuts:

- Value-semantic prop diff: exported sameUniversalHostPropValue (Object.is
  fast path, depth-2 structural equality over arrays and plain records from
  any realm via a universal-side hasCrossRealmPlainPrototype, the twin of
  packages/lynx/src/core/plain-object.ts). Used by shallowPropsEqual, and
  cloneSerializableValue accepts cross-realm plain objects through the same
  predicate.
- Events re-announce only what the host can observe: a re-created
  equivalent handler keeps its stable listener ID and the background
  dispatch table always rebinds to the newest closure, so only a new
  listener, priority change, or owner change emits a command. Host
  callbacks (attach) keep closure-identity announcement — their re-run on
  handler replacement is an observable contract.
- Compiler lowers statically string-or-falsy class arrays to their
  clsx-composed string (all-literal arrays fold to a static plan prop) and
  folds string-literal children and literal attribute values into the
  frozen plan, so hot per-row slot values are primitives.

The transport's backpressure coalescing (renders scheduled while a commit
awaits acknowledgement fold into one commit carrying the latest state) is
now an explicit, tested contract.

select@10k: 30,000 cmds / 2,406,468 B -> 2 cmds / 225 B. All 12 lynx-table
ratio guards tighten from KNOWN GAP ceilings (31x-15,000x) to 1.0x-1.5x
floors; baselines re-recorded.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SW6xKsEpmsN7rFu4K9mFM9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants