|
| 1 | +# Rspack Rust benchmarks |
| 2 | + |
| 3 | +Rust benchmark cases live in `xtask/benchmark/cases` and `xtask/benchmark/stages`. |
| 4 | + |
| 5 | +## Prepare benchmark fixtures |
| 6 | + |
| 7 | +Some benchmark cases use fixtures from `.bench/rspack-benchcases`. Prepare them before running the full benchmark suite or any bundle-related case: |
| 8 | + |
| 9 | +```bash |
| 10 | +pnpm run bench:prepare |
| 11 | +``` |
| 12 | + |
| 13 | +## Run in CI mode |
| 14 | + |
| 15 | +The CI command runs `cargo codspeed run` directly: |
| 16 | + |
| 17 | +```bash |
| 18 | +pnpm run bench:rust |
| 19 | +``` |
| 20 | + |
| 21 | +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. |
| 22 | + |
| 23 | +## Build benchmark binaries |
| 24 | + |
| 25 | +Use the build helper to run the same CodSpeed build command used by CI: |
| 26 | + |
| 27 | +```bash |
| 28 | +npm run build:bench |
| 29 | +``` |
| 30 | + |
| 31 | +The script expands to: |
| 32 | + |
| 33 | +```bash |
| 34 | +cargo codspeed build -m simulation --profile codspeed -p rspack_benchmark |
| 35 | +``` |
| 36 | + |
| 37 | +This only builds the benchmark binaries for CodSpeed simulation mode. It does not execute measurements. |
| 38 | + |
| 39 | +## Run local CPU simulation measurements |
| 40 | + |
| 41 | +Use the local helper script to run benchmarks through the CodSpeed runner in CPU simulation mode: |
| 42 | + |
| 43 | +```bash |
| 44 | +npm run bench:rust:local |
| 45 | +``` |
| 46 | + |
| 47 | +Pass a benchmark name filter after `--` to run a single benchmark: |
| 48 | + |
| 49 | +```bash |
| 50 | +npm run bench:rust:local -- build_chunk_graph |
| 51 | +``` |
| 52 | + |
| 53 | +The script expands to: |
| 54 | + |
| 55 | +```bash |
| 56 | +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 |
| 57 | +``` |
| 58 | + |
| 59 | +This command: |
| 60 | + |
| 61 | +- Creates a stable temporary directory for CodSpeed and Valgrind files |
| 62 | +- Sets `TMPDIR` so the temporary files are written to that directory |
| 63 | +- Sets `RAYON_NUM_THREADS=1` to match the single-threaded CI simulation environment |
| 64 | +- Sets `RSPACK_BENCHCASES_DIR` to the prepared benchmark fixtures |
| 65 | +- Wraps `cargo codspeed run -m simulation` in `codspeed run -m simulation` so local runs use the CodSpeed runner environment instead of only checking benchmarks |
| 66 | + |
| 67 | +A 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: |
| 68 | + |
| 69 | +```bash |
| 70 | +find /tmp/rspack-codspeed-valgrind-tmp -maxdepth 3 -type f |
| 71 | +``` |
| 72 | + |
| 73 | +Typical files include `profile.*.out/valgrind.log`, `profile.*.out/runner.log`, and `vgdb-pipe-*` files. |
| 74 | + |
| 75 | +## Requirements |
| 76 | + |
| 77 | +Local CPU simulation requires: |
| 78 | + |
| 79 | +- `cargo-codspeed` |
| 80 | +- `codspeed` |
| 81 | +- CodSpeed's Valgrind build |
| 82 | + |
| 83 | +Check the installed tools with: |
| 84 | + |
| 85 | +```bash |
| 86 | +cargo codspeed --version |
| 87 | +codspeed --version |
| 88 | +valgrind --version |
| 89 | +``` |
0 commit comments