Skip to content

perf(lynx): minimize universal keyed moves - #716

Merged
trueadm merged 2 commits into
octanejs:mainfrom
Huxpro:huxcx/perf-lynx-keyed-lis
Aug 12, 2026
Merged

trueadm merged 2 commits into
octanejs:mainfrom
Huxpro:huxcx/perf-lynx-keyed-lis

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • replace the universal keyed reconciler's greedy move planner with an O(n log n) LIS planner
  • preserve one template run for append/replace while moving only unstable survivors
  • add identity, event-scope, move-count, wire-byte, and large-list regression coverage
  • add a patch changeset

Tracks Huxpro#46.

Recalibration

This branch is based on upstream main at ffadd397, after #706 and #707 merged. The full live experiment was also run on an integration stack containing the complete #706 head followed by both #707 commits before those PRs merged.

Results

The 1,000-row far swap drops from 997 universal move commands / 47,986 bytes to 2 moves / 368 bytes, with zero row re-renders and preserved DOM identity and event routing. The same two-move invariant holds at 10k and 30k rows.

exact v2 run baseline swap candidate swap delta DNF
forward 51.465 ms 26.8 ms -48.0% 0
reverse 52.73 ms 26.2 ms -50.3% 0

Create, replace, append, and clear stayed within the accepted v1 regression envelope in both orders. The rejected reverse-placement prototype regressed append/replace by 20–32%; the submitted forward placement anchors to the next stable survivor and avoids that regression.

Latest-main rows=0 bundle deltas:

  • Web: +595 raw / +257 gzip bytes
  • Lynx: +595 raw / +251 gzip bytes

Validation

  • pnpm vitest run packages/octane/tests/universal-event-scope.test.ts packages/octane/tests/universal-host-sdk.test.ts packages/octane/tests/universal-renderer.test.ts packages/octane/tests/universal-core.test.ts — 106 passed
  • pnpm exec tsgo --noEmit -p packages/octane/tsconfig.json
  • node benchmarks/bench.mjs --only lynx-table --ratios — 24/299 applicable guards passed
  • forward and reverse exact v2 live runs — 802 records each, zero DNF
  • pnpm format:files:check ...
  • pnpm sync

Provenance

  • An agent authored this PR

Note

Medium Risk
Touches core universal keyed reconciliation and host placement, so incorrect LIS planning could break survivor identity, events, or append/replace template coalescing. Coverage and deterministic swap gates mitigate that risk.

Overview
Minimizes keyed host moves by replacing the greedy placement planner with an O(n log n) longest-increasing-subsequence plan in universal-core. Distant swaps now move only unstable survivors (e.g. 2 moves instead of ~997) while preserving identity, events, and lifecycle.

Stable survivors stay put; inserts/moves anchor to the next stable host. LIS runs only when survivors are actually reordered, so append/replace still coalesce into one mount-template-run.

Adds lynx-table swap gates for wire bytes, zero row re-renders, and handle deltas at 1k/10k, plus unit coverage for distant swaps and append/replace template runs.

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

@github-actions github-actions Bot added the perf PR: performance work label Aug 12, 2026
@trueadm
trueadm marked this pull request as ready for review August 12, 2026 09:01
@trueadm
trueadm merged commit 6b65644 into octanejs:main Aug 12, 2026
52 checks passed
trueadm added a commit that referenced this pull request Oct 3, 2026
… to renderers that use them (#1652)

* perf(octane): ship universal host bindings and template programs only to renderers that use them

Weekly Bench's three-bundle-size guards breached at 1.059x (minimal) and
1.042x (full catalogue) of React Three Fiber. Since #677, octane-min grew
15.6 KB gzip, almost all of it in universal-core.ts (131 KB -> 178 KB
minified). The largest additions were Lynx-only template paths (#693, #700,
#716, #750) and opt-in host bindings (#1044). @octanejs/three itself was flat.

- universalHostBinding() now installs the subscription, flush, and
  binding-only transaction code on its first call. The root keeps one lazy
  binding state instead of seven eager fields, and commits skip the
  per-host binding loops when no binding can exist.
- Template programs are a driver opt-in: templateProgramMount,
  templateProgramRuns, and collapsedTemplateMount take effect only with
  `templates: universalHostTemplates`. The Lynx background driver passes it.
  Program preparation, collapsed-template materialization and expansion, and
  the compact template update now sit behind that object.

octane-min 199019 -> 193811 gzip (1.031x), octane-full 260746 -> 255569
(1.021x). The guards ratchet to 1.034 and 1.024; reaching 1.0 needs a
broader universal-core diet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* chore: split the Lynx changeset from the octane changeset

The changeset check rejects a changeset that mixes the ignored private
@octanejs/lynx package with octane.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf PR: performance work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants