For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /configure/app/performance/parallel-build.md.

performance.parallelBuild

  • Type: boolean
  • Default: false
  • Status: experimental

Whether to compile the server build environment in a worker process during production builds. It applies to every application whose build has a server environment, which means SSR (server.ssr, server.ssrByEntries) and SSG (output.ssg, output.ssgByEntries).

By default the client and server environments are compiled by two Rspack compilers inside one Node.js process. They share one main thread and one V8 heap, so JavaScript loaders, plugin hooks and garbage collection of one compiler stall the other. With this option the main process compiles the client and a worker process compiles the server at the same time. Planning (entries, routes, generated code) and everything after the compile (server/ and api/ compilation, SSG, deploy) still run once, in the main process, and the output is identical to a regular build.

modern.config.ts
export default defineConfig({
  performance: {
    parallelBuild: true,
  },
});

When to enable it

The gain comes from JavaScript work on the main thread, then from the number of modules. Measured on generated applications that have a server environment (SSR is used as the example) (module count per compiler, median of several runs, 64-core machine):

ApplicationModulesRegular buildParallel buildTimePeak memory
Default toolchain2.6k10.3 s9.8 s-5%-9%
Default toolchain5k17.9 s16.8 s-6%-12%
Default toolchain10k31.6 s29.4 s-7%-14%
Default toolchain20k62.4 s57.5 s-8%-18%
Default toolchain40k144.5 s137.9 s-5%-6%
Default toolchain60k255.0 s244.4 s-4%0%
With a JavaScript loader on every module5k33.1 s25.0 s-24%-10%
With a JavaScript loader on every module10k61.0 s44.9 s-26%-15%
With a JavaScript loader on every module20k120.5 s85.6 s-29%-7%
With a JavaScript loader on every module40k262.3 s192.9 s-26%-16%
  • Enable it when a production build takes longer than about 30 seconds and the project uses JavaScript loaders or Rspack plugins written in JavaScript (Babel, custom instrumentation, code generation): the build gets about a quarter faster.
  • With the default toolchain only, the time gain stays in single digits (4% to 8%). Peak memory drops by 9% to 18% up to 20k modules; the drop narrows beyond that and is gone at 60k modules.
  • For small applications that build in a few seconds the difference is within noise; leave it off.

What runs in which process

StepProcess
Loading the configuration, entries, routes, generated entry codeMain, once. The worker loads the configuration again but takes entries and routes from the main process
Rspack compile of the client environment (browser bundles, HTML, static assets)Main
Rspack compile of the server environment (the Node.js bundles under dist/bundles: server render bundles and server data loaders)Worker
Compilation of the server/ directory (custom web server) and the api/ directory (BFF)Main, once
SSG prerendering, route.json, deploy outputMain, once

Scope

ApplicationBehaviour with the option on
SSR, including partial SSR with server.ssrByEntriesserver environment compiled in the worker
SSGserver environment compiled in the worker; prerendering stays in the main process
CSR only, with or without BFF or a custom web serverNo server environment; single process
RSC (server.rsc)Not supported; single process
Worker SSR (deploy.worker.ssr)A third environment is involved; single process

The option only affects build and deploy. dev, --watch, --analyze and builds with Rsdoctor enabled use the single process.

Notes

The worker process loads the configuration and sets up plugins again, because functions in the build configuration cannot be sent to another process. Custom plugins in the project, and any logic written in lifecycle hooks, run as follows:

HookMain processWorker process
config, modifyResolvedConfig, onPrepare, the hooks that modify the build configuration (modifyBundlerChain, modifyRsbuildConfig, modifyRspackConfig), onBeforeCreateCompiler, onAfterCreateCompiler, and the Rsbuild plugins in builderPluginsRunsRuns
modifyServerRoutes and the other hooks that compute entries and routesRunsDoes not run; the result of the main process is used
onBeforeBuild, onAfterBuild and the deploy hooksRunsDoes not run

Logic that only modifies the configuration is not affected. Errors and warnings of the server compile are printed by the worker with a [server] prefix, and a failure there fails the build.

Checking that a project can enable it

  1. Build once with the option disabled and keep the dist directory.
  2. Build once with the option enabled and compare the two dist directories, in particular the server output under dist/bundles. The contents should be the same.
  3. Read the log of the build with the option enabled: check whether the project's own reporting, file writes or summaries appear twice, once with the [server] prefix.

If the output is the same and nothing runs twice, the option can be enabled.

Common problems and fixes

ProblemSymptomFix
A hook that runs in both processes does something that should happen once, such as reporting, writing a file or sending a requestThe logic runs twice, without an errorMove it to onBeforeBuild or onAfterBuild
onBeforeBuild reads the bundlerConfigs of the server environment, or onAfterBuild reads its statsBoth arguments cover the client environment only; the server part is undefinedRead the resolved app config through api.getNormalizedConfig() instead, or move the logic to a hook that modifies the build configuration, such as modifyRspackConfig
A variable in a plugin instance or closure passes data between the client and server compilesEach process has its own state, so the server compile cannot read a value written in the main process; there is no errorLet each compile derive the data from the configuration or from a file; keep the option disabled if that is not possible
A part of the configuration that both compiles must agree on (source.define, source.globalVars, output paths, SSR settings, entries) evaluates differently in the two processes, for example when it depends on Date.now() or a random valueThe build fails with The configuration evaluated differently in the build worker and lists the fields that differMake the value deterministic, for example by reading it from an environment variable