xtask/benchmark/README.md
Rust benchmark cases live in xtask/benchmark/cases and xtask/benchmark/stages.
The rspack_sources benchmarks live in their own rspack_sources benchmark
target so CodSpeed builds and runs them in a separate binary, isolated from the
allocator state left behind by the larger compilation benchmark suite.
Some benchmark cases use fixtures from .bench/rspack-benchcases. Prepare them before running the full benchmark suite or any bundle-related case:
pnpm run bench:prepare
The CI command runs cargo codspeed run directly:
pnpm run bench:rust
When this command is run outside a CodSpeed runner environment, cargo-codspeed may only check benchmarks and print Checked: entries instead of making CPU simulation measurements.
Use the build helper to run the same CodSpeed build command used by CI:
pnpm run build:bench
The script expands to:
cargo codspeed build -m simulation --profile codspeed -p rspack_benchmark --bench benches --bench rspack_sources
This only builds the benchmark binaries for CodSpeed simulation mode. It does not execute measurements. Both benchmark targets are selected in a single cargo codspeed build invocation so the later cargo codspeed run step can collect both benchmark suites.
To build only the isolated rspack_sources target:
pnpm run build:bench:rspack-sources
Use the local helper script to run benchmarks through the CodSpeed runner in CPU simulation mode:
pnpm run bench:rust:local
Pass a benchmark name filter after -- to run a single benchmark:
pnpm run bench:rust:local -- build_chunk_graph
To run only the isolated rspack_sources binary:
pnpm run bench:rust:local -- --bench rspack_sources
The script expands to:
mkdir -p /tmp/rspack-codspeed-valgrind-tmp && TMPDIR=/tmp/rspack-codspeed-valgrind-tmp RAYON_NUM_THREADS=1 RSPACK_BENCHCASES_DIR=$PWD/.bench/rspack-benchcases codspeed run -m simulation -- cargo codspeed run -m simulation
This command:
TMPDIR so the temporary files are written to that directoryRAYON_NUM_THREADS=1 to match the single-threaded CI simulation environmentRSPACK_BENCHCASES_DIR to the prepared benchmark fixturescargo codspeed run -m simulation in codspeed run -m simulation so local runs use the CodSpeed runner environment instead of only checking benchmarksA real local simulation run prints Measured: entries. The script sets TMPDIR to /tmp/rspack-codspeed-valgrind-tmp, so CodSpeed and Valgrind temporary files are easy to inspect:
find /tmp/rspack-codspeed-valgrind-tmp -maxdepth 3 -type f
Typical files include profile.*.out/valgrind.log, profile.*.out/runner.log, and vgdb-pipe-* files.
Local CPU simulation requires:
cargo-codspeedcodspeedCheck the installed tools with:
cargo codspeed --version
codspeed --version
valgrind --version