perf(start): construct compiler-owned server function AST directly #8524
codex/fuse-clone-provenance fromcodex/direct-compiler-ast·opened 🎯 Changes#
Stacks on #8523; base branch: codex/fuse-clone-provenance.
Server-function compilation currently reparses compiler-owned JavaScript snippets for RPC calls, provider wrappers, imports, directives, and HMR guards. Construct those nodes directly with typed AST builders, preserving generated-reference ownership, source maps, and emitted code.
Compound builders live in named functions with readable inline snapshots of their generated JavaScript. Additional execution tests cover client/SSR/provider output across React, Solid, and Vue, escaping, binding cleanup, HMR, and invalidation.
Measured performance#
Complete generated React Start production builds, with 10 server functions per module and seven alternating fresh-process pairs per size:
| Server functions | #8523 median | This change median | Reduction | Peak RSS, before → after |
|---|---|---|---|---|
| 100 | 333.07 ms | 326.33 ms | Within noise | 329.8 → 324.2 MiB |
| 1,000 | 886.94 ms | 813.09 ms | 8.3% | 519.9 → 483.2 MiB |
| 5,000 | 6,682.98 ms | 6,048.85 ms | 9.5% | 883.8 → 849.5 MiB |
The candidate wins all seven pairs at 1,000 and 5,000 functions. The 5,000-function fixture is a stress case. Timings include Vite builder creation, transformation, bundling, minification, and writes; they exclude fixture generation, plugin-module loading, and output validation. All RPCs and handlers are retained; client output is byte-identical and server output matches after normalizing build paths and chunk filenames.
Focused compiler measurements show 15.0% faster client transforms, 19.9% faster SSR callers, 27.7% faster providers, and 29.3% faster development providers. The existing smaller e2e app's whole-build result was inconclusive (950.26 → 962.54 ms), so these gains should not be generalized to every app.
Measured on Node 24.8.0 / Apple M3 Max against #8523 at 6c228b37ad, with the extracted candidate on 9148909cc5. The current stack base 3dfc160aee only adds Solid CSS test changes. Full methodology, raw results, and attribution.
Previously completed validation#
- 608 compiler tests and 165 browser tests; TypeScript 5.6–7, ESLint, and package build/export checks passed.
- The latest inline-snapshot-only edit passed all eight builder tests.
- All 18 bundle scenarios have zero size/chunk-count changes; all 38 emitted client JS files are byte-identical.
- No checks were rerun when opening this PR; CI will validate the published branch.
✅ 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).
Summary by CodeRabbit#
- Performance
- Server-function compilation and production builds now run faster in several benchmarked workloads, while preserving equivalent generated output.
- Reliability
- Added checks for generated server-function output across React, Solid, and Vue, including client, server-rendering, provider, and development scenarios.
- Documentation
- Added guidance and results for compiler and production-build benchmarks.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: start-plugin-core
🚀 Changeset Version Preview#
6 package(s) bumped directly, 7 bumped as dependents.
🟥 Major bumps#
Package Version Reason @tanstack/router-plugin1.168.41 → 2.0.0 Changeset @tanstack/router-utils1.162.3 → 2.0.0 Changeset @tanstack/start-plugin-core1.171.48 → 2.0.0 Changeset 🟩 Patch bumps#
Package Version Reason @tanstack/react-router1.170.40 → 1.170.41 Changeset @tanstack/react-start-rsc0.1.58 → 0.1.59 Changeset @tanstack/router-generator1.167.39 → 1.167.40 Changeset @tanstack/react-start1.168.59 → 1.168.60 Dependent @tanstack/react-start-client1.168.38 → 1.168.39 Dependent @tanstack/react-start-server1.167.45 → 1.167.46 Dependent @tanstack/router-cli1.167.39 → 1.167.40 Dependent @tanstack/router-vite-plugin1.167.41 → 1.167.42 Dependent @tanstack/solid-start1.168.56 → 1.168.57 Dependent @tanstack/vue-start1.168.55 → 1.168.56 Dependent View your CI Pipeline Execution ↗ for commit c6c33e22857cdefcad00e217201f05e5bcd39551
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded 25m 52s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 2m 7s View ↗
☁️ Nx Cloud last updated this comment at
2026-09-27 20:42:27UTCBundle Size Benchmarks#
This pull request does not affect bundle size in any measured scenario.
More templates
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-router-react-example-basic-authjs
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-rsbuild
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-clerk-basic
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-example-next-migration
- tanstack-start-example-rscs
- tanstack-start-streaming-data-from-server-functions
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
- tanstack-router-vue-example-basic-jsx
- tanstack-router-vue-example-basic-file-based-jsx
- tanstack-router-vue-example-basic-file-based-sfc
- tanstack-router-solid-example-authenticated-routes
- tanstack-router-solid-example-authenticated-routes-firebase
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-default-search-params
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-basic-virtual-file-based
- tanstack-router-solid-example-basic-virtual-inside-file-based
- tanstack-router-solid-example-deferred-data
- tanstack-router-solid-i18n-paraglide
- tanstack-router-solid-example-kitchen-sink
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-kitchen-sink-solid-query
- tanstack-router-solid-example-kitchen-sink-solid-query-file-based
- tanstack-router-solid-example-large-file-based
- tanstack-router-solid-example-location-masking
- tanstack-router-solid-example-navigation-blocking
- tanstack-router-solid-example-quickstart
- tanstack-router-solid-example-quickstart-esbuild-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-router-solid-example-quickstart-rspack-file-based
- tanstack-router-solid-example-quickstart-webpack-file-based
- @tanstack/router-solid-mono-simple
- router-solid-mono-simple-lazy
- router-solid-monorepo-solid-query
- tanstack-router-solid-example-scroll-restoration
- tanstack-solid-router-search-validator-adapters
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-auth
- tanstack-solid-start-example-basic-authjs
- tanstack-solid-start-example-basic-cloudflare
- tanstack-solid-start-example-basic-netlify
- tanstack-solid-start-example-basic-nitro
- tanstack-start-example-basic-solid-query
- tanstack-solid-start-example-basic-static
- tanstack-solid-start-bun-hosting
- tanstack-solid-start-example-convex-better-auth
- tanstack-solid-start-example-counter
- tanstack-solid-start-i18n-paraglide
- tanstack-solid-start-example-large
- tanstack-solid-start-streaming-data-from-server-functions
- tanstack-solid-start-example-supabase-basic
- tanstack-solid-start-tailwind-v4
- tanstack-router-solid-example-view-transitions
- tanstack-router-solid-example-with-framer-motion
- tanstack-router-solid-example-with-trpc
@tanstack/arktype-adapter
npm i https://pkg.pr.new/@tanstack/arktype-adapter@8524@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@8524@tanstack/eslint-plugin-start
npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@8524@tanstack/history
npm i https://pkg.pr.new/@tanstack/history@8524@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@8524@tanstack/react-router
npm i https://pkg.pr.new/@tanstack/react-router@8524@tanstack/react-router-devtools
npm i https://pkg.pr.new/@tanstack/react-router-devtools@8524@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@8524@tanstack/react-start
npm i https://pkg.pr.new/@tanstack/react-start@8524@tanstack/react-start-client
npm i https://pkg.pr.new/@tanstack/react-start-client@8524@tanstack/react-start-rsc
npm i https://pkg.pr.new/@tanstack/react-start-rsc@8524@tanstack/react-start-server
npm i https://pkg.pr.new/@tanstack/react-start-server@8524@tanstack/router-cli
npm i https://pkg.pr.new/@tanstack/router-cli@8524@tanstack/router-core
npm i https://pkg.pr.new/@tanstack/router-core@8524@tanstack/router-devtools
npm i https://pkg.pr.new/@tanstack/router-devtools@8524@tanstack/router-devtools-core
npm i https://pkg.pr.new/@tanstack/router-devtools-core@8524@tanstack/router-generator
npm i https://pkg.pr.new/@tanstack/router-generator@8524@tanstack/router-plugin
npm i https://pkg.pr.new/@tanstack/router-plugin@8524@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@8524@tanstack/router-utils
npm i https://pkg.pr.new/@tanstack/router-utils@8524@tanstack/router-vite-plugin
npm i https://pkg.pr.new/@tanstack/router-vite-plugin@8524@tanstack/solid-router
npm i https://pkg.pr.new/@tanstack/solid-router@8524@tanstack/solid-router-devtools
npm i https://pkg.pr.new/@tanstack/solid-router-devtools@8524@tanstack/solid-router-ssr-query
npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@8524@tanstack/solid-start
npm i https://pkg.pr.new/@tanstack/solid-start@8524@tanstack/solid-start-client
npm i https://pkg.pr.new/@tanstack/solid-start-client@8524@tanstack/solid-start-server
npm i https://pkg.pr.new/@tanstack/solid-start-server@8524@tanstack/start-client-core
npm i https://pkg.pr.new/@tanstack/start-client-core@8524@tanstack/start-fn-stubs
npm i https://pkg.pr.new/@tanstack/start-fn-stubs@8524@tanstack/start-plugin-core
npm i https://pkg.pr.new/@tanstack/start-plugin-core@8524@tanstack/start-server-core
npm i https://pkg.pr.new/@tanstack/start-server-core@8524@tanstack/start-static-server-functions
npm i https://pkg.pr.new/@tanstack/start-static-server-functions@8524@tanstack/start-storage-context
npm i https://pkg.pr.new/@tanstack/start-storage-context@8524@tanstack/valibot-adapter
npm i https://pkg.pr.new/@tanstack/valibot-adapter@8524@tanstack/virtual-file-routes
npm i https://pkg.pr.new/@tanstack/virtual-file-routes@8524@tanstack/vue-router
npm i https://pkg.pr.new/@tanstack/vue-router@8524@tanstack/vue-router-devtools
npm i https://pkg.pr.new/@tanstack/vue-router-devtools@8524@tanstack/vue-router-ssr-query
npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@8524@tanstack/vue-start
npm i https://pkg.pr.new/@tanstack/vue-start@8524@tanstack/vue-start-client
npm i https://pkg.pr.new/@tanstack/vue-start-client@8524@tanstack/vue-start-server
npm i https://pkg.pr.new/@tanstack/vue-start-server@8524@tanstack/zod-adapter
npm i https://pkg.pr.new/@tanstack/zod-adapter@8524commit:
c6c33e2Merging this PR will regress 1 benchmark#
:warning: Different runtime environments detected
Some benchmarks with significant performance changes were compared across different runtime environments, which may affect the accuracy of the results.
⚡ 1improved benchmark❌ 1regressed benchmark✅ 189untouched benchmarks⏩ 3skipped benchmarks1Warning
Please fix the performance issues or acknowledge them on CodSpeed.
Performance Changes#
Mode Benchmark BASEHEADEfficiency ❌ Simulation hydrate restored route state and mixed Links (react)213.2 ms 248.4 ms -14.18% ⚡ Memory mem server streaming-peak chunked (react)642.3 KB 349.8 KB +83.63% Tip
Investigate this regression by commenting
@codspeedbot fix this regressionon this PR, or directly use the CodSpeed MCP with your agent.
Comparingcodex/direct-compiler-ast(c6c33e2) withcodex/fuse-clone-provenance(080a540)Footnotes#
-
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. ↩
-
Notes for when this is recut on top of #8504 (now on Yuku 0.19.0), from a review of Yuku's APIs:
- Other compiler-owned snippets that fit builders, beyond server functions:
react-start-rsc/src/plugin/rscCssTransform.ts: the{ __tanstackStartRscCss: null }options object and the<>{null}{null}</>fragment, which are parsed then patched behind runtime guards.router-plugin/src/core/code-splitter/compilers.ts: theconsole.warn(...)statement.consoleis a global, so it needslinkGeneratedReference(node, 'console').start-plugin-core/src/start-compiler/handleCreateServerFn.ts: theparseExpression(functionName)identifier.start-plugin-core/src/hydrate-when-transform.ts:parseExpression(preloadName)and the<Component {...props} />child.
- Keep template parsing where builders would be 3–10× longer: HMR blocks, the provider's extracted handler, import-protection
rewrite.ts, Hydrate lazy imports. - Every builder identifier that refers to a source or import binding must go through
linkGeneratedReference, orremoveUnusedBindingsprunes its import. - Yuku 0.19's
generate()prints any single node, so the builder snapshot tests no longer need to wrap nodes in aProgram.generateModulenow accepts aNode. b.PropertyreturnsObjectProperty | BindingPropertyandb.Literalthe wholeLiteralunion, which is why this PR writesObjectPropertyandDirectiverecords by hand. We may ask upstream for precise builders.parseStatements('')now returns[]without parsing, so the provider-directives call no longer costs an analyze when nothing is missing.
Written with Claude Code (AI-assisted).
- Other compiler-owned snippets that fit builders, beyond server functions:
Sign in to join this conversation.
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
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:
605f17db-53a0-4dec-b85e-2831bde04fcc📥 Commits
Reviewing files that changed from the base of the PR and between 080a540029f7445471be451f1ace27ee4eeedabf and c6c33e22857cdefcad00e217201f05e5bcd39551.
📒 Files selected for processing (43)
.changeset/fuzzy-berries-behave.mdbenchmarks/compiler/README.mdbenchmarks/compiler/direct-ast.mdbenchmarks/compiler/results/direct-ast-app-output.jsonbenchmarks/compiler/results/direct-ast-builders-digests.jsonbenchmarks/compiler/results/direct-ast-builders-timings.jsonbenchmarks/compiler/results/direct-ast-builds.jsonbenchmarks/compiler/results/direct-ast-bundle-baseline-hashes.jsonbenchmarks/compiler/results/direct-ast-bundle-baseline.jsonbenchmarks/compiler/results/direct-ast-bundle-builders-final-hashes.jsonbenchmarks/compiler/results/direct-ast-bundle-builders-final.jsonbenchmarks/compiler/results/direct-ast-bundle-final-hashes.jsonbenchmarks/compiler/results/direct-ast-bundle-final.jsonbenchmarks/compiler/results/direct-ast-bundle-pre-attribution.jsonbenchmarks/compiler/results/direct-ast-caller-digests.jsonbenchmarks/compiler/results/direct-ast-caller-timings.jsonbenchmarks/compiler/results/direct-ast-dense-refined-timings.jsonbenchmarks/compiler/results/direct-ast-digests.jsonbenchmarks/compiler/results/direct-ast-directives-digests.jsonbenchmarks/compiler/results/direct-ast-directives-refined-timings.jsonbenchmarks/compiler/results/direct-ast-directives-timings.jsonbenchmarks/compiler/results/direct-ast-final-digests.jsonbenchmarks/compiler/results/direct-ast-final-timings.jsonbenchmarks/compiler/results/direct-ast-final-verification.jsonbenchmarks/compiler/results/direct-ast-heavy-builds-100.jsonbenchmarks/compiler/results/direct-ast-heavy-builds-1000.jsonbenchmarks/compiler/results/direct-ast-heavy-builds-5000.jsonbenchmarks/compiler/results/direct-ast-hmr-digests.jsonbenchmarks/compiler/results/direct-ast-hmr-refined-timings.jsonbenchmarks/compiler/results/direct-ast-hmr-timings.jsonbenchmarks/compiler/results/direct-ast-hunk-bundles.jsonbenchmarks/compiler/results/direct-ast-imports-digests.jsonbenchmarks/compiler/results/direct-ast-imports-refined-timings.jsonbenchmarks/compiler/results/direct-ast-imports-timings.jsonbenchmarks/compiler/results/direct-ast-provider-digests.jsonbenchmarks/compiler/results/direct-ast-provider-timings.jsonbenchmarks/compiler/results/direct-ast-timings.jsonbenchmarks/compiler/server-fn-ast.mjsbenchmarks/compiler/server-fn-build.mjspackages/start-plugin-core/src/start-compiler/handleCreateServerFn.tspackages/start-plugin-core/src/start-compiler/serverFnAst.tspackages/start-plugin-core/tests/createServerFn/generated-ast.test.tspackages/start-plugin-core/tests/createServerFn/serverFnAst.test.tsIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
📝 Walkthrough
Walkthrough#
The server-function compiler now builds generated RPC calls, provider wrappers, imports, directives, exports, and HMR statements with AST helpers. New compiler and production-build benchmark harnesses record timing, memory, output comparisons, and bundle hashes. Tests cover generated output across frameworks and runtimes.
Changes#
Server-function AST generation and benchmarking
packages/start-plugin-core/src/start-compiler/serverFnAst.ts,packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts,packages/start-plugin-core/tests/createServerFn/*ast.test.ts,.changeset/fuzzy-berries-behave.mdbenchmarks/compiler/server-fn-ast.mjs,benchmarks/compiler/README.md,benchmarks/compiler/direct-ast.md,benchmarks/compiler/results/direct-ast-*.jsonbenchmarks/compiler/server-fn-build.mjs,benchmarks/compiler/direct-ast.md,benchmarks/compiler/results/direct-ast-app-output.json,benchmarks/compiler/results/direct-ast-builds.json,benchmarks/compiler/results/direct-ast-heavy-builds-*.json,benchmarks/compiler/results/direct-ast-bundle-*-hashes.json,benchmarks/compiler/results/direct-ast-hunk-bundles.jsonPriority: ➖ Normal
Estimated code review effort: 4 (Complex) | ~45 minutes
Merge Risk: ⚪ Minimal · up to
c6c33The server-function AST change has no identified issue that needs resolution before merging; normal checks remain appropriate.
Security Architecture Review#
Security architecture risk: 🔵 Low · up to
c6c33The change affects how server-function code is generated, not an identified authorization rule or deployment boundary. Tests and recorded build comparisons support equivalent output, but they do not establish equivalence for every application.
Retained concerns No architecture-level concerns identified.
Security review details
Security Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 6 files. (30 skipped: 30 unsupported.)
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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