Skip to content

bench: add a representative concat sourcemap benchmark#369

Merged
Boshen merged 1 commit into
mainfrom
bench/concat-owned-sourcemap
Jun 19, 2026
Merged

bench: add a representative concat sourcemap benchmark#369
Boshen merged 1 commit into
mainfrom
bench/concat-owned-sourcemap

Conversation

@Boshen

@Boshen Boshen commented Jun 19, 2026

Copy link
Copy Markdown
Member

Replaces the tiny-fixture concat benches (from_sourcemaps / add_sourcemap_loop over the ~3 KB on-disk fixtures) with a single representative workload that reflects how the builder is actually used: a 200-module chunk, each module carrying ~2 KB of sourcesContent, concatenated into one owned SourceMap — rolldown's SourceJoiner shape.

concat/owned_maps measures the current from_sourcemaps(..).into_owned_sourcemap() path (~47 µs here). Landing it on main first gives a stable baseline for follow-up concat optimizations to measure against.

@codspeed-hq

codspeed-hq Bot commented Jun 19, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 1.03%

⚡ 1 improved benchmark
❌ 2 regressed benchmarks
✅ 11 untouched benchmarks
🆕 2 new benchmarks
⏩ 7 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
lookup_table[real_small] 1.3 µs 1.4 µs -2.13%
lookup_table[real_medium] 1.5 µs 1.5 µs -1.93%
build_single 5.8 µs 5.7 µs +1.02%
🆕 from_sourcemaps N/A 1.3 ms N/A
🆕 add_sourcemap N/A 1.6 ms N/A

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing bench/concat-owned-sourcemap (6f74fc6) with main (e55562d)

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.

Boshen added a commit that referenced this pull request Jun 19, 2026
#366 switched `ConcatSourceMapBuilder` to borrowed `&'a str` storage, which is
optimal when inputs outlive the result. But its main consumer (rolldown's
`SourceJoiner`) feeds *owned* `SourceMap<'static>` maps and wants an owned map
back, so `into_owned_sourcemap` deep-copied every name/source/sourcesContent
string — and `sourcesContent` is the full module text.

Store entries as `Cow<'a, str>` again so the builder can absorb owned strings by
moving them, and add:

* `add_sourcemap_owned(SourceMap<'a>, u32)` / `from_owned_sourcemaps(..)` — consume
  owned maps and move their `Cow` entries in (no string bytes copied).
* `add_sourcemap` (borrowed) and `add_sourcemap_owned` now share an `add_tokens`
  helper; only how the strings get in differs.

`into_sourcemap` moves the accumulated vectors straight out (also cheaper than
#366's rebuild for the borrowed case); `into_owned_sourcemap` keeps moved-in owned
strings as-is and copies only borrowed ones.

The `concat/owned_maps` benchmark (added in #369 as the borrow baseline) is switched
to the move-in path here. From the investigation sweep (200 modules): move-in is flat
at ~32us regardless of `sourcesContent` size, while borrow + `into_owned_sourcemap`
grows linearly (37us @256b, 47us @2KB, 70us @8kb, 542us @32kb) — up to ~16x faster,
identical mappings output.
@Boshen

Boshen commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

Adds the borrow-path baseline benches: concat/ConcatSourceMapBuilder::from_sourcemaps and ::add_sourcemap. Follow-up #368 adds the move-in variants (from_owned_sourcemaps / add_sourcemap_owned) alongside them. Merge this one first.

Boshen added a commit that referenced this pull request Jun 19, 2026
#366 switched `ConcatSourceMapBuilder` to borrowed `&'a str` storage, which is
optimal when inputs outlive the result. But its main consumer (rolldown's
`SourceJoiner`) feeds *owned* `SourceMap<'static>` maps and wants an owned map
back, so `into_owned_sourcemap` deep-copied every name/source/sourcesContent
string — and `sourcesContent` is the full module text.

Store entries as `Cow<'a, str>` again so the builder can absorb owned strings by
moving them, and add:

* `add_sourcemap_owned(SourceMap<'a>, u32)` / `from_owned_sourcemaps(..)` — consume
  owned maps and move their `Cow` entries in (no string bytes copied).
* `add_sourcemap` (borrowed) and `add_sourcemap_owned` now share an `add_tokens`
  helper; only how the strings get in differs.

`into_sourcemap` moves the accumulated vectors straight out (also cheaper than
#366's rebuild for the borrowed case); `into_owned_sourcemap` keeps moved-in owned
strings as-is and copies only borrowed ones.

The `concat` benchmark (added in #369 as `ConcatSourceMapBuilder::from_sourcemaps`,
the borrow baseline) is switched here to `ConcatSourceMapBuilder::from_owned_sourcemaps`.
From the investigation sweep (200 modules): move-in is flat at ~32us regardless of
`sourcesContent` size, while borrow + `into_owned_sourcemap` grows linearly
(37us @256b, 47us @2KB, 70us @8kb, 542us @32kb) — up to ~16x faster, identical
mappings output.
@Boshen
Boshen force-pushed the bench/concat-owned-sourcemap branch from 2d2f655 to 77447a4 Compare June 19, 2026 14:22
Replace the tiny-fixture `from_sourcemaps` / `add_sourcemap_loop` concat benches
(~3 KB total) with a single representative workload: a 200-module chunk, each
carrying ~2 KB of `sourcesContent`, concatenated into one owned `SourceMap` —
rolldown's `SourceJoiner` shape. `concat/owned_maps` measures the current
`from_sourcemaps` + `into_owned_sourcemap` path.
@Boshen
Boshen force-pushed the bench/concat-owned-sourcemap branch from 77447a4 to 6f74fc6 Compare June 19, 2026 14:32
Boshen added a commit that referenced this pull request Jun 19, 2026
#366 switched `ConcatSourceMapBuilder` to borrowed `&'a str` storage, which is
optimal when inputs outlive the result. But its main consumer (rolldown's
`SourceJoiner`) feeds *owned* `SourceMap<'static>` maps and wants an owned map
back, so `into_owned_sourcemap` deep-copied every name/source/sourcesContent
string — and `sourcesContent` is the full module text.

Store entries as `Cow<'a, str>` again so the builder can absorb owned strings by
moving them, and add:

* `add_sourcemap_owned(SourceMap<'a>, u32)` / `from_owned_sourcemaps(..)` — consume
  owned maps and move their `Cow` entries in (no string bytes copied).
* `add_sourcemap` (borrowed) and `add_sourcemap_owned` now share an `add_tokens`
  helper; only how the strings get in differs.

`into_sourcemap` moves the accumulated vectors straight out (also cheaper than
#366's rebuild for the borrowed case); `into_owned_sourcemap` keeps moved-in owned
strings as-is and copies only borrowed ones.

The `concat` benchmark group covers all four entry points: `from_sourcemaps` /
`add_sourcemap` (borrow — the baseline added in #369) plus `from_owned_sourcemaps` /
`add_sourcemap_owned` (the move-in variants added here). From the investigation
sweep (200 modules): move-in is flat at ~32us regardless of `sourcesContent` size,
while borrow + `into_owned_sourcemap` grows linearly (37us @256b, 47us @2KB,
70us @8kb, 542us @32kb) — up to ~16x faster, identical mappings output.
@Boshen
Boshen merged commit 8d72a6a into main Jun 19, 2026
8 checks passed
@Boshen
Boshen deleted the bench/concat-owned-sourcemap branch June 19, 2026 14:36
@oxc-guard oxc-guard Bot mentioned this pull request Jun 19, 2026
Boshen added a commit that referenced this pull request Jun 19, 2026
#370)

* Revert "bench: add a representative concat sourcemap benchmark (#369)"

This reverts commit 8d72a6a.

* Revert "refactor: apply borrow builder pattern to ConcatSourceMapBuilder (#366)"

This reverts commit e55562d.
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.

1 participant