perf(start-plugin-core): avoid repeated work in Rsbuild compilation scans #8799
main fromrefs/pull/8799/head·opened 🎯 Changes#
Two passes that run on every Rsbuild compilation did avoidable work.
Client build normalization scanned each chunk's modules twice, once for tsr-split and once for tss-hydrate, calling the native identifier() each time. It now reads both in one scan. The literal-key guards stay separate, so encoded keys and first-value semantics are unchanged; new tests cover repeated, empty, +-encoded and percent-encoded keys, lookalike keys, and concatenation on and off.
Server function metadata replay (finishMake, stage -20) ran serverFnBuildInfoSchema.safeParse on every module's buildInfo, although almost no modules have the field. It now returns early when the field is absent, which was already the result.
| Measurement | Before | After |
|---|---|---|
| Metadata replay, 1,665-module dev compilation | 5.7 ms | 1.0 ms |
| Normalization, 128 routes, with hydration metadata | — | ~4% lower |
| Normalization, 128 routes, route split only | — | within noise |
Normalization numbers are from the new tests/rsbuild/normalized-client-build.bench.ts (real Rspack compilations, 8 and 128 routes, concatenation on and off), same fixture before and after. Client bundle output is unchanged.
Overlap with open PRs#
Both halves overlap older open PRs, and I'd rather those land:
- #8305 contains the same
readServerFnBuildInfoearly return. Prefer #8305: it's older and covers Zod work beyond this one function. If it merges first, I'll drop thestart-compiler-host.tschange from this PR. If this merges first, #8305's rebase drops its identical hunk. - #8588 goes further on normalization: it finds route and hydration chunks with one pass over all modules, reads modules only from those chunks, and caches chunk-graph reads (2.5–4.4× on 760–3,245-chunk apps per its description). Prefer #8588, but it predates #8695 and needs porting to the new static-dependency code. If it merges first, I'll rebase this onto it and keep the single scan only if it still measures faster inside the chunks #8588 reads; otherwise I'll close this. If this merges first, #8588 can call
getChunkMetadataFromModulesin place of its two extractors.
So this PR is the small, low-risk fallback if those stay stalled; happy to close it once they move.
Written with an AI coding assistant.
✅ 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#
- Bug Fixes
- Improved Rsbuild compilation handling for modules without server function metadata. Existing metadata continues to be validated, and invalid metadata is still rejected.
- 1
Important
Review skipped#
Review was skipped as selected files did not have any reviewable changes.
Run configuration-
- Source mode: Auto
- Repository: TanStack/router
- Branch: main
- File: .coderabbit.yaml
- Commit: f723f3b
- Layers: Repository YAML
- Review profile: CHILL
- Plan: Advanced
- Run ID:
dfceb235-c6c2-49ad-9712-a2343f3b909b
Commits-
Reviewing files that changed from the base of the PR and between b277e7b242909a6b23fbf8fd01e8f7ddccc42dbf and d262370b803c2df5ee794b866072d2406fd9b9b0.
You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- Trigger review
No actionable comments were generated in the recent review.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: TanStack/router
- Branch: main
- File: .coderabbit.yaml
- Commit: da2adec
- Layers: Repository YAML
- Review profile: CHILL
- Plan: Advanced
- Run ID:
aaf96738-59e4-4b0c-80cc-38090e120f8a
Commits-
Reviewing files that changed from the base of the PR and between da2adec76dbe6c0da6d6a0d5640f7b9388217f45 and b277e7b242909a6b23fbf8fd01e8f7ddccc42dbf.
Files selected for processing: 2-
.changeset/rsbuild-cheaper-compilation-scans.mdpackages/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
-
readServerFnBuildInfonow returnsnullbefore schema validation when server function metadata is absent. Present metadata continues to use the existing schema validation. A changeset requests a patch release for@tanstack/start-plugin-core.Changes: Rsbuild metadata handling
Layer / File(s) Summary Skip validation when metadata is absent
packages/start-plugin-core/src/rsbuild/start-compiler-host.ts,.changeset/rsbuild-cheaper-compilation-scans.mdreadServerFnBuildInfochecks for undefined metadata before schema validation. The changeset requests a patch release and describes this update.Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Refactor
Possibly related issues
- TanStack/router issue 8810 — It tracks build-time speed work that includes skipping schema parsing for modules without server-function metadata.
Suggested labels:
package: start-plugin-coreSuggested reviewers:
schiller-manuel
Merge Risk:
Minimal · previous reviewb277e-
No actionable merge-blocking risk is identified in the supplied changes.
Pre-merge checks:
4 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Docstring Coverage Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold. Passed checks: 4 passed-
Check name Status Explanation Title check The title clearly identifies an Rsbuild performance change. It is broad because the current summary mainly covers avoiding unnecessary server-function metadata validation, but it remains related to th… Description check The description includes the required Changes, Checklist, and Release Impact sections. It explains the motivation, implementation, measurements, overlap with other pull requests, testing, AI assistanc… Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Full details: Title check
-
Explanation
The title clearly identifies an Rsbuild performance change. It is broad because the current summary mainly covers avoiding unnecessary server-function metadata validation, but it remains related to the pull request objective.
Full details: Description check
-
Explanation
The description includes the required Changes, Checklist, and Release Impact sections. It explains the motivation, implementation, measurements, overlap with other pull requests, testing, AI assistance, and changeset. One understanding-code checklist item remains unchecked, but the description is otherwise complete.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
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.
-
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: d262370b803c2df5ee794b866072d2406fd9b9b0
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 5 packages
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