Skip to content

Commit f83f2f5

Browse files
authored
chore: add local rust benchmark script (#14007)
1 parent fd9b3d8 commit f83f2f5

5 files changed

Lines changed: 112 additions & 4 deletions

File tree

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"build:binding:ci": "pnpm --filter @rspack/binding run build:ci",
3939
"build:binding:release": "pnpm --filter @rspack/binding run build:release",
4040
"build:binding:profiling": "pnpm --filter @rspack/binding run build:profiling",
41+
"build:bench": "cargo codspeed build -m simulation --profile codspeed -p rspack_benchmark",
4142
"prepare": "is-ci || husky",
4243
"test:hot": "pnpm --filter \"@rspack/*\" test:hot",
4344
"test:unit": "pnpm --parallel --filter \"@rspack/*\" test",
@@ -48,6 +49,7 @@
4849
"test:rs": "cargo test --workspace --exclude rspack_binding_api --exclude rspack_node --exclude rspack_binding_builder --exclude rspack_binding_builder_macros --exclude rspack_binding_builder_testing --exclude rspack_binding_build --exclude rspack_napi --exclude rspack_watcher -- --nocapture",
4950
"bench:ci": "pnpm run bench:prepare && pnpm run bench:rust && pnpm --filter bench run bench",
5051
"bench:rust": "RSPACK_BENCHCASES_DIR=$PWD/.bench/rspack-benchcases cargo codspeed run",
52+
"bench:rust:local": "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",
5153
"bench:prepare": "node ./scripts/bench/setup.mjs"
5254
},
5355
"engines": {

website/docs/en/contribute/development/project.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,17 @@ End-to-end tests for Rspack, covering real-world scenarios and integration testi
214214
- **`fixtures/`**: Shared fixtures and utilities for E2E tests
215215
- **`utils/`**: Utility functions for E2E test execution
216216

217-
### Benchmarks (`bench/`)
217+
### JavaScript benchmarks (`bench/`)
218218

219219
Performance benchmarks for tracking Rspack JavaScript API performance and preventing performance degradation:
220220

221221
- **`fixtures/`**: Benchmark test fixtures (e.g., `ts-react` project for benchmarking)
222222
- Benchmark files for measuring build performance and API execution time
223+
224+
### Rust benchmarks (`xtask/benchmark/`)
225+
226+
CodSpeed benchmarks for tracking Rust compilation pipeline performance:
227+
228+
- **`cases/`**: End-to-end benchmark cases for module graph, chunk graph, bundling, scanning dependencies, and persistent cache
229+
- **`stages/`**: Focused benchmark cases for individual compilation stages
230+
- See **`xtask/benchmark/README.md`** for local CodSpeed CPU simulation commands and Valgrind temporary file locations

website/docs/zh/contribute/development/project.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,17 @@ Rspack 的端到端测试,涵盖真实场景和集成测试:
214214
- **`fixtures/`**: E2E 测试的共享 fixtures 和工具
215215
- **`utils/`**: E2E 测试执行的工具函数
216216

217-
### 基准测试 (`bench/`)
217+
### JavaScript 基准测试 (`bench/`)
218218

219219
用于跟踪 Rspack JavaScript API 性能并防止性能退化的性能基准测试:
220220

221221
- **`fixtures/`**: 基准测试 fixtures(例如,用于基准测试的 `ts-react` 项目)
222222
- 用于测量构建性能和 API 执行时间的基准测试文件
223+
224+
### Rust 基准测试 (`xtask/benchmark/`)
225+
226+
用于跟踪 Rust 编译流水线性能的 CodSpeed 基准测试:
227+
228+
- **`cases/`**: 针对 module graph、chunk graph、bundling、依赖扫描和 persistent cache 的端到端基准测试用例
229+
- **`stages/`**: 针对单个 compilation stage 的基准测试用例
230+
- 请参考 **`xtask/benchmark/README.md`** 了解本地 CodSpeed CPU simulation 命令和 Valgrind 临时文件位置

website/project-words.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ memfs
9494
mimalloc
9595
minifiers
9696
miro
97-
MPHF
9897
modulegeneratorassetdataurl
9998
modulegeneratorassetdataurlencoding
10099
modulegeneratorassetdataurlmimetype
@@ -111,6 +110,7 @@ moduleparsercssauto
111110
moduleparsercssautonamedexports
112111
moduleparsercssmodule
113112
monaco
113+
MPHF
114114
msvc
115115
myorg
116116
myrspackapp
@@ -214,10 +214,11 @@ webpack
214214
xcode
215215
xcrun
216216
xctrace
217-
xmcp
218217
Xeon
219218
XKKCNZZNJD
219+
xmcp
220220
xstyled
221+
xtask
221222
xxhash
222223
yannik
223224
Zack

xtask/benchmark/README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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

Comments
 (0)