Skip to content

perf(start-plugin-core): run the Rsbuild metadata loader right after the Start transform - #8749

Open
guru-irl wants to merge 5 commits into
TanStack:mainfrom
guru-irl:perf/start-metadata-loader-pre-phase
Open

guru-irl wants to merge 5 commits into
TanStack:mainfrom
guru-irl:perf/start-metadata-loader-pre-phase

Conversation

@guru-irl

@guru-irl guru-irl commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Changes

Motivation

  • On Rsbuild, Start records the server functions it finds in each module in the module's buildInfo, so modules restored from Rspack's persistent cache keep their server functions.
  • A small loader writes that metadata, and it ran in the post phase, after builtin:swc-loader.
  • Rspack runs consecutive JavaScript loaders in one pass and returns to Rust at each builtin loader, so a JavaScript loader after SWC needs its own pass.
  • Each pass converts the module source between Rust and JavaScript and runs the JavaScript loader runner.

Changes

  • The metadata loader rule is now the first rule and runs in the pre phase. Pre loaders run right to left, so it runs right after the Start transform and before normal loaders such as builtin:swc-loader, in the same JavaScript loader pass as the transform.
  • The improvement only applies when import protection is disabled. Start's import-protection loader also runs after SWC, so with import protection enabled each module still needs a second pass. fix(start-plugin-core): skip the Rsbuild import-protection loader when disabled #8748 skips that loader when import protection is disabled. With both changes, such apps need one JavaScript loader pass instead of two for each module that SWC compiles.
  • Production module ids and chunk hashes change once, because the loader chain is part of each module's identifier. The emitted code does not change: with named ids, every output file has the same lines, at most with modules in a different order.
  • COMPILER_ARCHITECTURE.md now says pre instead of post.

Tests

  • @tanstack/start-plugin-core test:unit, test:types and test:eslint pass. The custom-server-rsbuild e2e passes in dev and prod (it uses Rspack's persistent cache), the server-functions e2e passes for Rsbuild SSR from a fresh build and for the Rsbuild cache spec, and the react-start/rsbuild e2e passes.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with the relevant test commands, or tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

@changeset-bot

changeset-bot Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bb24862

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@tanstack/start-plugin-core Patch
@tanstack/react-start-rsc Patch
@tanstack/react-start Patch
@tanstack/solid-start Patch
@tanstack/vue-start Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: TanStack/router/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eab6833a-50f5-43a3-a493-ac38f08f6ae8
📥 Commits

Reviewing files that changed from the base of the PR and between 76cd9e1 and c2c24a5.

📒 Files selected for processing: 6
  • .changeset/start-metadata-loader-pre-phase.md
  • e2e/react-start/custom-server-rsbuild/src/functions/inline-loader-fn.js
  • e2e/react-start/custom-server-rsbuild/src/routes/index.tsx
  • e2e/react-start/custom-server-rsbuild/tests/server-fns.spec.ts
  • packages/start-plugin-core/src/rsbuild/COMPILER_ARCHITECTURE.md
  • packages/start-plugin-core/src/rsbuild/start-compiler-host.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📝 Walkthrough

The Rsbuild metadata loader now runs in the pre phase. The custom-server example adds a server function imported with a ! prefix, and an end-to-end test checks its greeting.

Changes: Rsbuild metadata loader

Layer / File(s) Summary
Set the metadata loader phase
packages/start-plugin-core/src/rsbuild/start-compiler-host.ts, packages/start-plugin-core/src/rsbuild/COMPILER_ARCHITECTURE.md, .changeset/start-metadata-loader-pre-phase.md
The metadata-loader rule is prepended to the module rules and uses enforce: 'pre'. The documentation and changeset describe the loader phase and related production module ID and chunk hash changes.
Exercise an inline-loader server function
e2e/react-start/custom-server-rsbuild/src/functions/inline-loader-fn.js, e2e/react-start/custom-server-rsbuild/src/routes/index.tsx, e2e/react-start/custom-server-rsbuild/tests/server-fns.spec.ts
The example imports and calls getInlineLoaderGreeting through a !-prefixed path. The test checks that clicking the button displays the returned greeting.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant StartTransform
  participant MetadataLoader
  participant BuiltinSWC
  StartTransform->>MetadataLoader: transform completes
  MetadataLoader->>BuiltinSWC: loader processes module before builtin SWC
Loading

Suggested reviewers: schiller-manuel

Merge Risk: ⚪ Minimal · up to c2c24

The metadata loader runs after the Start transform and preserves metadata for the inline-loader server-function path. No actionable merge-blocking risk is established; the change is ready to merge subject to normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. (2 skipped: 2… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description includes the required Changes, Checklist, and Release Impact sections. It explains the motivation, implementation, performance effect, production impact, documentation update, and test…
Title check Passed The title clearly and concisely describes the main performance change: moving the Rsbuild metadata loader after the Start transform.
Full details: Description check

Explanation

The description includes the required Changes, Checklist, and Release Impact sections. It explains the motivation, implementation, performance effect, production impact, documentation update, and test results. All checklist items are addressed, and a changeset is noted.

Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nx-cloud

nx-cloud Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit bb24862

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ❌ Failed 20m 48s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 43s View ↗

☁️ Nx Cloud last updated this comment at 2026-10-19 06:37:40 UTC

@pkg-pr-new

pkg-pr-new Bot commented Oct 19, 2026

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@8749

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@8749

@tanstack/eslint-plugin-start

npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@8749

@tanstack/history

npm i https://pkg.pr.new/@tanstack/history@8749

@tanstack/react-router

npm i https://pkg.pr.new/@tanstack/react-router@8749

@tanstack/react-router-devtools

npm i https://pkg.pr.new/@tanstack/react-router-devtools@8749

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@8749

@tanstack/react-start

npm i https://pkg.pr.new/@tanstack/react-start@8749

@tanstack/react-start-client

npm i https://pkg.pr.new/@tanstack/react-start-client@8749

@tanstack/react-start-rsc

npm i https://pkg.pr.new/@tanstack/react-start-rsc@8749

@tanstack/react-start-server

npm i https://pkg.pr.new/@tanstack/react-start-server@8749

@tanstack/router-cli

npm i https://pkg.pr.new/@tanstack/router-cli@8749

@tanstack/router-core

npm i https://pkg.pr.new/@tanstack/router-core@8749

@tanstack/router-devtools

npm i https://pkg.pr.new/@tanstack/router-devtools@8749

@tanstack/router-devtools-core

npm i https://pkg.pr.new/@tanstack/router-devtools-core@8749

@tanstack/router-generator

npm i https://pkg.pr.new/@tanstack/router-generator@8749

@tanstack/router-plugin

npm i https://pkg.pr.new/@tanstack/router-plugin@8749

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@8749

@tanstack/router-utils

npm i https://pkg.pr.new/@tanstack/router-utils@8749

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/@tanstack/router-vite-plugin@8749

@tanstack/solid-router

npm i https://pkg.pr.new/@tanstack/solid-router@8749

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/@tanstack/solid-router-devtools@8749

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@8749

@tanstack/solid-start

npm i https://pkg.pr.new/@tanstack/solid-start@8749

@tanstack/solid-start-client

npm i https://pkg.pr.new/@tanstack/solid-start-client@8749

@tanstack/solid-start-server

npm i https://pkg.pr.new/@tanstack/solid-start-server@8749

@tanstack/start-client-core

npm i https://pkg.pr.new/@tanstack/start-client-core@8749

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/@tanstack/start-fn-stubs@8749

@tanstack/start-plugin-core

npm i https://pkg.pr.new/@tanstack/start-plugin-core@8749

@tanstack/start-server-core

npm i https://pkg.pr.new/@tanstack/start-server-core@8749

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/@tanstack/start-static-server-functions@8749

@tanstack/start-storage-context

npm i https://pkg.pr.new/@tanstack/start-storage-context@8749

@tanstack/valibot-adapter

npm i https://pkg.pr.new/@tanstack/valibot-adapter@8749

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/@tanstack/virtual-file-routes@8749

@tanstack/vue-router

npm i https://pkg.pr.new/@tanstack/vue-router@8749

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/@tanstack/vue-router-devtools@8749

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@8749

@tanstack/vue-start

npm i https://pkg.pr.new/@tanstack/vue-start@8749

@tanstack/vue-start-client

npm i https://pkg.pr.new/@tanstack/vue-start-client@8749

@tanstack/vue-start-server

npm i https://pkg.pr.new/@tanstack/vue-start-server@8749

@tanstack/zod-adapter

npm i https://pkg.pr.new/@tanstack/zod-adapter@8749

commit: bb24862

@codspeed

codspeed Bot commented Oct 19, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 0.65%

⚠️ 48 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

ℹ️ 3 benchmarks have no flame graph

The flamegraph could not be generated because too much time was spent in runtime internals, making the visualization not useful for performance analysis.

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 192 untouched benchmarks
⏩ 3 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Memory mem server error-paths redirect (solid) 11.6 KB 12.3 KB -5.22%
⚡ Memory mem client navigation-churn (solid) 113.8 KB 109.3 KB +4.15%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing guru-irl:perf/start-metadata-loader-pre-phase (bb24862) with main (b1b1117)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant