In this section, we'll explore how to profile Rspack for identifying bottlenecks. By examining where Rspack spends its time, we can gain insights into how to improve performance. Since different profilers have different strengths. It is good to use more than one.
Performance analysis should be conducted on a release version that includes debug information. This approach ensures accurate performance results while providing sufficient debug information for analysis. Use the following command to profiling using local build rspack.
pnpm build:binding:profiling@rspack/core and @rspack/cli to use link protocol to link to local build Rspack: dependencies: {
- "@rspack/core": "x.y.z",
- "@rspack/cli": "x.y.z",
# link protocol only works in pnpm
+ "@rspack/core": "link:{your_rspack_repo}/packages/rspack",
+ "@rspack/cli": "link:{your_rspack_repo}/packages/rspack-cli"
}pnpm installSamply supports performance analysis for both Rust and JavaScript simultaneously. Follow these steps to perform a complete performance analysis:
samply record -- node --perf-prof --perf-basic-prof --interpreted-frames-native-stack {your_rspack_folder}/rspack-cli/bin/rspack.js -c {your project}/rspack.config.js
Node.js currently only supports --perf-prof on Linux platforms. JavaScript profiling in Samply depends on --perf-prof support. If you need to use Samply for JavaScript profiling on other platforms, consider using Docker for profiling, or you can compile Node.js yourself for macOS using node-perf-maps for profiling purposes.
Rspack’s JavaScript typically runs in the Node.js thread. Select the Node.js thread to view the time distribution on the Node.js side.

Rspack’s Rust code usually runs in the tokio thread. Select the tokio thread to view the time distribution on the Rust side.

If we want to analyze the time cost of loaders and plugins or the compilation behavior of loaders, we can use Rsdoctor to view:

Refer to Rsdoctor Compilation Analysis
Xcode instruments can be used to produce a CPU profile if you are on a Mac.
To install Xcode Instruments, simply install the Command Line Tools:
xcode-select --installFor normal Rust builds, cargo instruments can be used as the glue
for profiling and creating the trace file.
Since Rspack takes quite a while to build, you can use the following procedure without invoking cargo instruments.
It has the same effect.
In workspace root's Cargo.toml, turn on debug symbols and disable symbol stripping in the [profile.release] section
[profile.release]
debug = 1 # debug info with line tables only
strip = false # do not strip symbolsThen build the project
pnpm run build:cli:releaseThe final binary is located at packages/rspack-cli/bin/rspack once the project is built.
Under the hood, cargo instruments invokes the xcrun command,
which means we can run the following in our own project that uses Rspack.
xcrun xctrace record --template 'Time Profile' --output . --launch -- /path/to/rspack/packages/rspack-cli/bin/rspack buildIt produces the following output
Starting recording with the Time Profiler template. Launching process: rspack.
Ctrl-C to stop the recording
Target app exited, ending recording...
Recording completed. Saving output file...
Output file saved as: Launch_rspack_2023-04-24_11.32.06_9CFE3A63.traceWe can open the trace file by
open Launch_rspack_2023-04-24_11.32.06_9CFE3A63.trace