test(bench): add concat_source_add microbenchmark#233
Merged
Conversation
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.
Merging this PR will not alter performance
Performance Changes
Comparing Footnotes
|
There was a problem hiding this comment.
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_manybenchmark that builds a freshConcatSourceby adding 500 children in the timed loop. - Add
concat_source_add_fewbenchmark that builds a freshConcatSourceby adding 16 children in the timed loop. - Register both benchmarks under the existing
rspack_sourcesbenchmark group.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
SyMind
approved these changes
Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds two new criterion benchmarks under the existing
rspack_sourcesgroup:concat_source_add_many— builds aConcatSourceby sequentially adding 500RawStringSourcechildrenconcat_source_add_few— same shape, but with 16 childrenWhy
The current bench suite builds each
ConcatSourceonce during setup and then loops over.map().to_json()(or.source(),.size(), hashing, etc.) insideb.iter. That measures the cached read path, but leaves the construction path — the repeatedaddcalls — completely uninstrumented.In real Rspack code generation,
addis one of the hottest patterns:rspack_plugin_javascript/src/runtime.rsdoes apar_iter().fold(ConcatSource::default, |mut acc, src| { acc.add(src); acc }), andrspack_core's concatenated module rendering chains 300+addcalls per module. Without coverage here, perf changes touchingadd(good or bad) slip past CodSpeed silently — for example, the recentlock()→get_mut()change inaddshowed 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 buildingVec<BoxSource>of NRawStringSourcechildren up-front (so allocation is excluded from the hot loop), thenb.iterbuilds a freshConcatSourceand adds them all.rspack_sourcesbenchmark group alongside the others.