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.
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):
- 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
Scope
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:
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
- Build once with the option disabled and keep the
distdirectory. - Build once with the option enabled and compare the two
distdirectories, in particular theserveroutput underdist/bundles. The contents should be the same. - 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.