Running a performance analysis helps you identify bottlenecks in your project so you can optimize the right areas.
Rsdoctor is a build analyzer that visualizes how long each loader and plugin takes to compile.
See Use Rsdoctor for more information.
A build runs both JavaScript and Rust code and incurs communication overhead between them.
JavaScript overhead is usually higher than Rust overhead. Use Node.js profiling to understand where time is spent in JavaScript and pinpoint bottlenecks.
For example, to capture a CPU profile, run the following commands from your project root:
# dev
node --cpu-prof ./node_modules/@rsbuild/core/bin/rsbuild.js dev
# build
node --cpu-prof ./node_modules/@rsbuild/core/bin/rsbuild.js build
# Set higher precision sampling interval
node --cpu-prof --cpu-prof-interval=100 ./node_modules/@rsbuild/core/bin/rsbuild.js buildThese commands generate a *.cpuprofile file. You can use speedscope to visualize it:
# Install speedscope
npm install -g speedscope
# View cpuprofile content
# Replace the name with the local file name
speedscope CPU.date.000000.00000.0.001.cpuprofileSet the RSPACK_PROFILE environment variable to capture an Rspack build performance profile.
{
"scripts": {
"dev:profile": "RSPACK_PROFILE=OVERVIEW rsbuild dev",
"build:profile": "RSPACK_PROFILE=OVERVIEW rsbuild build"
}
}Because Windows does not support this syntax, you can use cross-env to set environment variables across different systems:
{
"scripts": {
"dev:profile": "cross-env RSPACK_PROFILE=OVERVIEW rsbuild dev",
"build:profile": "cross-env RSPACK_PROFILE=OVERVIEW rsbuild build"
},
"devDependencies": {
"cross-env": "^7.0.0"
}
}After the build finishes or the dev server stops, Rsbuild creates a .rspack-profile-${timestamp}-${pid} folder in the current directory. It contains a rspack.pftrace file (in versions before 1.4.0, the file name was trace.json) generated by Rspack using tracing. The file records the time spent in each phase and can be viewed with ui.perfetto.dev.
CTRL + D instead of CTRL + C so Rspack can finish recording performance data.trace.json file can be large. Compress it into a zip file before sharing.