Skip to content

perf: bring Lynx renderer to ReactLynx parity - #693

Merged
trueadm merged 1 commit into
octanejs:mainfrom
openai-oss-forks:fix/lynx-renderer-performance
Aug 10, 2026
Merged

trueadm merged 1 commit into
octanejs:mainfrom
openai-oss-forks:fix/lynx-renderer-performance

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Make large, production-compiled Octane Lynx mounts and first interactions faster than the equivalent real ReactLynx Snapshot workload without changing visible output, native events, refs, or first-screen behavior.

The final clean-install, same-machine benchmark on the latest rebased upstream head compares 21 warmed samples against pinned @lynx-js/[email protected]:

Workload Octane median ReactLynx median Octane / ReactLynx
Empty commit 0.170 ms 0.104 ms 1.631×
Mount 1,000 rows 4.768 ms 3.837 ms 1.243×
Mount 10,000 rows 44.755 ms 47.255 ms 0.947×
First native update, 1,000 rows 0.902 ms 0.967 ms 0.932×
First native update, 10,000 rows 7.845 ms 8.673 ms 0.905×

The 10,000-row mount is 5.3% faster and its first real native-event update is 9.5% faster. Empty startup and the 1,000-row mount remain slower; both native-update workloads are faster in this run, although sub-millisecond cases have considerable scheduling/GC variance.

Why

Previously, every eligible nine-host row became nine logical host records, roughly 20 transport commands, nine acknowledged public-handle snapshots, and six eagerly installed renderer-private selectors. ReactLynx compiles the same subtree into a shared Snapshot creator with compact dynamic slots. Closing that structural gap required changes across the compiler, renderer-neutral host contract, Lynx transport, and native host driver.

Changes

  • Compile safe intrinsic keyed loops into immutable, shared host programs; elide compiler-proven redundant row owners and coalesce consecutive rows into one contiguous program run with flattened scalar values and implicit host/listener identities.
  • Execute program runs directly against the existing Element PAPI using dense, lazily materialized host/public-handle state. Install renderer-private selectors only when refs or public-instance callbacks actually need them.
  • Negotiate compact acknowledgements, template programs/runs, and lazy public instances through backwards-compatible correlated readiness probes. Preserve strict hostile-input validation, generation/attachment checks, transaction rollback, stale-event rejection, and unnegotiated/first-screen fallback.
  • Retain public behavior for keyed reconciliation, refs, native events, worklets, lists/recycling, portals, callbacks, teardown, and first-screen adoption. Optimize the first accepted state update without moving mount work into interaction.
  • Rebase onto the latest upstream main without losing its certified Three host-component/compact-leaf optimizations, linear-time topology placement, scope-aware events, or proportional Lynx commit-wire profiling.
  • Add a genuine production-compiled ReactLynx Snapshot comparator with exact benchmark-only ReactLynx/internal-Preact versions and pnpm-safe fork resolution. Gate identical reachable trees, 90,008 hosts, 20,000 events, three real native clicks, one shared program run, one compact acknowledgement, and same-run timing ratios.
  • Refresh all mandatory pnpm sync-generated parity-audit lockfile SHA-256 records and the user-app evaluation manifest; those files contain no unrelated behavioral changes.
  • Add patch changesets for octane and @octanejs/lynx.

Validation

  • pnpm format:check — repository-wide command not run; changed files were formatted and git diff --check passed.
  • pnpm typecheck — aggregate command not run; all eight directly affected source/testing/type-test configurations passed.
  • pnpm test — aggregate command not run; all relevant complete Vitest project groups passed on the rebased head: 12,469 tests, zero failures.
  • targeted tests: 11,900 Octane development/production + Three; 320 Lynx; 249 Vite/Rspack/Rsbuild/Rspeedy plugin tests.
pnpm sync

./node_modules/.bin/vitest run --project octane --project octane-prod --project three
./node_modules/.bin/vitest run --project lynx
./node_modules/.bin/vitest run --project vite-plugin --project rspack-plugin --project rsbuild-plugin --project rspeedy-plugin

./node_modules/.bin/tsgo --noEmit -p packages/octane/tsconfig.json
./node_modules/.bin/tsgo --noEmit -p packages/octane/typetests/tsconfig.json
./node_modules/.bin/tsgo --noEmit -p packages/lynx/tsconfig.json
./node_modules/.bin/tsgo --noEmit -p packages/lynx/tsconfig.testing.json
./node_modules/.bin/tsgo --noEmit -p packages/lynx/typetests/tsconfig.json
./node_modules/.bin/tsgo --noEmit -p packages/three/tsconfig.json
./node_modules/.bin/tsgo --noEmit -p packages/three/typetests/tsconfig.json
./node_modules/.bin/tsgo --noEmit -p packages/rspeedy-plugin-octane/tsconfig.typecheck.json

BENCH_JSON=/private/tmp/octane-lynx-react-parity-upstream-rebased-final.json node benchmarks/lynx-render/run.mjs 21
node benchmarks/bench.mjs --quick --ratios lynx-render
node benchmarks/bench.mjs --ratios lynx-bundle-size

The benchmark was rerun after a clean pnpm dependency installation. ReactLynx remains confined to the private benchmark importer; no Octane, Lynx, Three, plugin, or root production dependency gains React or Preact.

Risk / follow-ups

  • Bundle-size regression: the representative compressed Lynx artifact grows from approximately 107 KB to 149 KB gzip (roughly 42 KB / 39%). This is a real size-for-runtime-speed tradeoff, not noise; reducing or splitting the retained compiler/transport/host-driver machinery should be follow-up work before size-sensitive deployment.
  • The benchmark is Node-only: it does not measure native paint, layout, memory, device startup, or Android/iOS engine behavior. ReactLynx performs its real Snapshot JSON serialization, while the in-process Octane ContextProxy currently transfers objects by reference.
  • The optional protocol/host paths are substantial. Unsupported peers, mutable payloads, worklets, native lists, portals, refs, and first-screen adoption retain legacy behavior and have focused compatibility/security regressions, but real-device validation remains necessary.

Provenance

  • An agent produced this diff (agent-authored)

Note

High Risk
Touches dual-thread Lynx transport, host/client drivers, and acknowledgement/handle lifecycle on the critical render path; incorrect compact-ACK or lazy-handle behavior could break refs, events, or stale-target checks despite extensive gates.

Overview
Speeds up large Lynx mounts by compiling repeated row trees into shared host programs and applying them via new transport ops (mount-template-range, mount-template-run) with contiguous host/listener IDs, instead of one logical host and per-node ACK per row.

The Lynx stack gains capability-negotiated compact acknowledgements (compact-v1), lazy public handles and octane-ref selectors (installed on demand for refs/queries), and dense main-thread host state that materializes records only when observed. Background renderer config adds the template-program-mount capability; client and host drivers implement compact handle derivation, template program preparation, and batched PAPI application while keeping legacy paths for lists, portals, worklets, refs, and first-screen adoption.

The lynx-render benchmark now runs production-compiled Octane against pinned ReactLynx Snapshot on the same fake Element PAPI, with first-tap update timings, reachable-tree checksum parity, and structural gates (one shared program run, bounded wire commands, one compact ACK). Baseline ratio guards and changesets document the patch.

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

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Aug 10, 2026
@trueadm
trueadm marked this pull request as ready for review August 10, 2026 19:22
@trueadm
trueadm merged commit 01240e6 into octanejs:main Aug 10, 2026
53 checks passed
This was referenced Aug 11, 2026
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

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