Skip to content

test: configure rayon for codspeed benchmarks#13954

Merged
hardfist merged 1 commit into
mainfrom
codex/codspeed-rayon-current-thread
May 8, 2026
Merged

test: configure rayon for codspeed benchmarks#13954
hardfist merged 1 commit into
mainfrom
codex/codspeed-rayon-current-thread

Conversation

@hardfist

@hardfist hardfist commented May 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • before
image
  • after
image

Configure Rayon before the Rust benchmark groups run when rspack_core is built with the codspeed feature. The benchmark entrypoint now runs a small setup group first, and that setup uses ThreadPoolBuilder::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

  • Tests updated (or not required).
  • Documentation updated (or not required).

Validation

  • cargo fmt --all
  • cargo check --benches -p rspack_benchmark
  • RUSTFLAGS="--cfg codspeed --check-cfg=cfg(codspeed)" cargo check --benches -p rspack_benchmark

@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing 00ffc6b to feat(rsc): support configurable CSS link props (#13945) by Cong-Cong Pan

🙈 Size remains the same at 61.92MB

@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 6 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Change
popular-libs 1.7 MB 0
react-10k 5.7 MB 0
react-1k 826.3 KB 0
react-5k 2.7 MB 0
rome 1.6 MB 0
ui-components 4.8 MB 0

Generated by Rsdoctor GitHub Action

@hardfist hardfist force-pushed the codex/codspeed-rayon-current-thread branch from d44bb4d to 56b7d3c Compare May 8, 2026 10:49
@codspeed-hq

codspeed-hq Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 4.44%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 8 improved benchmarks
❌ 3 regressed benchmarks
✅ 23 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

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)

Open in CodSpeed

@hardfist hardfist force-pushed the codex/codspeed-rayon-current-thread branch from 56b7d3c to 00ffc6b Compare May 8, 2026 11:11
@hardfist hardfist marked this pull request as ready for review May 8, 2026 12:10
Copilot AI review requested due to automatic review settings May 8, 2026 12:10
@hardfist hardfist merged commit fa595f7 into main May 8, 2026
56 of 59 checks passed
@hardfist hardfist deleted the codex/codspeed-rayon-current-thread branch May 8, 2026 12:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in rspack_core to configure Rayon’s global thread pool with use_current_thread(), and invoke it via a small setup step before benchmark groups run.
  • Propagate the codspeed feature from rspack_core to rspack_parallel, changing RayonConsumer::consume behavior 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::consume now collects the entire ParallelIterator into a Vec before 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants