Skip to content

Roadmap: replace the universal-renderer target for Lynx with a Lynx-specialized compiler and renderer #58

Open

Description

@Huxpro

Roadmap: a Lynx-specialized compiler + renderer, off the universal ABI

Decision being proposed

Stop targeting Lynx through octane/universal. Introduce a dedicated target: 'lynx' compiler backend and a Lynx-owned runtime core, so that **/*.lynx.tsrx compiles to optimal Lynx code: direct Element PAPI emission on the main thread, a slot-addressed delta protocol between threads, and no generic host-command vocabulary, plan interpreter, or per-prop capability dispatch anywhere on the hot path.

The public API and component model stay exactly Octane: same hooks (compiler-assigned slots, inferred deps, [state, update, getState]), same directives (@if/@for/@switch/@try), same Suspense/Activity/portals/context/refs semantics, same root.render(App) surface, same docs/differences-from-react.md contract. What changes is everything below the compiler front-end.

Design references: ReactLynx's Snapshot model (straight-line snapshot creators + compact patch opcodes) and the Vue Lynx Vapor lane (compile-time static/dynamic split, no VDOM/plan at runtime). We have both vendored as measurement references under benchmarks/lynx-table/reference/ already.

Why: the universal ABI owns the dominant costs

The wire is not the problem anymore. benchmarks/lynx-table stage attribution (Chromium, n=5, AB/BA) shows clone/transfer at 0.2–0.9% of wall time and ACK at ~0%, and the wire ratio gates already pin command/byte counts at the changed-rows floor. What dominates is everything the universal indirection makes us do around the wire:

create rows wall PAPI create other host apply BTS replay clone/transfer
1,000 148.3 ms 41.8% 27.6% 18.1% 0.4%
10,000 1,201.5 ms 48.1% 28.4% 12.2% 0.3%
30,000 3,498.6 ms 51.2% 28.4% 9.8% 0.3%

The stage report's own verdict: wire/value encoding is a NO-GO as an optimization target; the observed owner is PAPI/host materialization (69.5–79.6% of create), and it remains linear. That materialization cost is structural to the generic path:

  1. Per-prop virtual dispatch, every render. classifyLifecycle / classifyLocalCallback / classifyEvent / encodeHostProp per prop per host (packages/octane/src/universal-core.ts:3740-3800, :7505), plus delete props[name] hidden-class churn and lazily allocated per-host Maps.
  2. Deep-clone → identity loss → structural re-diff. With a transport present, every object-valued prop goes through cloneSerializableValue (recursive clone + freeze per level). The code's own comment (universal-core.ts:4155-4162): an identity-only diff would emit "wire cost proportional to tree size instead of change size" — so we pay a bounded structural deep-compare instead. The clone causes the diff.
  3. Triple prop work per update. Core diffs prev/next; the Lynx driver's updates.classify runs the whole planLynxHostPropPatch and discards everything but a boolean (packages/lynx/src/core/client-driver.ts:1471-1477); the update command then ships the full props bag, and the main thread runs planLynxHostPropPatch again (packages/lynx/src/core/host-props.ts:569) to derive PAPI writes.
  4. Unconditional main-thread revalidation in production. validateLynxBackgroundOutboundMessage recursively validates every command and every prop value of every inbound batch (packages/lynx/src/main-thread.ts:2458 → core/protocol.ts:1315) — a full structural walk we only need because the wire vocabulary is generic and untyped.
  5. First screen is an interpreter. IFR walks generic universal plan nodes at runtime (packages/lynx/src/main-renderer.ts:682-810); the FCP stage contract literally has a plan_interpretation stage. Vapor/ReactLynx emit the element-creation code directly.
  6. Per-node handle/identity machinery. One LynxHandleEntry per accepted host with ack state, dual snapshots, lazy facades, generation tracking (packages/lynx/src/core/client-driver.ts:76-95) — required because logical IDs are minted at runtime by a renderer-agnostic core instead of being compile-time-stable.
  7. Bundle size: 3.11× the competition. Production inventory: 159 KB gzip total vs the 51 KB ReactLynx/Vue Lynx median. Attributed owners include the universal runtime (16.1% raw), host driver/PAPI translation (7.7%), protocol/transport/profiling (7.1%), and first-screen/adoption (6.3%) — plus a compiler-emitted program share inflated by the plan/descriptor encoding.

And the "universal" abstraction has already bent to its two real consumers: firstScreenEvents, threadFunctionsModule, the main-thread: prop namespace, main-thread-render-only, thread-functions, and 6 of 10 driver capability flags are Lynx/perf-driven additions, while compile-universal.js hard-codes three by renderer ID for its own optimizations (compile-universal.js:2041, :2098, :3055). The template-program sub-ABI (mount-template-run, compact blueprints, capability handshakes) is itself the evidence that the generic vocabulary was too slow and we have been re-specializing inside it. The ABI is documented as experimental and changeable in patch releases (docs/universal-renderer-architecture.md:3, :1447-1451), and both Lynx packages are 0.0.0 private — there is no compatibility debt blocking this.

The recent optimization arc (octanejs#693 → octanejs#696 → octanejs#700 → octanejs#706 → octanejs#707 → octanejs#716 → octanejs#717) drove the wire to the floor; octanejs#717 closed with "no evidence-backed Octane representation experiment left" within the current representation. The remaining 3× gaps (host materialization, bundle size, interpretation) are what a representation change addresses.

Design sketch

Compiler: target: 'lynx'

Reuse the shared front-end unchanged — the two-pass structure already exists: compile.js:7884 lowers JSX away and re-enters compileInternal for hook slots, dependency inference, HMR, profiling, and source maps. The Lynx backend replaces only what compileUniversal emits:

  • Static/dynamic split at compile time (the Vapor move). Each template compiles to (a) a static structure descriptor encoded once — ideally aligned with what the .lynx.bundle template/element sections can carry natively — and (b) a straight-line create function that emits dense PAPI calls (the intrinsics.view/text/rawText + append factories in core/papi.ts become the primary path, not an escape hatch), and (c) per-dynamic-slot update functions. No plan objects, no runtime node-kind dispatch.
  • Typed slot-delta wire format. Background→main patches address compile-time-stable slot IDs: [templateId, instanceId, slotIndex, value]. Because the compiler knows each slot's type (text, attribute, class list, style prop, event, child range), the main-thread applier is a table dispatch into pre-bound PAPI setters — no prop-bag diffing on either side, no generic revalidation, and validation shrinks to a cheap header/type check.
  • Dual-graph codegen from one module — keep the existing layer mechanism (rspeedy-plugin-octane/src/layers.js) and per-layer erasure rules (background callbacks/effects erased from main; the statically-named host props constraint), but the main-thread graph now emits the create functions directly instead of data for an interpreter.
  • Per-target codegen is already a supported concept: renderers.js is versioned, data-only config resolved identically across Vite/Rspack/Rsbuild/Volar; this adds a first-class target rather than a new capability pile.

Runtime: a Lynx-owned core

  • Background: a Lynx-specific reconciler core owning hook cells, context, effects phasing, Suspense/Activity, keyed @for (LIS), and the commit split — same observable semantics as today's contract, but producing slot deltas natively instead of UniversalHostCommand batches. Whether this is a fresh core or an extraction from universal-core.ts is a Phase 0 decision; the ownership/commit semantics in docs/universal-renderer-architecture.md §5–§10 and the 15K-line universal-* test surface define the behavior to preserve.
  • Main: the applier + first-screen create functions, PrimJS-safe, with no plan interpreter and no full-batch revalidation. First-tree adoption keys off compile-time template/slot identity instead of runtime-minted logical IDs and snapshot field comparison, which should collapse most of core/first-screen.ts and the per-node ack/handle machinery.
  • Keep what already works and is Lynx-shaped: thread directives and worklets ('main thread' / 'background only', runOnMainThread/runOnBackground, main-thread:ref), native list descriptors and recycling callbacks, event-token routing with embedded priority, init-data/global-props lifecycle, NodesRef handles, the testing facade, and the ContextProxy framing. These port over; they were never the problem.

What this deletes from the Lynx path

Generic command vocabulary and per-command validation, per-prop classify/encode/clone, updates.classify double diffing, plan interpretation, template-program/compact-blueprint compensation layers, the capability handshake, and most per-node handle state. Each maps to a measured cost above.

Non-goals

  • No change to the DOM path. runtime.ts stays byte-identical; the DOM byte-identity invariant continues to hold. This is the third specialized backend, not a generalization.
  • No change to the authoring model. .tsrx sources that compile today must compile identically; a shared web/native component keeps working under both targets.
  • Not deciding the universal ABI's fate here. @octanejs/three stays on it. Whether the universal target remains the generic fallback or shrinks is a separate decision once Lynx is off it (tracked as an exit question of the last phase).
  • No ReactLynx/Preact runtime dependency, same as before — Snapshot/Vapor are design references and behavioral oracles only, per UPSTREAM.md provenance rules.

Milestones

Each phase lands behind the existing benchmark gates (lynx-table stage attribution, lynx-render, lynx-list, lynx-bundle-size, wire ratio floors in benchmarks/baselines/ratios.json) with semantic checksums, and the universal-path Lynx stack remains the working default until the cutover gate.

L0 — Representation spec and cost model (1–2 wk). Write the Lynx IR spec: static structure encoding, slot table, delta opcode set, adoption identity, list integration. Decide fresh-core vs extraction for the background runtime. Prototype the create-function codegen for the lynx-table fixture only and measure papi_element_creation + plan_interpretation deltas against today's path and the vendored Vapor/ReactLynx references. Exit gate: measured evidence that direct emission beats plan interpretation on FCP stages, or a documented no-go.

L1 — Compiler backend (3–4 wk). target: 'lynx' in renderers.js (config version bump), compile-lynx.js sharing the front-end via compileInternal, dual-graph emission through the existing layer mechanism, per-layer erasure parity, source maps, HMR identity. Exit gate: the existing .lynx.tsrx corpus and compiler test suite compiles under the new target; emitted-program size ≤ the current plan encoding for the same fixtures.

L2 — Background core + delta protocol (4–6 wk). Hook/context/effect/Suspense/keyed-reconciliation core producing slot deltas; port the transport framing; typed protocol with header-level validation only. Exit gate: the behavioral surface of the current Lynx + relevant universal test suites passes on the new core (ported, not weakened); update_storm / select / swap wire gates hold at their floors by construction.

L3 — Main-thread applier + first-screen codegen (3–5 wk). Slot-table applier, direct-emit first screen (both immediate and engine render modes), adoption on compile-time identity, event token routing and buffered replay. Exit gate: plan_interpretation stage eliminated from FCP attribution; adoption mismatch diagnostics at parity; first-screen host-spread and callback-erasure rules preserved.

L4 — Lists, worklets, platform surface (3–5 wk). Native list descriptors and recycling on the new applier (including revisiting the native-lists-excluded-from-adoption divergence), worklet/thread-function port, NodesRef, init-data/global-props, portals, lazy bundles, testing facade. Exit gate: lynx-list physical-cell ratio holds; packages/lynx test suite green on the new stack.

L5 — Parity, size, and cutover (2–4 wk). Full benchmark sweep vs universal-path Octane, ReactLynx, and Vue Lynx references; production bundle inventory re-attribution. Cutover gate: create wall-clock at 10k rows materially below the current 1,201 ms with PAPI-stage dominance reduced; main-thread gzip meaningfully toward the ~51 KB median (propose ≤1.5× as the target, ratified in L0); no wire-floor regressions; then flip lynxRendererRules to the new target and mark the universal Lynx path deprecated.

L6 — Cleanup and ABI decision (1–2 wk). Remove the Lynx-only universal capabilities/compensation layers from octane/universal where three doesn't use them; update docs/universal-renderer-architecture.md and docs/lynx-native-renderer-plan.md; file the follow-up on the universal ABI's remaining scope.

Native-engine evidence (macOS Explorer first paint, tap delivery, Android/iOS) carries over as the same open gates as today — this roadmap doesn't waive them, and the L5 cutover uses the same evidence standards the current milestones demand.

Risks

Risk Mitigation
Duplicating a third hook/reconciler core triples semantic-drift surface (DOM, universal, Lynx) L0 explicitly evaluates extracting a host-neutral ownership/hook kernel from universal-core.ts; the escape clause in docs/universal-renderer-architecture.md:1417-1429 allows extraction "after evidence from two renderers" — we now have two
Slot-delta protocol can't express dynamic structure (conditional subtrees, keyed ranges) as compactly as hoped Directive blocks are compile-time-known structure; ranges get their own opcodes; L0 spec must cover @if/@for/@try before any codegen lands
Compile-time identity vs adoption/repair edge cases (mismatched main/background graphs) Same thread-DCE + deterministic-metadata discipline as Milestone 6 today, but identity is now static, which shrinks the matching problem rather than growing it
PAPI cost is partly engine-intrinsic and won't yield to representation change L0's fixture-level prototype measures exactly this before we commit; references give the achievable floor
Losing the universal path's accepted-fault/ack robustness contract Port the contract, not the encoding: version/generation framing, accepted-fault split, and teardown semantics carry into the typed protocol
0.x churn in Lynx SDK/tooling during a long migration Keep the audited pin discipline (UPSTREAM.md, audit/toolchain.json); the new backend targets the same pinned 3.9.0 surface

Open questions for L0

  1. Fresh background core vs extraction of an ownership/hook kernel shared with universal-core.ts?
  2. How much static structure can live in the .lynx.bundle template sections (encoder-side) vs main-thread create functions (code-side)?
  3. Does the slot table subsume the template-program capability entirely, or does three want the same mechanism (informing what stays in octane/universal)?
  4. Delta batching granularity: per-commit batches (today's model) vs finer-grained scheduling once a lane scheduler exists — the universal path has no lane scheduler or memo bailout today, and the new core should not inherit that gap.

Activity

  1. Huxpro commented on Aug 19, 2026

    @Huxpro
    OwnerAuthor

    Development for this roadmap now happens on the long-lived new-lynx integration branch instead of stacked PRs against main:

    Remaining tracked work: #60 (L1 directive lowering + dual-graph emission), #61 (L2 slot-delta protocol + background core), #62 (L3 remaining slices: lazy command batch, capture fast-exit).


    Generated by Claude Code

  2. added a commit that references this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions