Skip to content

test(bench): add concat_source_add microbenchmark#233

Merged
JSerFeng merged 1 commit intomainfrom
fy/bench-concat-source-add
Apr 23, 2026
Merged

test(bench): add concat_source_add microbenchmark#233
JSerFeng merged 1 commit intomainfrom
fy/bench-concat-source-add

Conversation

@JSerFeng
Copy link
Copy Markdown
Contributor

What

Adds two new criterion benchmarks under the existing rspack_sources group:

  • concat_source_add_many — builds a ConcatSource by sequentially adding 500 RawStringSource children
  • concat_source_add_few — same shape, but with 16 children

Why

The current bench suite builds each ConcatSource once during setup and then loops over .map().to_json() (or .source(), .size(), hashing, etc.) inside b.iter. That measures the cached read path, but leaves the construction path — the repeated add calls — completely uninstrumented.

In real Rspack code generation, add is one of the hottest patterns: rspack_plugin_javascript/src/runtime.rs does a par_iter().fold(ConcatSource::default, |mut acc, src| { acc.add(src); acc }), and rspack_core's concatenated module rendering chains 300+ add calls per module. Without coverage here, perf changes touching add (good or bad) slip past CodSpeed silently — for example, the recent lock()get_mut() change in add showed no movement on the existing benches even though it's measurably ~6–7 ns faster per call.

The 500/16 sizes were picked to match those two real shapes (concatenated module assembly vs. runtime module wrapping).

How

  • benches/bench.rs: two new functions, each building Vec<BoxSource> of N RawStringSource children up-front (so allocation is excluded from the hot loop), then b.iter builds a fresh ConcatSource and adds them all.
  • Registered in the existing rspack_sources benchmark group alongside the others.
  • No production code changes.

Adds two new criterion benches that build a ConcatSource by repeatedly
calling `add()` — one with 500 children (mirroring rspack's
concatenated_module rendering), one with 16 (mirroring runtime module
assembly). The existing bench suite only exercises `.map().to_json()`
on a pre-built ConcatSource, which leaves `add()`'s hot path
unmeasured. These cover that gap so future regressions in the
construction path get caught.
Copilot AI review requested due to automatic review settings April 23, 2026 11:38
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 23, 2026

Merging this PR will not alter performance

✅ 11 untouched benchmarks
🆕 2 new benchmarks
⏩ 7 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 concat_source_add_few N/A 6.3 µs N/A
🆕 concat_source_add_many N/A 51.2 µs N/A

Comparing fy/bench-concat-source-add (678e9a7) with main (7795fd2)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Criterion microbenchmarks to measure the ConcatSource construction hot path in rspack_sources, focusing specifically on repeated add calls (a pattern heavily used during Rspack codegen).

Changes:

  • Add concat_source_add_many benchmark that builds a fresh ConcatSource by adding 500 children in the timed loop.
  • Add concat_source_add_few benchmark that builds a fresh ConcatSource by adding 16 children in the timed loop.
  • Register both benchmarks under the existing rspack_sources benchmark group.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread benches/bench.rs
Comment thread benches/bench.rs
@JSerFeng JSerFeng enabled auto-merge (squash) April 23, 2026 11:42
@JSerFeng JSerFeng merged commit 10a3b71 into main Apr 23, 2026
10 checks passed
@JSerFeng JSerFeng deleted the fy/bench-concat-source-add branch April 23, 2026 11:44
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