Skip to content

perf(octane): load independent idle/visible/media strategies on demand - #1681

Merged
trueadm merged 3 commits into
mainfrom
claude/agitated-morse-fad4c1
Oct 3, 2026
Merged

trueadm merged 3 commits into
mainfrom
claude/agitated-morse-fad4c1

Conversation

@trueadm

@trueadm trueadm commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The independent island bootstrap (packages/octane/src/hydration/independent-island.ts) statically imported idle(), visible() and media() to rebuild a wrapper's serialized when. Every islands page therefore shipped all three, including pages whose widgets use only load() and interaction(), such as examples/signal-chat.

Result: the signal-chat islands-only route drops from 71,763 B to 71,151 B gzip-9 (−612 B), still 18 scripts. That baseline is d826c3e, before #1678 (signal Action frame) landed. The branch now includes #1678, which measured the same route at 67,719 B and set a 68 KiB cap. The combined route is not measured locally; CI's islands budget e2e runs it against that cap.

What changed

  • New subpath octane/hydration/independent-strategies exports independentHydrationStrategies. It holds the attribute decoding that automaticStrategy did, and it is now the only module that imports idle/visible/media.
  • New strategies option on bootstrapIndependentHydration and registerIndependentHydrationIsland:
    • When passed, triggers arm during registration, exactly as before. This is the synchronous installation that independent-island-strategies.test.ts pins.
    • When omitted, an island whose when is idle, visible or media imports the strategies on demand and arms once they resolve. Dispose and pause during the load are honored. A failed load, or a failed arm such as matchMedia throwing, goes to onError, as a synchronous arm failure did before.
  • Attribute names moved: the four parameter attribute names move from hydration-markers.ts to a leaf module, hydration/strategy-attributes.ts. Only the server and the strategies chunk use them. If the strategies chunk shares any module with the bootstrap graph, the bundler splits that module into a separate chunk, and every islands page then loads it. Sharing hydration-markers measured +329 B plus one extra script.
  • Generated entries unchanged: packages/app-core/src/codegen.js passes no strategies, so its pages use the on-demand path.

Why no preload in the generated entries

I measured an alternative in which the entries scan the initial DOM for idle, visible or media sidecars and await the strategies before calling the bootstrap:

Variant islands entry full entry hydration chunk
Entry preload, awaited before bootstrap +94 B +111 B −597 B
Entry passes an on-demand loader +37 B +30 B −597 B
On demand inside octane (this PR) 0 0 −535 B

The preload made every renderer page pay about 111 B, including pages with no islands. It also delayed load() islands behind the strategies chunk. A failed chunk load rejected the whole bootstrap, so even interaction() islands stopped registering. And it bought nothing an app can observe: an idle, visible or media island cannot arm before the chunk arrives in either design.

Reviewer notes

  • Tree-shaking pitfall: Promise.all([import('octane/hydration'), …]).then(([{ … }]) => …) hides the destructuring from the bundler. The full entry then keeps the whole octane/hydration namespace, which reshuffled shared chunks and grew the islands page to 75,351 B. Only import(x).then(({ a }) => …) or .then((m) => m.a) stays tree-shakeable.
  • Docs: docs/deferred-hydration.md describes the on-demand load and the strategies option. The changeset is minor because it adds a new public subpath and option.

Validation

Per-chunk bytes for the islands-only page, baseline vs this PR, gzip-9 of the scripts the page loads:

  • hydration −535, data-encoding −58, event-capture −20; every other chunk within ±9 B.

  • The full entry, octane-hydrate, is unchanged (2,328 → 2,329).

  • pnpm format:files:check on the changed files

  • pnpm typecheck:files on the changed files (clean); full pnpm typecheck was not run locally

  • pnpm test (full suite not run locally; left to CI)

  • targeted tests:

    • packages/octane/tests/hydration/independent-island-strategies.test.ts: 12 pass. The existing cases now pass strategies. New cases cover arming on demand, dispose and pause before the load resolves, and an arm failure reaching onError. Five deliberate code breaks each failed the matching test, including one that ignores a passed strategies and fails the synchronous-arming cases.
    • Other independent island suites: independent-island.test.ts, -signal-identity, early-independent-intent, and independent-parent all pass, 120 tests across the five files.
    • packages/vite-plugin-octane/tests/islands-route.test.ts: a real Vite production build now also asserts that the five strategy modules stay out of the islands bootstrap's static graph. A control checks they are still emitted. Re-adding a static import of the strategies fails it.
  • examples/signal-chat: pnpm build, then the islands-only JavaScript budget e2e against the production preview, passes at 71,151 B (baseline 71,763 B on d826c3e).

  • node benchmarks/bundle-size/run-minimal.mjs --budgets and benchmarks/bundle-size/run.mjs pass. hydrate-root, deferred-hydration and capture-only are byte-identical to the baseline.

Risk / follow-ups

  • Arming timing change: in generated apps, an initial idle, visible or media independent island now arms after the strategies chunk loads, not inside the bootstrap call. An app has no way to observe the bootstrap call itself, and pause and dispose are handled during the wait. Direct callers who want synchronous arming pass strategies: independentHydrationStrategies.
  • Existing bundler oddity: the built hydration chunk's namespace object contains STREAMED_RENDERER_RECEIVER: () => STREAMED_RENDERER_RECEIVER, but that identifier isn't declared in the chunk. It is also present on main, and nothing reads that property.

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

Low Risk
Bundle-size and lazy-loading change for independent hydration; behavior is covered by expanded tests, with only a slight delay before idle/visible/media islands arm when strategies is omitted.

Overview
Independent island bootstrap no longer statically pulls in idle(), visible(), and media(). Those triggers live in a new octane/hydration/independent-strategies chunk (independentHydrationStrategies), loaded the first time a registered widget needs one; islands pages that only use load() and interaction() skip that JavaScript (e.g. signal-chat islands route −612 B gzip).

bootstrapIndependentHydration and registerIndependentHydrationIsland accept an optional strategies option to arm triggers synchronously during registration (same behavior as before). Generated app entries omit it and use the on-demand path. Strategy parameter attribute names moved to hydration/strategy-attributes.ts so they are not shared with the bootstrap graph and forced into every islands entry.

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

trueadm and others added 2 commits October 3, 2026 19:37
The independent island bootstrap statically imported idle(), visible() and
media() to rebuild a wrapper's serialized `when`, so every islands page shipped
all three even when its widgets used only load() and interaction().

The decoding now lives in octane/hydration/independent-strategies. The
bootstrap and registerIndependentHydrationIsland accept it as `strategies`,
which arms triggers during registration exactly as before. When it is omitted,
an island that needs a trigger imports the strategies on demand and arms once
they resolve, honoring dispose and pause in between and reporting a failed
load or arm through onError. The four parameter attribute names move to a leaf
module so the strategies chunk shares no module with the bootstrap; sharing
hydration-markers split it into an extra chunk every islands page loaded.

signal-chat islands-only route: 71,763 -> 71,151 B gzip-9, 18 scripts.

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
@github-actions
github-actions Bot marked this pull request as draft October 3, 2026 18:38
@trueadm
trueadm marked this pull request as ready for review October 3, 2026 19:06
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No budget breaches, no added work, and no timing changes beyond ±3%.

Compares 1066cf6c5, the merge commit's first parent with 576cc998b 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

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 2.783 2.808 +1.8% −3.5% … +6.9% ⚪ within noise
octane-tsrx replace 5.775 5.817 ±0.0% −2.6% … +1.8% ⚪ within noise
octane-tsrx add 2.458 2.458 ±0.0% −3.8% … +2.0% ⚪ within noise
octane-tsrx update 0.115 0.115 ±0.0% −1.4% … +0.7% ⚪ within noise
octane-tsrx select 0.005 0.005 −0.5% −1.1% … ±0.0% ⚪ within noise
octane-tsrx swap 0.034 0.033 −0.3% −2.4% … +0.7% ⚪ within noise
octane-tsrx remove 0.017 0.018 +2.9% +1.5% … +7.1% ⚪ within noise
octane-tsrx runlots 23.608 23.350 +0.8% −2.2% … +3.6% ⚪ within noise
octane-tsrx select_lots 0.005 0.006 +1.0% +0.0% … +2.0% ⚪ within noise
octane-tsrx clear 43.317 43.525 −0.2% −2.7% … +0.7% ⚪ within noise
octane-jsx run 3.225 3.242 ±0.0% −2.9% … +1.5% ⚪ within noise
octane-jsx replace 7.083 6.875 −2.9% −9.6% … +0.7% ⚪ within noise
octane-jsx add 3.033 3.225 ±0.0% ±0.0% … +3.3% ⚪ within noise
octane-jsx update 0.250 0.240 −1.4% −3.3% … +0.7% ⚪ within noise
octane-jsx select 0.133 0.132 −1.0% −1.5% … −0.3% ⚪ within noise
octane-jsx swap 0.236 0.231 ±0.0% −0.9% … +0.0% ⚪ within noise
octane-jsx remove 0.174 0.172 −0.8% −1.7% … +0.0% ⚪ within noise
octane-jsx runlots 29.075 28.958 −0.5% −3.4% … +3.0% ⚪ within noise
octane-jsx select_lots 1.499 1.524 −0.8% −1.5% … +1.9% ⚪ within noise
octane-jsx clear 47.342 47.233 +0.2% −1.0% … +2.6% ⚪ 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)

No changes across 105 measured values.

@trueadm
trueadm merged commit c1a8faf into main Oct 3, 2026
50 checks passed
@trueadm
trueadm deleted the claude/agitated-morse-fad4c1 branch October 3, 2026 19:28
trueadm added a commit that referenced this pull request Oct 3, 2026
Main gained #1685, which raised 51 budgets for the useLayoutSnapshot
commit-phase priority fix (#1686), and #1681/#1665. Re-measured on main
425a32a: each of #1663, #1664 and #1666 merged alone, and all three
plus #1686 merged together. Each budget is the larger of main's value and
the largest measured value plus 32 (raw/gzip) or 256 (brotli), so the
three perf PRs and #1686 can land in any order.

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