Skip to content

perf(start-plugin-core): speed up rsbuild client build normalization - #1

Closed
guru-irl wants to merge 10 commits into
mainfrom
perf/rsbuild-client-build-capture
Closed

guru-irl wants to merge 10 commits into
mainfrom
perf/rsbuild-client-build-capture

Conversation

@guru-irl

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

Copy link
Copy Markdown
Owner

🎯 Changes

normalizeRspackClientBuild converts the Rspack client compilation into the data used to build the Start manifest. It runs on every Rsbuild build and on every dev rebuild. This PR makes it faster for builds with many chunks. The output does not change.

  • Chunk and chunk group properties (files, auxiliaryFiles, groupsIterable, chunks, childrenIterable) are now read once per call. Rspack builds a new collection on every read, and the previous code read them many times per chunk.
  • Modules are now read only from chunks that contain a route-split or hydration module. The previous code called getChunkModules for every chunk.

Benchmarks

Median of 21 runs of normalizeRspackClientBuild on generated apps, Rspack 2.2.3, production unless noted:

App Chunks Chunk groups main This PR Speedup
Routes and shared vendor chunks 760 481 61.1 ms 14.3 ms 4.3x
Large 2,456 901 131.8 ms 36.5 ms 3.6x
Large (development) 2,456 901 138.6 ms 37.3 ms 3.7x
Shared modules in route chunks 1,397 901 97.0 ms 39.4 ms 2.5x
Many non-route async chunks 3,245 3,101 235.1 ms 53.4 ms 4.4x

For each app, the output was compared with main on Rspack 2.0.0, 2.1.1 and 2.2.3 and was identical.

Tests

  • New unit tests in normalized-client-build.test.ts use a small fake chunk graph. They check that:
    • imports and dynamic imports are listed in the same order as before (this test also passes on main);
    • modules are read only from chunks with a route-split or hydration module;
    • each chunk and chunk group property is read at most once.
  • @tanstack/start-plugin-core test:unit, test:types and test:eslint pass.
  • These Rsbuild e2e suites pass:
    • react-start rsbuild, rsc-rsbuild and hmr
    • deferred-hydration (production and dev)
    • solid-start deferred-hydration
    • css-inline, with and without transform assets

✅ 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).

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

🚀 Changeset Version Preview

4 package(s) bumped directly, 10 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/react-router 1.170.41 → 1.170.42 Changeset
@tanstack/solid-router 1.170.38 → 1.170.39 Changeset
@tanstack/start-plugin-core 1.171.49 → 1.171.50 Changeset
@tanstack/vue-router 1.170.37 → 1.170.38 Changeset
@tanstack/react-start 1.168.60 → 1.168.61 Dependent
@tanstack/react-start-client 1.168.39 → 1.168.40 Dependent
@tanstack/react-start-rsc 0.1.59 → 0.1.60 Dependent
@tanstack/react-start-server 1.167.46 → 1.167.47 Dependent
@tanstack/solid-start 1.168.57 → 1.168.58 Dependent
@tanstack/solid-start-client 1.168.37 → 1.168.38 Dependent
@tanstack/solid-start-server 1.167.44 → 1.167.45 Dependent
@tanstack/vue-start 1.168.56 → 1.168.57 Dependent
@tanstack/vue-start-client 1.167.40 → 1.167.41 Dependent
@tanstack/vue-start-server 1.167.44 → 1.167.45 Dependent

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Bundle Size Benchmarks

  • Commit: 344913531342
  • Measured at: 2026-10-02T07:41:09.575Z
  • Baseline source: history:d6decca41807
  • Dashboard: bundle-size history

The following scenarios have bundle-size changes or lack baseline data for comparison:

Scenario Current (gzip) Initial (gzip) Raw Brotli Trend
react-router.minimal 84.0 KiB
-3.4 KiB
83.8 KiB
n/a
261.4 KiB
-13.3 KiB
73.2 KiB
-2.7 KiB
███████████▁
react-router.full 87.5 KiB
-3.3 KiB
87.4 KiB
n/a
273.3 KiB
-12.9 KiB
76.3 KiB
-2.7 KiB
███████████▁
solid-router.minimal 33.5 KiB
-2.0 KiB
33.4 KiB
n/a
96.0 KiB
-10.9 KiB
30.4 KiB
-1.6 KiB
███████████▁
solid-router.full 38.4 KiB
-1.9 KiB
38.3 KiB
n/a
110.8 KiB
-10.4 KiB
34.6 KiB
-1.5 KiB
███████████▁
vue-router.minimal 49.4 KiB
-3.9 KiB
49.3 KiB
n/a
136.8 KiB
-15.3 KiB
44.7 KiB
-3.2 KiB
███████████▁
vue-router.full 55.0 KiB
-3.4 KiB
54.9 KiB
n/a
155.1 KiB
-13.2 KiB
49.7 KiB
-2.6 KiB
███████████▁
react-start.minimal 96.8 KiB
-5.1 KiB
96.7 KiB
n/a
302.4 KiB
-20.5 KiB
84.0 KiB
-4.0 KiB
███████████▁
react-start.query-integration 104.2 KiB
n/a
104.1 KiB
n/a
329.0 KiB
n/a
90.5 KiB
n/a
▅
react-start.deferred-hydration 97.5 KiB
n/a
96.7 KiB
n/a
303.7 KiB
n/a
84.7 KiB
n/a
▅
react-start.full 99.9 KiB
-5.4 KiB
99.8 KiB
n/a
312.1 KiB
-21.1 KiB
86.8 KiB
-4.2 KiB
███████████▁
react-start.rsbuild.minimal 100.3 KiB
-1.1 KiB
100.2 KiB
n/a
313.4 KiB
-12.4 KiB
86.5 KiB
-649 B
███████████▁
react-start.rsbuild.minimal-iife 100.7 KiB
n/a
100.6 KiB
n/a
314.4 KiB
n/a
86.9 KiB
n/a
▅
react-start.rsbuild.full 103.6 KiB
-1.2 KiB
103.4 KiB
n/a
323.5 KiB
-12.9 KiB
89.3 KiB
-550 B
███████████▁
solid-start.minimal 46.4 KiB
-3.2 KiB
46.3 KiB
n/a
135.8 KiB
-17.0 KiB
41.3 KiB
-2.3 KiB
███████████▁
solid-start.deferred-hydration 49.4 KiB
n/a
46.3 KiB
n/a
143.2 KiB
n/a
44.0 KiB
n/a
▅
solid-start.full 51.5 KiB
-3.9 KiB
51.3 KiB
n/a
151.2 KiB
-18.5 KiB
45.6 KiB
-3.1 KiB
███████████▁
vue-start.minimal 65.5 KiB
n/a
65.4 KiB
n/a
186.2 KiB
n/a
58.4 KiB
n/a
▅
vue-start.full 69.3 KiB
n/a
69.2 KiB
n/a
198.6 KiB
n/a
61.8 KiB
n/a
▅

Current gzip tracks all emitted client JS chunks. Initial gzip tracks only the entry/import graph. Trend sparkline is historical current gzip ending with this PR measurement; lower is better.

Remove the real Rspack compile fixture, its helper and snapshots. Cover the
same behavior in the existing normalized-client-build unit tests with a small
fake chunk graph: output order of imports and dynamic imports, module reads
only for route-split and hydration chunks, and one read per chunk graph
property.
…eader

Clarify comments on the chunk scan and read helpers, read child groups
directly since their merged JS files are already cached per group, keep the
unrelated isManifestJsAsset line unchanged, and assert the set of chunks whose
modules are read.
@guru-irl

Copy link
Copy Markdown
Owner Author

Raised upstream as TanStack#8588.

@guru-irl guru-irl closed this Oct 17, 2026
guru-irl pushed a commit that referenced this pull request Nov 11, 2026
… over HTTP, deprecate the rest outside the unreserved set (TanStack#8858)

* refactor(start-plugin-core): derive server-fn ids from the stable key, with 22-character defaults

`serverFns.generateFunctionId` now receives the server function's
stable name (`greetUser`) as `functionName` instead of the generated
handler name (`greetUser_createServerFn_handler`). Repeats of the same
variable name in one file get `#1`, `#2`, ...

Default production ids are the first 22 base64url characters of the
SHA256 of `<file>#<stable key>` instead of the full 64-character hex
digest.

Split out of TanStack#8817, which derives ids the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(start-plugin-core): keep generateFunctionId's handler-name input, reject custom ids that aren't one URL path segment

Follows TanStack#8817's current id contract:

- `generateFunctionId` receives the generated handler name again
  (`greetUser_createServerFn_handler`, `_1`, `_2`… for repeats), with
  characters outside `[A-Za-z0-9_$]` as `_`. The handler export keeps its
  name.
- The default id stays 22 base64url characters of
  `sha256("<root-relative file>#<variable name>")`, `#n` for repeats.
- A custom id outside RFC 3986's unreserved characters and `$` (or `.`,
  `..`, empty) fails the build, naming the file, the function and the id.
- The e2e id maps return to main's keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(start-plugin-core): a repeated server function name loses leading and doubled underscores

The generator's `functionName` for a repeated name goes through the old
increment rule, which strips leading underscores and collapses runs of
underscores (a second `_x` gets `x_createServerFn_handler_1`). Say so,
and pin it with `_x` twice and `café` then `caf_`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(start-plugin-core): names that become equal after the `_` replacement get suffixes too

`café` and `caf_` both give `caf__createServerFn_handler`, so the later
one gets `caf_createServerFn_handler_1`, like a repeated variable name.
Describe the replacement first, then the suffix rule for any resulting
duplicate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(start-plugin-core): keep main's server-fn ids; refuse custom ids that never worked over HTTP

TanStack#8817 now prints main's default ids and passes main's functionName to
generateFunctionId, so this reverts the shorter default ids, the
generator-name split and the empty-id failure. What stays is TanStack#8817's
custom-id check: an id the URL never carries whole fails the build, one
with other characters outside the unreserved set and $ builds with a
deprecation warning, and the resolver manifest escapes a `'` in an id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant