Skip to content

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

Merged
trueadm merged 2 commits into
mainfrom
perf/universal-optional-host-paths
Oct 3, 2026
Merged

trueadm merged 2 commits into
mainfrom
perf/universal-optional-host-paths

Conversation

@trueadm

@trueadm trueadm commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The weekly Bench's three-bundle-size guards breach React Three Fiber: octane-min is 1.059× and octane-full 1.042×. This PR removes Lynx-only and opt-in code from every Three bundle and ratchets both guards to the new measured ratio.

Where the bytes went. I rebuilt the #677 entry (fc1c146, when the guard passed by 4.5 KB) with today's toolchain and attributed by module and declaration.

Changes

  • Host bindings install on first use. universalHostBinding() sets a module-level support slot. That slot holds the subscription, flush, and binding-only transaction code: the former dropHostBindings … flushHostBindingUpdates methods plus UniversalBoundHostTransaction.
    • A root keeps one lazily created binding state instead of seven eagerly allocated fields.
    • Commits skip the per-host binding loops when no binding can exist.
    • Behavior is unchanged.
  • Template programs are a driver opt-in. UniversalHostDriver.templates takes the new universalHostTemplates export.
    • The templateProgramMount, templateProgramRuns, and collapsedTemplateMount capabilities take effect only with it. Without it, those trees mount and update through ordinary host commands.
    • Behind the support: program compilation and preparation, collapsed-template materialization and expansion, and tryCreateCompactTemplateUpdateTransaction.
    • The Lynx background driver passes the support. The main-thread host driver never creates a universal root, so it doesn't import it.
  • UniversalRootImpl (not exported) drops private on the members these module-level supports read.
  • Guards: octane-min 1.0 → 1.034, octane-full 1.0 → 1.024. Notes record the cause; the target remains 1.0.

Evidence

node benchmarks/three/run-size.mjs, same machine, every bundle scene-checked in Chromium:

Bundle (gzip) main this PR R3F ratio
minimal 199,019 193,811 (−5,208) 187,994 1.059 → 1.031
full catalogue 260,746 255,569 (−5,177) 250,292 1.042 → 1.021

Universal-core in the Three bundle drops from 177.9 KB to 158.1 KB minified.

Runtime A/B, same worktree, interleaved, main core vs this core: update_1k 0.988×, mount_1k 1.008×, reorder_1k 0.973× (noise).

Validation

  • pnpm format:files:check, pnpm sync clean
  • pnpm typecheck:files on the changed sources
  • pnpm test (not run in full locally, to keep machine load down; CI runs it)
  • targeted:
    • octane project: universal-host-sdk, universal-renderer, universal-host-bindings, universal-host-binding-retention, universal-effect-retention, and universal-native (all pass).
    • The full lynx project: 29 files, 404 tests. Removing templates from the Lynx client driver fails a Lynx test, so the opt-in is covered.
    • The new test "mounts program-capable keyed rows through ordinary host commands without template support" fails when the root ignores the missing support (it emits mount-template-run).
    • The universal-template-events and universal-prop-shapes benchmarks pass their semantic checks.

Risk / follow-ups

  • Driver ABI (beta): a third-party driver that declares the three template-program capabilities must now also pass templates: universalHostTemplates. Without it, those trees fall back to ordinary commands. Output is correct but unoptimized. Documented in the changeset and docs/universal-renderer-architecture.md.
  • Still in every universal bundle:
    • the async transport methods: about 0.9 KB gzip. Moving them changes the transport option contract.
    • the template pieces inline in createPreparedTransaction.
    • general universal-core growth from React-parity features.
  • Getting back to 1.0 needs that broader diet. The weekly triage waivers for these two guards (in the uncommitted bench-gating work) can be dropped once this lands.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Touches universal root commit, transaction, and driver contract (new required opt-in for template-program optimization); behavior is preserved via fallbacks but misconfigured drivers lose compact template paths.

Overview
Universal renderers no longer always pay for experimental host bindings or template-program machinery. The first universalHostBinding() call installs subscription, flush, and binding-only transaction support; roots that never create bindings skip that code path while behavior stays the same.

Template programs are opt-in per driver via a new templates: universalHostTemplates field on UniversalHostDriver. templateProgramMount, templateProgramRuns, and collapsedTemplateMount only activate when that export is supplied; otherwise keyed/program-capable trees mount and update through ordinary host commands. The Lynx background driver opts in; Three does not, shrinking typical production bundles by ~5.2 KB gzip.

Benchmark ratchets for three-bundle-size move from 1.0× to the measured R3F ratios (minimal ~1.031×, full ~1.021×), with docs/changeset notes that third-party drivers declaring template capabilities must now pass universalHostTemplates or accept the unoptimized fallback.

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

… 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]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Oct 3, 2026
@trueadm
trueadm marked this pull request as ready for review October 3, 2026 09:24
trueadm added a commit that referenced this pull request Oct 3, 2026
three-renderer frame_1k_subscribers and the two three-bundle-size ratios have
owner PRs (#1651, #1652) that re-note and ratchet those entries, so this branch
drops their waivers instead of editing the same entries.

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

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No size increases and no timing regressions outside noise.

Compares dc3e18023 with 7353cec6f on the same runner. Timing verdicts require a change beyond the combined margin of error (at least 5%) and one 0.1ms timer tick, with the fastest sample also moving beyond that margin. Workflow run

js-framework: 1k/10k row operations (ms, lower is better)

All 20 timed operations (20 within noise)
target operation base head Δ noise
octane-tsrx run 4.17 4.14 −0.7% ±14% ⚪ within noise
octane-tsrx replace 8.21 8.73 +6.3% ±15% ⚪ within noise
octane-tsrx add 3.82 3.86 +1.0% ±15% ⚪ within noise
octane-tsrx update 0.45 0.45 +0.0% ±55% ⚪ within noise
octane-tsrx select 0.16 0.18 +12.5% ±99% ⚪ within noise
octane-tsrx swap 0.39 0.44 +12.8% ±34% ⚪ within noise
octane-tsrx remove 0.45 0.48 +6.7% ±41% ⚪ within noise
octane-tsrx runlots 33.76 33.45 −0.9% ±12% ⚪ within noise
octane-tsrx select_lots 0.24 0.23 −4.2% ±52% ⚪ within noise
octane-tsrx clear 46.78 47.95 +2.5% ±6% ⚪ within noise
octane-jsx run 4.10 4.26 +3.9% ±13% ⚪ within noise
octane-jsx replace 7.68 7.93 +3.3% ±16% ⚪ within noise
octane-jsx add 3.58 3.79 +5.9% ±16% ⚪ within noise
octane-jsx update 0.66 0.63 −4.5% ±41% ⚪ within noise
octane-jsx select 0.44 0.49 +11.4% ±30% ⚪ within noise
octane-jsx swap 0.72 0.79 +9.7% ±28% ⚪ within noise
octane-jsx remove 0.62 0.75 +21.0% ±27% ⚪ within noise
octane-jsx runlots 30.96 31.95 +3.2% ±8% ⚪ within noise
octane-jsx select_lots 2.93 3.02 +3.1% ±41% ⚪ within noise
octane-jsx clear 49.17 48.66 −1.0% ±5% ⚪ within noise

Application bundle size (bytes)

No changes across 45 measured values.

Public-import reachability bundles (bytes)

No changes across 105 measured values.

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]>
trueadm added a commit that referenced this pull request Oct 3, 2026
…nd re-judge them (#1646)

* ci(bench): triage the weekly ratio-guard breaches so new ones show

The weekly Bench job (`bench.mjs --quick --ratios`) was red with 81 ratio
breaches, 4 suites that wrote no numbers and 4 harness gate failures, so a new
breach was invisible. Every item is now a fix or a rebaseline.

- Harness drift, fixed. Each harness had stopped producing numbers when runtime
  source it anchors on changed:
  - ssr-final-replay: a second suspended loop since 2026-09-29.
  - root-transactions/contracts: staged-DOM text and attribute journaling since
    2026-09-15.
  - signal-dom-bindings: a second native style Block allocation site since
    2026-09-23.
  - codegen-size: the server runtime's lazy streamed-signals chunk since
    2026-09-16.
  - recursive-context: counted a pure-call annotation and trailing newlines as
    output growth.
- Rebaselined, with numbers in each note: five cross-framework bundle-size
  ratios and the workerd script-size ratio. The absolute app and server-render
  budgets are now the ratchet. Lynx's no-worklet byte caps from 2026-08-17 are
  reset to measured + 32, with the background program pinned exactly.
- Fix pending, with dated waivers that expire 2026-10-24, each with an owner
  task:
  - three exact counters the revived harnesses exposed (one extra closure per
    ssrTry, 128 live text reads per 128 unchanged compiled updates, compiled
    output at 1.295x its source);
  - Lynx create ratios and the re-entrant transport gate;
  - superlinear hydrate boundary preparation;
  - Octane Three versus R3F size and frame dispatch;
  - two timing regressions near the timer floor;
  - ten quick-mode timing guards whose samples are noise-bound;
  - the scoped descriptor shape change.
- bench.mjs supports a guard `waiver` ({ reason, expires }). A waived breach
  prints and does not fail, and fails again once the date passes.
  HARNESS_FAILURE_ALLOWLIST now also covers a suite whose harness writes no
  numbers.

The budget breaches (57) clear when the budget reset lands.

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

* fix(benchmarks): pair and lengthen the timing samples behind waived ratio guards

Twelve timing guards breached in weekly quick runs without a verdict. Their
samples sat near Chromium's 100 µs clock or under two-sample noise, and each
target ran its whole block minutes after the other side of its guard.

- benchmarks/lib/paired.mjs: rotating per-round visit order and a ~20 ms
  sample calibration shared by the harnesses below.
- js-framework-reorder, memo-wall, svg-dashboard, spa-navigation: every
  target's page stays open in one browser and each sample round visits all
  targets; short ops repeat until a sample takes about 20 ms (clicks,
  hook invocations, op batches, and summed navigation legs).
- activity caught-reveal: a sample reveals several independent hidden roots
  in one window, with the small case revealing eight times as many roots so
  both cases do equal work; the cases alternate per round.
- ssr-workerd: an untimed priming spawn per target, then paired cold-spawn
  rounds; quick mode runs six rounds instead of two.
- bench.yml: a `suites` dispatch input to run selected suites.

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

* fix(benchmarks): collect garbage before every timed spa-navigation leg

The untimed return leg mounts a whole route, and its collection landed
inside the next timed teardown: nav_teardown samples ran at 17-45% rme.

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

* fix(benchmarks): re-judge the twelve waived timing guards with paired samples

Two quick CI runs of the paired, ~20 ms harness and same-runner A/B runs
against the commits that set each guard decided every waiver:

- Passing, waiver removed: activity reports, ssr-workerd
  cold_spawn_to_first_byte, svg-dashboard pan_zoom, memo-wall
  parent_rerender_equal_A and octane-jsx mount, spa-navigation
  nav_teardown and nav_mount (no Octane change since #674 on one runner).
- Rebaselined: svg-dashboard icon_swap 1.2 -> 1.6, because #983's esbuild
  minification made React 15% faster while Octane stayed flat.
- Confirmed Octane regressions, waiver kept and pointed at the fix:
  js-framework-reorder rotateb (1.41x per click since #639), memo-wall
  one_change_B (1.5x) and ctx_through_wall_B (1.44x), and svg-dashboard
  tooltip_swarm (1.31x since #635).
- The rotateb note claimed React moves every survivor; it moves one. A new
  rotatef guard covers the LIS-vs-lastPlacedIndex differentiator (0.043x).

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

* fix(benchmarks): rebaseline spa-navigation nav_mount to its CI baseline

The 1.2 ceiling came from a local 0.94x reading. On CI runners #674 itself
measures 1.15x and head 1.09-1.16x, so the ceiling left 3% of quick-mode
headroom; 1.35 keeps a margin while still catching per-node mount growth.

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

* ci(bench): drop the three weekly waivers that now have fix PRs

The waived guards now have owner PRs: ssr-final-replay try_closures (#1644),
root-transactions equal_reads (#1643) and codegen-size gzip compiled/source
(#1645). #1645 rebaselines the same codegen-size entry, so this branch no
longer edits it.

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

* ci(bench): leave lynx-render to its owner fix

The lynx-render transport gate failure and the create_1k/create_10k ratio
breaches both trace to #885's JSON-encoded transport and now have an owner
fix. Its branch re-notes those two guards, so this branch drops their waivers
and the suite's allowlist entry instead of editing the same entries.

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

* ci(bench): keep harness failures unwaivable and leave descriptor shapes to their owner

Waiving a suite that throws before it writes numbers would hide any crash in
that suite, not only the known shape change, and skip all of its guards. The
scoped-descriptor-shapes defect has an owner fix in progress. That fix re-pins
the harness's expected keys, so narrowing the waiver here would edit the same
assertion. HARNESS_FAILURE_ALLOWLIST is empty again, and a thrown suite failure
always fails the job. Dated waivers remain only on individual ratio guards.

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

* ci(bench): leave the Three guards to their owner fixes

three-renderer frame_1k_subscribers and the two three-bundle-size ratios have
owner PRs (#1651, #1652) that re-note and ratchet those entries, so this branch
drops their waivers instead of editing the same entries.

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

* fix(benchmarks): point the four kept timing waivers at their attributed fixes

rotateb and ctx_through_wall_B clear with #1655 and #1656; one_change_B's
per-row remainder and tooltip_swarm's scoped-descriptor accessor reads each
have their own fix task.

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

* fix(benchmarks): point parent_rerender_equal_A's note at its per-commit journal fix

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm merged commit 7422815 into main Oct 3, 2026
30 checks passed
@trueadm
trueadm deleted the perf/universal-optional-host-paths branch October 3, 2026 11:04
trueadm added a commit that referenced this pull request Oct 3, 2026
…1641)

* ci(bench): triage the weekly ratio-guard breaches so new ones show

The weekly Bench job (`bench.mjs --quick --ratios`) was red with 81 ratio
breaches, 4 suites that wrote no numbers and 4 harness gate failures, so a new
breach was invisible. Every item is now a fix or a rebaseline.

- Harness drift, fixed. Each harness had stopped producing numbers when runtime
  source it anchors on changed:
  - ssr-final-replay: a second suspended loop since 2026-09-29.
  - root-transactions/contracts: staged-DOM text and attribute journaling since
    2026-09-15.
  - signal-dom-bindings: a second native style Block allocation site since
    2026-09-23.
  - codegen-size: the server runtime's lazy streamed-signals chunk since
    2026-09-16.
  - recursive-context: counted a pure-call annotation and trailing newlines as
    output growth.
- Rebaselined, with numbers in each note: five cross-framework bundle-size
  ratios and the workerd script-size ratio. The absolute app and server-render
  budgets are now the ratchet. Lynx's no-worklet byte caps from 2026-08-17 are
  reset to measured + 32, with the background program pinned exactly.
- Fix pending, with dated waivers that expire 2026-10-24, each with an owner
  task:
  - three exact counters the revived harnesses exposed (one extra closure per
    ssrTry, 128 live text reads per 128 unchanged compiled updates, compiled
    output at 1.295x its source);
  - Lynx create ratios and the re-entrant transport gate;
  - superlinear hydrate boundary preparation;
  - Octane Three versus R3F size and frame dispatch;
  - two timing regressions near the timer floor;
  - ten quick-mode timing guards whose samples are noise-bound;
  - the scoped descriptor shape change.
- bench.mjs supports a guard `waiver` ({ reason, expires }). A waived breach
  prints and does not fail, and fails again once the date passes.
  HARNESS_FAILURE_ALLOWLIST now also covers a suite whose harness writes no
  numbers.

The budget breaches (57) clear when the budget reset lands.

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

* ci(bench): drop the three weekly waivers that now have fix PRs

The waived guards now have owner PRs: ssr-final-replay try_closures (#1644),
root-transactions equal_reads (#1643) and codegen-size gzip compiled/source
(#1645). #1645 rebaselines the same codegen-size entry, so this branch no
longer edits it.

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

* ci(bench): leave lynx-render to its owner fix

The lynx-render transport gate failure and the create_1k/create_10k ratio
breaches both trace to #885's JSON-encoded transport and now have an owner
fix. Its branch re-notes those two guards, so this branch drops their waivers
and the suite's allowlist entry instead of editing the same entries.

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

* ci(bench): keep harness failures unwaivable and leave descriptor shapes to their owner

Waiving a suite that throws before it writes numbers would hide any crash in
that suite, not only the known shape change, and skip all of its guards. The
scoped-descriptor-shapes defect has an owner fix in progress. That fix re-pins
the harness's expected keys, so narrowing the waiver here would edit the same
assertion. HARNESS_FAILURE_ALLOWLIST is empty again, and a thrown suite failure
always fails the job. Dated waivers remain only on individual ratio guards.

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

* ci(bench): leave the Three guards to their owner fixes

three-renderer frame_1k_subscribers and the two three-bundle-size ratios have
owner PRs (#1651, #1652) that re-note and ratchet those entries, so this branch
drops their waivers instead of editing the same entries.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Oct 4, 2026
… (#1710)

#1700 freezes a fresh root's decoded program runs so a first mount takes
the dense host record store again. That costs the main thread 141 raw
bytes: preview main gzip 83,657 -> 83,742 and IFR 89,331 -> 89,404,
both over their measured + 32 caps. The weekly-only lynx-bundle-size
gate never ran on that pull request.

Raise both caps to the new measurement + 32. Re-pin the background
program at 288,390: it shrank after the 2026-10-03 reset (#1652, #1662),
and its exact pin is the next gate in the same block. Budget values and
their comment only.

Refs #1055

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.

1 participant