Skip to content

perf(rspack-plugin): specialize imported void roots and component calls in production builds - #1840

Merged
trueadm merged 2 commits into
mainfrom
perf/rspack-void-component-proofs
Oct 7, 2026
Merged

trueadm merged 2 commits into
mainfrom
perf/rspack-void-component-proofs

Conversation

@trueadm

@trueadm trueadm commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1839. Rspack production client builds now specialize a createRoot or hydrateRoot root, and a <Component /> call, over an imported void @{} component, as the Vite plugin already does. Before, the Rspack loader never gave the compiler a cross-module proof, so every imported root kept the generic returned-value renderer.

A loader can't see another module's final output when it runs. So the proof is built from the module graph after make, and each importer that can use it is compiled once more. This follows the same pattern as the existing CSS-module constants controller. An import is proven only when all three of these hold:

  1. The provider's authored claim: Octane compiled the provider in this build, and findVoidComponentExports lists the export as void.
  2. The provider's final code: the provider's final JavaScript, after SWC and every later loader, still exports a function that cannot return a value. The new analyzeCompiledModule() in octane/compiler/bundler checks this. It follows the wrappers the compiler emits (__s, markWarm, bindPresentationView, and a comparator-free memo) and the setup IIFEs that transpilers lower. Reassigned bindings, eval, async functions, generators, re-exports and value returns stay unproven.
  3. The importer's final code: the importer's final code still binds each local that Octane's output read through to the same request and export.

Edges are read from the real ESM connections, so aliases, layers and issuer rules are respected.

When an importer's proof fails on its rebuilt graph, it is rebuilt once more without the proof. That covers a later loader that rewrites a provider or rebinds an import. A proven module that changes after that, for example through another plugin's rebuildModule, fails the build at seal or asset emission. Watch builds record the facts their cached modules need, but never consume proofs. Dev, HMR, profiling and Lynx-style builds keep the generic paths; those are builds with a custom runtime, universalRuntime or layerSpecializations.

The CSS controller's graph helpers move unchanged to module-graph.js, so both controllers share them.

Measurements

Production builds with the runtime bundled. Baseline is the same tree with the controller not installed; median of 5–7 runs.

Scenario gzip brotli build time
Issue repro (one hydrateRoot leaf) 86,370 → 51,880 (−40%) 72,107 → 44,359 1,252 → 1,253 ms
Root over 4 nested void components 63,353 → 33,719 (−47%) 53,354 → 29,125 1,205 → 1,231 ms
200-component tree, each with a {count as any} hole 78,182 → 78,188 (+6 B) — ~1,460 → ~1,775 ms (+21%)

The 200-component case shows the cost side. Its renderable holes keep the generic return path in the runtime, so there's no byte win. Every non-leaf importer is still compiled twice. A first version of this PR cost +41% there; two changes brought it down:

  • each final module is parsed once for both facts;
  • a provider that will itself be rebuilt is proven only on its rebuilt code, not on its stale first pass.

What remains is mostly the inherent rebuild.

Validation

  • pnpm format:check — pnpm format:files:check on every changed file only
  • pnpm typecheck — pnpm typecheck:files on the changed files only (both projects clean)
  • pnpm test — not run in full
  • targeted tests:
    • vitest --project rspack-plugin: 13 files, 182 tests, including the new void-component-proofs.test.ts, which covers main thread and workers.
    • vitest --project rsbuild-plugin: 59 tests.
    • vitest --project rspeedy-plugin: 64 tests. The demo tests need the pnpm 12 binary on PATH locally.
    • octane tests/compiler/void-root-exports.test.ts and bundler-compiler.test.ts: 81 tests.
    • Re-ran void-root-exports and void-component-proofs after merging current main.

Each new test was checked by breaking the matching part of the implementation:

  • Not installing the controller fails 9 of the 12 original adapter tests.
  • Skipping the provider's final-code check renders <main><b>value</b></main>, because Loud's output is dropped.
  • Skipping the importer binding check, or the generic rebuild, drops the returned JSX ('').
  • Disabling seal and asset verification lets a post-specialization rebuild pass.
  • Watch-mode proofs, and a watch cache without facts, each fail their test.

The authored void claims for 1,971 of 1,972 exports across 444 repo .tsrx files re-prove on both Octane's own output and its SWC ES5 lowering. The one miss is a direct-call twin with an isRenderCall guard return, which stays generic.

Risk / follow-ups

  • Build time: production one-shot builds compile each proof-consuming importer twice. Vite avoids that by loading providers before transforming; Rspack loaders can't. Measured above.
  • No benchmark ratio guard yet: the Rspack bundle win has no guard, because benchmarks/codegen-size externalizes the runtime and has no jsdom for a semantic control. Specialization is guarded by the adapter tests instead, following the Vite adapter tests.
  • Conservative misses: a compiled export with a direct-call twin, and any compiled wrapper outside the four above, stays generic. The void-root-exports test fails when a compiler change emits a new wrapper around claimed exports.

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
Production-only but changes compile/caching behavior (double-compile importers, fail-closed graph verification) and relies on static analysis of final JS; incorrect proofs could mis-specialize roots/calls, though conservative checks and tests mitigate this.

Overview
Rspack production client builds now match the Vite plugin by specializing createRoot/hydrateRoot and <Component /> when the target is a proven imported void @{} component, enabling tree-shaking of the generic return-value path (reported ~40% gzip on a one-root hydrateRoot app).

Because loaders cannot see other modules’ final output, the plugin adds a post-make proof controller (same shape as CSS-module constants): it walks ESM edges, requires Octane’s authored void export claim and analyzeCompiledModule() on provider/importer JavaScript after SWC and later loaders, then rebuilds proof-consuming importers with isVoidComponentImport. Importers using proofs are non-cacheable; proofs fail the build if sources change after specialization. Watch/dev/HMR/profiling and custom runtime / universalRuntime / layerSpecializations stay generic.

octane/compiler/bundler exports analyzeCompiledModule (voidComponentExports, importBindings). Shared Rspack graph helpers move to module-graph.js; loaders/workers carry void build metadata like CSS constants.

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

trueadm and others added 2 commits October 7, 2026 08:51
…ls in production builds

Rspack production client builds kept the generic root and component-call
paths for compiled components imported from other modules, because the
loader never supplied the cross-module void-export proof that the Vite
plugin does. The one-root hydrateRoot app from the issue drops from about
86 KB to 52 KB gzip.

A main-thread controller proves each candidate import from the effective
module graph after make, then rebuilds the importer with the proof. A proof
needs both Octane's authored void-export claim for the module it was
compiled from and the provider's final JavaScript, after SWC and every later
loader, still unable to return a value. The importer's final code must also
bind the import to the same module and export. An importer whose proof does
not hold after its rebuild is rebuilt once more without one. A proven module
that changes later fails the build at seal or asset emission. Watch builds
record facts for the cache but never consume proofs.

octane/compiler/bundler adds analyzeCompiledModule() for the final-code
facts. The CSS-module controller's graph helpers move to module-graph.js so
both controllers share them.

Fixes #1839

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the agent-authored Diff or issue body substantially produced by an AI agent label Oct 7, 2026
@trueadm
trueadm marked this pull request as ready for review October 7, 2026 07:53
@github-actions github-actions Bot added the perf PR: performance work label Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

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

Compares 35eb3c729, the merge commit's first parent with 99687e76b 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.675 2.633 ±0.0% −3.4% … +0.0% ⚪ within noise
octane-tsrx replace 6.583 6.550 +0.0% −3.0% … +3.8% ⚪ within noise
octane-tsrx add 2.467 2.467 ±0.0% −0.0% … +2.0% ⚪ within noise
octane-tsrx update 0.133 0.131 −0.7% −1.6% … ±0.0% ⚪ within noise
octane-tsrx select 0.006 0.006 +1.1% ±0.0% … +2.1% ⚪ within noise
octane-tsrx swap 0.031 0.033 +0.3% −0.7% … +0.7% ⚪ within noise
octane-tsrx remove 0.015 0.015 +0.8% −1.7% … +3.4% ⚪ within noise
octane-tsrx runlots 24.933 24.808 −0.8% −2.6% … +1.2% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 ±0.0% −1.1% … +1.1% ⚪ within noise
octane-tsrx clear 42.667 41.875 +0.1% −0.5% … +1.6% ⚪ within noise
octane-jsx run 3.842 3.583 −2.9% −3.9% … −1.3% ⚪ within noise
octane-jsx replace 7.158 7.250 +2.4% −3.3% … +9.1% ⚪ within noise
octane-jsx add 3.292 3.317 +0.0% −2.8% … +3.1% ⚪ within noise
octane-jsx update 0.279 0.282 ±0.0% −2.1% … +1.3% ⚪ within noise
octane-jsx select 0.130 0.128 −0.3% −1.4% … +0.8% ⚪ within noise
octane-jsx swap 0.233 0.216 −1.1% −2.3% … +0.6% ⚪ within noise
octane-jsx remove 0.174 0.174 +0.3% −0.7% … +2.8% ⚪ within noise
octane-jsx runlots 29.283 29.467 −1.8% −3.1% … +0.4% ⚪ within noise
octane-jsx select_lots 1.497 1.595 −0.8% −2.7% … +2.3% ⚪ within noise
octane-jsx clear 47.167 44.617 −1.6% −7.6% … +5.3% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

No changes across 60 measured values.

Public-import reachability bundles (bytes)

No changes across 108 measured values.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website fcece29 Commit Preview URL

Branch Preview URL
Oct 07 2026, 08:19 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website-mcp fcece29 Commit Preview URL

Branch Preview URL
Oct 07 2026, 08:21 AM

@trueadm
trueadm merged commit b8e55da into main Oct 7, 2026
53 checks passed
@trueadm
trueadm deleted the perf/rspack-void-component-proofs branch October 7, 2026 10:20
trueadm added a commit that referenced this pull request Oct 7, 2026
Conflicts: the 87 react-parity manifests and the user-apps-v1 manifest
record the lockfile hash, which main changed by adding jsdom to the
codegen-size benchmark (#1840); pnpm sync regenerated them. The merged
lockfile needs no changes from `pnpm install --lockfile-only`.

The new anonymous-default-component fixture (#1842) is already in the
new layout and compiles in both modes; #1842's tests pass on this
branch's parser.

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.

Rspack production builds miss imported void-root specialization

1 participant