test: configure rayon for codspeed benchmarks#13954
Conversation
📦 Binary Size-limit
🙈 Size remains the same at 61.92MB |
Rsdoctor Bundle Diff AnalysisFound 6 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
d44bb4d to
56b7d3c
Compare
Merging this PR will degrade performance by 4.44%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | rust@build_module_graph |
1.2 s | 1.1 s | +5.21% |
| ❌ | Simulation | rust@build_chunk_graph |
93.4 ms | 97.7 ms | -4.44% |
| ❌ | Simulation | bundle@basic-react-development |
340 ms | 354.3 ms | -4.05% |
| ⚡ | Simulation | rust@flag_dependency_usage |
29.4 ms | 26.5 ms | +10.98% |
| ⚡ | Simulation | rust@concatenate_module_code_generation |
121.2 ms | 116.2 ms | +4.33% |
| ⚡ | Simulation | rust@persistent_cache_restore_after_single_file_change@basic-react-development |
19.8 ms | 18.8 ms | +5.43% |
| ❌ | Simulation | rust@runtime_requirements |
54.2 ms | 56.4 ms | -3.91% |
| ⚡ | Simulation | rust@create_chunk_ids |
9.1 ms | 8.8 ms | +3.4% |
| ⚡ | Simulation | rust@split_chunks |
5.3 ms | 5.2 ms | +3.33% |
| ⚡ | Simulation | rust@create_concatenate_module |
38.9 ms | 37.5 ms | +3.92% |
| ⚡ | Simulation | rust@persistent_cache_restore@basic-react-development |
18.7 ms | 17.5 ms | +6.53% |
Comparing codex/codspeed-rayon-current-thread (00ffc6b) with main (7fbf01d)
56b7d3c to
00ffc6b
Compare
There was a problem hiding this comment.
Pull request overview
This PR improves CodSpeed attribution for Rust benchmarks by ensuring Rayon is configured so the benchmark thread participates as Rayon worker 0, and by propagating a codspeed feature into rspack_parallel to adjust parallel-consumption behavior during CodSpeed runs.
Changes:
- Add a
codspeed-only utility inrspack_coreto configure Rayon’s global thread pool withuse_current_thread(), and invoke it via a small setup step before benchmark groups run. - Propagate the
codspeedfeature fromrspack_coretorspack_parallel, changingRayonConsumer::consumebehavior under CodSpeed. - Adjust the benchmark Tokio runtime to use a current-thread runtime when compiled under
cfg(codspeed).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| xtask/benchmark/src/lib.rs | Builds a current-thread Tokio runtime under cfg(codspeed) to reduce thread noise in CodSpeed. |
| xtask/benchmark/benches/benches.rs | Adds a setup “group” to configure Rayon before other benchmark groups execute. |
| crates/rspack_parallel/src/iterator_consumer/rayon.rs | Alters RayonConsumer::consume behavior under feature = "codspeed". |
| crates/rspack_parallel/Cargo.toml | Introduces a codspeed feature flag for rspack_parallel. |
| crates/rspack_core/src/utils/mod.rs | Adds a codspeed utils module and re-exports it behind the codspeed feature. |
| crates/rspack_core/src/utils/codspeed.rs | New helper to configure Rayon global pool for CodSpeed attribution. |
| crates/rspack_core/Cargo.toml | Makes rspack_core’s codspeed feature enable rspack_parallel/codspeed. |
| Cargo.toml | Allows cfg(codspeed) under unexpected_cfgs.check-cfg to avoid lint warnings. |
Comments suppressed due to low confidence (1)
crates/rspack_parallel/src/iterator_consumer/rayon.rs:41
- When
feature = "codspeed"(and on wasm),RayonConsumer::consumenow collects the entireParallelIteratorinto aVecbefore invoking the callback. This can significantly increase peak memory usage for large iterators (e.g., persistent cache paths) and also contradicts the trait docs about consuming items immediately without waiting for all data to be processed. Consider either keeping a streaming implementation for the codspeed path (that still satisfies CodSpeed attribution), or updating the trait docs to clearly describe the codspeed/wasm behavior and its memory implications.
#[cfg(any(target_family = "wasm", feature = "codspeed"))]
fn consume(self, mut func: impl FnMut(Self::Item)) {
let items: Vec<Self::Item> = self.collect();
for item in items {
func(item)
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Configure Rayon before the Rust benchmark groups run when
rspack_coreis built with thecodspeedfeature. The benchmark entrypoint now runs a small setup group first, and that setup usesThreadPoolBuilder::use_current_thread()so Rayon worker 0 is the benchmark thread. This helps CodSpeed attribute Rayon work to the measured parent function.Related links
N/A
Checklist
Validation
cargo fmt --allcargo check --benches -p rspack_benchmarkRUSTFLAGS="--cfg codspeed --check-cfg=cfg(codspeed)" cargo check --benches -p rspack_benchmark