Skip to content

perf(rolldown): some minor perf optimization found by autoresearch#8730

Merged
graphite-app[bot] merged 1 commit intomainfrom
perf/claude-code-autoresearch
Mar 16, 2026
Merged

perf(rolldown): some minor perf optimization found by autoresearch#8730
graphite-app[bot] merged 1 commit intomainfrom
perf/claude-code-autoresearch

Conversation

@Brooooooklyn
Copy link
Copy Markdown
Member

@Brooooooklyn Brooooooklyn commented Mar 16, 2026

Note

Medium Risk
Touches collapse_sourcemaps, which is used in chunk rendering/minification; incorrect source_id propagation could subtly break sourcemap fidelity even though the change is small and performance-motivated.

Overview
Optimizes sourcemap processing by removing rustc-hash/rolldown_utils dependencies and simplifying collapse_sourcemaps to pass through source_id directly instead of remapping via cached hash maps.

Also swaps newline counting in SourceMapSource to use memchr::memchr_iter for faster \n scanning.

Written by Cursor Bugbot for commit 56cddc8. This will update automatically on new commits. Configure here.

Copilot AI review requested due to automatic review settings March 16, 2026 03:29
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 16, 2026

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 308427e
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/69b7c4512578b30008a58f97

Copy link
Copy Markdown
Member Author


How to use the Graphite Merge Queue

Add the label graphite: merge-when-ready to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Copy Markdown
Contributor

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

This PR targets minor performance optimizations in rolldown_sourcemap’s collapse_sourcemaps implementation by removing hash-map based source ID remapping and introducing parallel processing over tokens, along with dropping the direct rustc-hash dependency from this crate.

Changes:

  • Parallelize token processing in collapse_sourcemaps using rolldown_utils::rayon.
  • Simplify source ID handling by using original_token.get_source_id() directly (removing source-index remapping/caching).
  • Remove rustc-hash from crates/rolldown_sourcemap dependencies (and update Cargo.lock).

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
crates/rolldown_sourcemap/src/lib.rs Switches collapse_sourcemaps token traversal to rayon and removes source-id remapping logic.
crates/rolldown_sourcemap/Cargo.toml Drops rustc-hash dependency for this crate.
Cargo.lock Updates lockfile to reflect removed dependency.

@Brooooooklyn Brooooooklyn force-pushed the perf/claude-code-autoresearch branch from 0e2508f to 2e6a386 Compare March 16, 2026 03:36
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@Brooooooklyn Brooooooklyn force-pushed the perf/claude-code-autoresearch branch from 2e6a386 to 6b669f1 Compare March 16, 2026 03:40
Copilot AI review requested due to automatic review settings March 16, 2026 03:40
Copy link
Copy Markdown
Contributor

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

This PR targets small performance improvements in rolldown by optimizing sourcemap collapsing and adjusting a JSX parsing flag used during chunk minification.

Changes:

  • Parallelize token processing in rolldown_sourcemap::collapse_sourcemaps and remove rustc-hash usage from rolldown_sourcemap.
  • Optimize newline counting in rolldown_sourcemap with memchr_iter.
  • Make minify-stage JSX parsing conditional on transform_options.is_jsx_preserve().

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/rolldown_sourcemap/src/source.rs Switch newline counting to memchr_iter for simpler/faster scanning.
crates/rolldown_sourcemap/src/lib.rs Parallelize collapse token mapping and remove hash-based source-id remapping/cache.
crates/rolldown_sourcemap/Cargo.toml Drop rustc-hash dependency from rolldown_sourcemap.
crates/rolldown/src/stages/generate_stage/minify_chunks.rs Make JSX parsing toggle depend on is_jsx_preserve().
Cargo.lock Remove rustc-hash from the resolved dependency set for rolldown_sourcemap.
Comments suppressed due to low confidence (1)

crates/rolldown_sourcemap/src/lib.rs:90

  • par_bridge() produces an unindexed ParallelIterator, so the subsequent collect::<Vec<_>>() does not guarantee preserving the original token order. Sourcemap token ordering is typically required to be sorted by (dst_line, dst_col) for correct lookup/serialization and for deterministic output; collecting in parallel here can silently scramble ordering. Consider switching to an indexed parallel iterator (e.g. collect tokens first then into_par_iter()), or sort the resulting tokens by destination position before constructing the SourceMap.
  let tokens = last_map
    .get_source_view_tokens()
    .par_bridge()
    .filter_map(|token| {
      let original_token = sourcemap_and_lookup_table.iter().rev().try_fold(
        token,
        |token, (sourcemap, lookup_table)| {
          sourcemap.lookup_source_view_token(
            lookup_table,
            token.get_src_line(),
            token.get_src_col(),
          )
        },
      );
      original_token.map(|original_token| {
        Token::new(
          token.get_dst_line(),
          token.get_dst_col(),
          original_token.get_src_line(),
          original_token.get_src_col(),
          original_token.get_source_id(),
          original_token.get_name_id(),
        )
      })
    })
    .collect::<Vec<_>>();

@Brooooooklyn Brooooooklyn force-pushed the perf/claude-code-autoresearch branch 2 times, most recently from a91449a to 7dc38dd Compare March 16, 2026 03:52
Copilot AI review requested due to automatic review settings March 16, 2026 03:52
Copy link
Copy Markdown
Contributor

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

This PR aims to improve build performance by streamlining sourcemap collapsing and reducing unnecessary work during minification (notably around line counting and JSX parsing mode selection).

Changes:

  • Optimizes newline counting in SourceMapSource by switching to memchr_iter.
  • Simplifies collapse_sourcemaps by removing rustc-hash-based source remapping/cache and directly forwarding source/name IDs from the folded token.
  • Adjusts chunk minification to enable JSX parsing only when transform_options.is_jsx_preserve() is set, and removes rustc-hash from rolldown_sourcemap dependencies.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/rolldown_sourcemap/src/source.rs Uses memchr_iter for faster newline counting.
crates/rolldown_sourcemap/src/lib.rs Removes FxHashMap remapping/cache in collapse_sourcemaps; forwards source_id directly.
crates/rolldown_sourcemap/Cargo.toml Drops rustc-hash dependency from the sourcemap crate.
crates/rolldown/src/stages/generate_stage/minify_chunks.rs Makes JSX parsing in minifier conditional on is_jsx_preserve().
Cargo.lock Updates lockfile to reflect removed rustc-hash dependency.
Comments suppressed due to low confidence (1)

crates/rolldown_sourcemap/src/lib.rs:88

  • The PR description mentions collapsing sourcemaps by processing tokens in parallel and re-sorting tokens for deterministic output. In the current implementation here, tokens are processed sequentially via get_source_view_tokens().filter_map(...).collect::<Vec<_>>() and there is no explicit re-sort step. If the description is meant to reflect the final behavior, either update the implementation or adjust the PR description to match what’s actually shipped.
  let tokens = last_map
    .get_source_view_tokens()
    .filter_map(|token| {
      let original_token = sourcemap_and_lookup_table.iter().rev().try_fold(
        token,
        |token, (sourcemap, lookup_table)| {
          sourcemap.lookup_source_view_token(
            lookup_table,
            token.get_src_line(),
            token.get_src_col(),
          )
        },
      );
      original_token.map(|original_token| {
        Token::new(
          token.get_dst_line(),
          token.get_dst_col(),
          original_token.get_src_line(),
          original_token.get_src_col(),
          original_token.get_source_id(),
          original_token.get_name_id(),
        )
      })
    })
    .collect::<Vec<_>>();

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 16, 2026

Benchmarks Rust

group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.00     66.1±2.13ms        ? ?/sec    1.02     67.2±3.47ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.00     74.8±2.19ms        ? ?/sec    1.00     74.5±1.68ms        ? ?/sec
bundle/bundle@rome_ts                                        1.00    146.5±7.18ms        ? ?/sec    1.03    151.3±5.95ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.00    167.4±6.58ms        ? ?/sec    1.02    170.8±6.80ms        ? ?/sec
bundle/bundle@threejs                                        1.07     67.5±4.34ms        ? ?/sec    1.00     63.0±2.45ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.01     74.3±3.24ms        ? ?/sec    1.00     73.3±3.56ms        ? ?/sec
bundle/bundle@threejs10x                                     1.02   733.0±10.24ms        ? ?/sec    1.00   716.8±11.12ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.02   835.9±10.07ms        ? ?/sec    1.00    820.0±8.70ms        ? ?/sec

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 16, 2026

Merging this PR will not alter performance

✅ 6 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing perf/claude-code-autoresearch (308427e) with main (2a906e6)2

Open in CodSpeed

Footnotes

  1. 8 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.

  2. No successful run was found on main (308427e) during the generation of this report, so 2a906e6 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Brooooooklyn Brooooooklyn force-pushed the perf/claude-code-autoresearch branch from 4444d38 to 56cddc8 Compare March 16, 2026 06:21
@Brooooooklyn
Copy link
Copy Markdown
Member Author

Brooooooklyn commented Mar 16, 2026

CleanShot 2026-03-16 at 14 45 34@2x

It's not too much, but it's worth taking a look

@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app bot commented Mar 16, 2026

Merge activity

…8730)

<!-- CURSOR_SUMMARY -->
> [!NOTE]
> **Medium Risk**
> Touches `collapse_sourcemaps`, which is used in chunk rendering/minification; incorrect `source_id` propagation could subtly break sourcemap fidelity even though the change is small and performance-motivated.
>
> **Overview**
> **Optimizes sourcemap processing** by removing `rustc-hash`/`rolldown_utils` dependencies and simplifying `collapse_sourcemaps` to pass through `source_id` directly instead of remapping via cached hash maps.
>
> Also swaps newline counting in `SourceMapSource` to use `memchr::memchr_iter` for faster `\n` scanning.
>
> <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 56cddc8. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@graphite-app graphite-app bot force-pushed the perf/claude-code-autoresearch branch from 56cddc8 to 308427e Compare March 16, 2026 08:50
@socket-security
Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedutil-deprecate@​1.0.21001008375100
Addedsource-map-js@​1.2.19910010080100
Addedpathe@​2.0.31001009282100
Addedsignal-exit@​4.1.01001009382100
Addedsource-map-support@​0.5.219910010083100
Addedpicomatch@​4.0.310010010085100
Addedterser@​5.46.09710010085100
Addedws@​8.19.09810010086100
Addedsemver@​7.7.410010010089100
Addedtypescript@​5.9.31001009010090

View full report

@graphite-app graphite-app bot merged commit 308427e into main Mar 16, 2026
33 checks passed
This was referenced Mar 18, 2026
shulaoda added a commit that referenced this pull request Mar 18, 2026
## [1.0.0-rc.10] - 2026-03-18

### 🚀 Features

- add indentExclusionRanges property to MagicString (#8746) by @IWANABETHATGUY
- expose `oxcRuntimePlugin` (#8654) by @sapphi-red
- rust: make bundler generic over FileSystem for in-memory benchmarks (#8652) by @Boshen

### 🐛 Bug Fixes

- rolldown_plugin_vite_dynamic_import_vars: align dynamic import fast check with Vite (#8760) by @shulaoda
- renamer: handle existing bindings in nested scopes when finding unique names (#8741) by @drewolson
- pass `yarn_pnp` option where needed (#8736) by @sapphi-red
- preserve optional chaining in namespace member expr rewrite (#8712) by @Copilot
- correct UTF-16 index handling in native MagicString (#8693) by @IWANABETHATGUY
- mark failing doctests as ignore (#8700) by @Boshen
- prevent may_partial_namespace from leaking through include_module (#8682) by @IWANABETHATGUY
- ci: bump native-build cache key to invalidate stale napi-rs artifacts (#8678) by @Boshen
- `comments.annotation: false` breaking tree-shaking (#8657) by @IWANABETHATGUY
- validate filenames for NUL bytes from chunkFileNames/entryFileNames (#8644) by @IWANABETHATGUY
- dce-only minify should not set NODE_ENV to production (#8651) by @IWANABETHATGUY

### 🚜 Refactor

- rust: remove dead `CrossModuleOptimizationConfig::side_effects_free_function_optimization` (#8673) by @Dunqing
- rust: simplify `cross_module_optimization` by removing redundant scope tracking (#8672) by @Dunqing
- simplify string repeat in guess_indentor (#8753) by @IWANABETHATGUY
- consolidate custom magic-string tests into one file (#8696) by @IWANABETHATGUY
- extract CJS bailout checks from include_symbol (#8683) by @IWANABETHATGUY
- rust: remove `BindingIdentifierExt` to use `BindingIdentifier::symbol_id()` instead (#8667) by @Dunqing
- bench: add bench_preset helper and inline presets (#8658) by @Boshen
- rust: filter external modules from entries instead of mapping bit positions (#8637) by @Dunqing

### 📚 Documentation

- clarify watch mode behavior and its limitations (#8751) by @sapphi-red
- add external link icon to GitHub button in Hero section (#8731) by @thisisnkc
- guide: clarify that `inject` option is only conceptually similar to esbuild's one (#8743) by @sapphi-red
- meta/design: add `devtools.md` (#8663) by @hyf0
- add viteplus alpha announcement banner (#8668) by @shulaoda

### ⚡ Performance

- rolldown: some minor perf optimization found by autoresearch (#8730) by @Brooooooklyn
- replace Vec allocation with lazy iterator in find_hash_placeholders (#8703) by @Boshen
- replace TypedDashMap with TypedMap in CustomField (#8708) by @Boshen
- bench: remove scan benchmark binary to halve LTO link time (#8694) by @Boshen

### 🧪 Testing

- watch: increase timeout for error output (#8766) by @sapphi-red
- vite-tests: remove JS plugin tests (#8767) by @sapphi-red
- watch: add CLI exit code test (#8752) by @sapphi-red
- normalize paths on Windows even if `resolve.symlinks` is false (#8483) by @sapphi-red

### ⚙️ Miscellaneous Tasks

- correct comment in bundle-analyzer-plugin.ts (#8770) by @origami-z
- upgrade oxc to 0.120.0 (#8764) by @Boshen
- enable all test for `reset` category in MagicString.test.ts (#8749) by @IWANABETHATGUY
- deps: update test262 submodule for tests (#8742) by @sapphi-red
- deps: update oxc apps (#8734) by @renovate[bot]
- deps: update softprops/action-gh-release action to v2.6.1 (#8724) by @renovate[bot]
- deps: update npm packages (major) (#8722) by @renovate[bot]
- deps: update github-actions (major) (#8721) by @renovate[bot]
- deps: update softprops/action-gh-release action to v2.6.0 (#8720) by @renovate[bot]
- deps: update npm packages (#8718) by @renovate[bot]
- deps: update rust crates (#8717) by @renovate[bot]
- deps: update github-actions (#8716) by @renovate[bot]
- deps: update dependency oxlint-tsgolint to v0.17.0 (#8713) by @renovate[bot]
- deps: bump cargo-shear to v1.11.2 (#8711) by @Boshen
- use org level `CODE_OF_CONDUCT.md` (#8706) by @sapphi-red
- fix cache key mismatch and remove redundant cache saves (#8695) by @Boshen
- deps: update oxc apps (#8692) by @renovate[bot]
- deps: update oxc apps (#8649) by @renovate[bot]
- should do matrix out side of reusable workflows 2 (#8691) by @hyf0
- should do matrix out side of reusable workflows (#8690) by @hyf0
- deps: update dependency rolldown-plugin-dts to v0.22.5 (#8689) by @renovate[bot]
- upgrade oxc to 0.119.0 and oxc_resolver to 11.19.1 (#8686) by @Boshen
- correct if condition of `type-check` job (#8677) by @hyf0
- Gate CI type-check job on node changes (#8669) by @Copilot
- benchmark: improve codspeed build (#8665) by @Boshen
- deps: update oxc to v0.118.0 (#8650) by @renovate[bot]
- deps: update crate-ci/typos action to v1.44.0 (#8647) by @renovate[bot]
- deps: update oxc resolver to v11.19.1 (#8646) by @renovate[bot]
- deps: update dependency rust to v1.94.0 (#8648) by @renovate[bot]
- deps: update dependency rolldown-plugin-dts to v0.22.4 (#8645) by @renovate[bot]

### ◀️ Revert

- Revert "ci: Gate CI type-check job on node changes" (#8674) by @hyf0
- "chore(deps): update dependency rust to v1.94.0 (#8648)" (#8660) by @shulaoda

### ❤️ New Contributors

* @origami-z made their first contribution in [#8770](#8770)
* @drewolson made their first contribution in [#8741](#8741)
* @thisisnkc made their first contribution in [#8731](#8731)

Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
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