Skip to content

perf: keep the signal Action frame out of islands-only pages - #1678

Merged
trueadm merged 1 commit into
mainfrom
perf/islands-signal-action-placement
Oct 3, 2026
Merged

trueadm merged 1 commit into
mainfrom
perf/islands-signal-action-placement

Conversation

@trueadm

@trueadm trueadm commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Islands-only pages no longer download the signal Action frame or the transition coordinator: about 4 KB gzip that they load but never run. signal-chat's islands-only page goes from 71,763 B to 67,719 B gzip-9 (−4,044 B, −5.6%), and its e2e ceiling drops from 71 KiB to 68 KiB.

Why a design was needed. Only the renderer creates frames (nativeCandidateForAction in runtime.ts), yet signals/graph.ts registered both factories at load. Three constraints conflict:

  • bundle-boundaries.test.mjs keeps createRoot-only bundles at 0 bytes of this code, so the runtime can't import it.
  • signals-action-lifecycle.test.ts needs a frame when signals are imported after a renderer Action awaited, with no native reads; the props-handle and form-Action tests in that file pin the same case.
  • An import edge from either side always loads the code with that side, and a dynamic edge is async (esbuild without splitting also inlines it).

So no single import edge loads it only when both the renderer and the graph are present, and the code has to live on one side, chosen per build.

Design. octane's package imports now choose the side through src/signals/action-capability.ts, with action-capability-elsewhere.ts as the other side's stub:

#octane/signal-actions/graph (graph.ts) #octane/signal-actions/renderer (runtime.ts)
default registers the factories in transition-state (today's behaviour) reads that live registry
octane-islands no-op imports the factories directly

Either placement is complete: any document that loads the renderer can create a frame as soon as the graph writes, including for late-imported signals. The condition only decides which pages download the code. Under octane-islands, transition-state's registry also tree-shakes away.

@octanejs/vite-plugin adds octane-islands to the production client build when every RenderRoute uses hydrate: 'islands', the scope chosen with the maintainer. Mixed apps keep the default, so renderer pages that don't use signals never pay. Other bundlers can opt in through their resolve conditions (documented in docs/ssr.md).

Publishing. The #octane/signal-actions/* keys point at ./src. The per-file runtime build therefore rewrites them:

  • dist/ imports #octane/dist/signal-actions/*, which both manifests map to dist/ (so the condition still works for published consumers).
  • dist/node and the CJS tree import the default target relatively, since Node never sets a bundler condition.

verify-dist.mjs checks that the mappings agree and that no emitted module keeps a source-only key, so dist/ resolves the same in the repository (in-place smoke, benchmarks) and in the tarball.

Validation

  • pnpm format:check (scoped pnpm format:files on every changed file; CI runs the full gate)
  • pnpm typecheck (pnpm typecheck:files on the changed source and test files; CI runs the full gate)
  • pnpm test (not run locally; left to CI)
  • targeted tests:
    • node --test benchmarks/scoped-signals/bundle-boundaries.test.mjs: 34/34. New test: under octane-islands the engine and streamed-signal bootstraps keep 0 B of transition-action/transition-coordinator (9,256 + 5,135 B minified by default); createRoot keeps 0 B by default and carries them under the condition; and a bundled renderer Action that imports signals after awaiting stages its write (in-scope [2, 4], committed 0, then published once) under both placements. Seen failing three ways: graph registration kept under the condition (9,067 B in the engine bundle), renderer side not carrying the factories (byte assertion), and the same with the byte check removed (the write publishes early, 2 instead of 0).
    • vitest run packages/octane/tests/signals-action-lifecycle.test.ts --project octane-signals: 8/8 (default placement).
    • vitest run packages/vite-plugin-octane/tests/islands-route.test.ts: 6/6. New test: real Vite builds. The mixed app keeps the frame reachable from the signal-graph chunk and not from the runtime chunk; the all-islands app is the reverse, and its server still renders. Fails with the plugin change disabled.
    • node packages/octane/scripts/build.mjs: full publish build, verifyDist (including the new import check), in-place smokeDist of every ESM/CJS entry, published-errors.test.mjs, version check. Published dist/ bundled with and without octane-islands honours the condition exactly as source does.
    • signal-chat: pnpm build + OCTANE_EXAMPLE_PREVIEW=1 playwright test -g "islands-only JavaScript budget" passes at 67,719 B (main measured 71,763 B with the same commands). The facade chunk goes from 16,019 B to 12,013 B gzip; the frame and coordinator now sit in the runtime chunk, which islands-only pages never load.
    • node benchmarks/bundle-size/run-minimal.mjs --budgets root-static-local root-chained-jsx hooks-state prop-attributes context: raw/gzip/brotli identical to main.

Risk / follow-ups

  • Default-placement bundles that include the signal graph grow by +29 B raw (+7 to +16 B gzip with esbuild), from the installSignalActions() wrapper. No byte budget or ratio guard covers a signal-graph bundle (none of the budgeted fixtures imports octane/signals).
  • About 89 B gzip of frame-only helpers in transition-state.ts (writer tracking) still ship in the shared chunk on islands pages, because transition-state is one module shared by the graph and the runtime.
  • The forkCandidate methods in signals/requests.ts, computations.ts and engine.ts are also only reached from frames. They are class methods, and moving them to the renderer side would pull requests/computations into renderer bundles, so they need their own design; not attempted here.

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
Changes how transition Action code is split across bundles and depends on correct octane-islands resolution; wrong placement could break staging of signal writes inside renderer Actions, though tests cover both placements and late signal import.

Overview
Islands-only client builds no longer ship the signal Action frame and transition coordinator (~4 KB gzip) with the signal graph. Those modules are only needed when the renderer stages startTransition writes, so pages that load signals without the renderer were paying for dead code.

Octane now picks which bundle carries that code via package imports and the octane-islands resolve condition. By default graph.ts still registers the factories through action-capability.ts; under octane-islands the renderer imports them directly and signal bundles get a no-op stub (action-capability-elsewhere.ts). Behavior stays the same for late-loaded signals after an Action awaits.

@octanejs/vite-plugin adds octane-islands to the production client resolve conditions when every RenderRoute uses hydrate: 'islands'; mixed apps keep the default. Published dist/ rewrites internal #octane/signal-actions/* imports to #octane/dist/* so tarball and in-repo builds honor the same conditions, with verify-dist guarding drift.

Docs, bundle-boundary / Vite integration tests, and the signal-chat islands JS budget ceiling (71 → 68 KiB) reflect the win.

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

Only the renderer creates signal Action frames and the transition coordinator,
but signals/graph.ts registered them at load, so every bundle that loaded the
signal graph carried about 4 KB gzip that renderer-free pages never run. No
import edge loads code only when both the renderer and the graph are present,
so package.json now chooses the side that carries it: the graph by default
(#octane/signal-actions/graph), or the renderer under the `octane-islands`
condition (#octane/signal-actions/renderer). Both placements stage Action writes,
including for signals imported after an Action awaited.

The Vite plugin adds the condition to the production client build when every
RenderRoute is islands-only. signal-chat's islands-only page drops from 71,763 B
to 67,719 B gzip-9, and its e2e ceiling falls from 71 KiB to 68 KiB.

The published runtime imports `#octane/dist/` twins of these keys, so dist/
resolves to dist/ both in the repository and in the tarball.

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 17:53
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🟡 js-framework: 1 timed operation(s) slower beyond ±3%
  • 🔴 bundle-reachability: 3 value(s) increased within budget

Compares 4778bf374, the merge commit's first parent with 2425b7791 on the same runner. A byte value over its committed budget or any increase in a js-framework work counter fails this check. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

target operation base ms head ms head/base 95% CI
octane-tsrx clear 37.592 40.817 +5.1% +3.6% … +7.7% 🟡 slower
All 20 timed operations (19 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 2.275 2.358 +2.2% −0.0% … +8.5% ⚪ within noise
octane-tsrx replace 6.075 6.200 +4.3% ±0.0% … +9.3% ⚪ within noise
octane-tsrx add 2.317 2.283 −2.1% −4.3% … ±0.0% ⚪ within noise
octane-tsrx update 0.118 0.118 +0.3% −1.7% … +1.0% ⚪ within noise
octane-tsrx select 0.005 0.005 −0.5% −1.0% … ±0.0% ⚪ within noise
octane-tsrx swap 0.033 0.033 +0.0% −0.6% … +2.3% ⚪ within noise
octane-tsrx remove 0.016 0.016 +0.7% −1.1% … +2.8% ⚪ within noise
octane-tsrx runlots 22.750 22.592 +0.2% −2.8% … +3.3% ⚪ within noise
octane-tsrx select_lots 0.005 0.005 +2.5% +1.9% … +2.6% ⚪ within noise
octane-tsrx clear 37.592 40.817 +5.1% +3.6% … +7.7% 🟡 slower
octane-jsx run 3.167 3.133 ±0.0% −3.1% … +0.0% ⚪ within noise
octane-jsx replace 5.800 5.792 −0.0% −1.7% … +0.0% ⚪ within noise
octane-jsx add 2.992 3.017 ±0.0% −3.2% … +1.6% ⚪ within noise
octane-jsx update 0.231 0.231 ±0.0% −1.4% … +0.7% ⚪ within noise
octane-jsx select 0.114 0.115 ±0.0% −1.8% … +0.5% ⚪ within noise
octane-jsx swap 0.206 0.206 +0.3% −0.5% … +0.5% ⚪ within noise
octane-jsx remove 0.164 0.162 −0.6% −2.9% … +0.9% ⚪ within noise
octane-jsx runlots 27.117 27.267 +0.0% −1.1% … +1.9% ⚪ within noise
octane-jsx select_lots 1.335 1.371 +0.5% −0.3% … +1.1% ⚪ within noise
octane-jsx clear 42.717 42.483 +0.3% −0.6% … +2.7% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx bindings_js_gzip 240,407 240,396 −11 (−0.0%) 🟢
octane-tsrx bindings_js_brotli 204,738 204,641 −97 (−0.0%) 🟢
octane-tsrx bindings_app_gzip 121,728 121,717 −11 (−0.0%) 🟢
octane-tsrx bindings_app_brotli 101,836 101,739 −97 (−0.1%) 🟢

50 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
binding-base-ui-esbuild gzip 68,170 68,150 −20 (−0.0%) 🟢
binding-base-ui-esbuild brotli 59,089 59,105 +16 (+0.0%) 🔴
binding-radix-esbuild gzip 68,744 68,748 +4 (+0.0%) 🔴
binding-radix-esbuild brotli 59,653 59,644 −9 (−0.0%) 🟢
binding-apollo-client-esbuild gzip 114,493 114,490 −3 (−0.0%) 🟢
binding-apollo-client-esbuild brotli 99,731 99,812 +81 (+0.1%) 🔴

99 other measured values are unchanged.

@trueadm
trueadm merged commit 1066cf6 into main Oct 3, 2026
52 checks passed
@trueadm
trueadm deleted the perf/islands-signal-action-placement branch October 3, 2026 18:37
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