Build Profiling

Performing a performance analysis can help you identify performance bottlenecks in your project, allowing for targeted optimization.

Using Rsdoctor

Rsdoctor is a build analyser that can visually display the compilation time of each loaders and plugins.

Please refer to Use Rsdoctor for more information.

Rspack Profiling

Rspeedy supports the use of the RSPACK_PROFILE environment variable for Rspack build performance profile.

package.json
{
  "scripts": {
    "dev:profile": "RSPACK_PROFILE=OVERVIEW rspeedy dev",
    "build:profile": "RSPACK_PROFILE=OVERVIEW rspeedy build"
  }
}

This command will generate a .rspack-profile-${timestamp}-${pid} folder in the current directory, containing a trace.json file, which is generated by Rspack based on tracing and records the time spent on each phase at a granular level, and can be viewed using ui.perfetto.dev.

For more information about Rspack build performance analysis usage, please refer to Rspack - Tracing.

Node.js Profiling

In general, the performance overhead on the JS side will be greater than that on the Rust side, and you can use Node.js profiling to analyze the overhead on the JS side.

Run the following command in the project root:

# dev
node --cpu-prof ./node_modules/@lynx-js/rspeedy/bin/rspeedy dev

# build
node --cpu-prof ./node_modules/@lynx-js/rspeedy/bin/rspeedy build

The above commands will generate a cpuprofile file. We can use speedscope to visualize this file:

# Install speedscope
npm install -g speedscope

# View cpuprofile content
# Replace the name with the local file name
speedscope CPU.date.000000.00000.0.001.cpuprofile