Skip to content

perf: reduce code splitter allocation and lookup overhead#13968

Merged
LingyuCoder merged 14 commits into
mainfrom
codex/optimize-code-splitter-prepare
May 11, 2026
Merged

perf: reduce code splitter allocation and lookup overhead#13968
LingyuCoder merged 14 commits into
mainfrom
codex/optimize-code-splitter-prepare

Conversation

@LingyuCoder
Copy link
Copy Markdown
Contributor

@LingyuCoder LingyuCoder commented May 9, 2026

Summary

  • Optimize code splitter preparation by replacing the prepared connection IndexMap with vector-backed grouped connections and building the async block map directly from modules and module graph blocks.
  • Reduce module graph lookups and allocation churn while preparing entrypoint depth data, including sparse outgoing maps, preallocated depth queues, and a single mutable module graph pass for depth writes.
  • Streamline chunk group processing paths by avoiding temporary collections/clones in connect queue, outdated chunk group revisits, combining, and merging.
  • Add capacity hints for dynamic import chunk short-name assignment in the ESM library chunk optimizer.

Related links

N/A

Checklist

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

@github-actions github-actions Bot added the release: performance release: performance related release(mr only) label May 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

📦 Binary Size-limit

Comparing d2f4080 to feat(externals): add modern-module externals type (#13861) by Fy

🎉 Size decreased by 16.00KB from 61.92MB to 61.90MB (⬇️0.03%)

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 9, 2026

Merging this PR will improve performance by 11.87%

⚠️ 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

⚡ 1 improved benchmark
✅ 33 untouched benchmarks
⏩ 25 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation rust@build_chunk_graph 80.6 ms 72 ms +11.87%

Comparing codex/optimize-code-splitter-prepare (d2f4080) with main (eae2abd)2

Open in CodSpeed

Footnotes

  1. 25 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 (4e0ad16) during the generation of this report, so eae2abd was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

Rsdoctor Bundle Diff Analysis

⚠️ Note: The latest commit (fa01589641) does not have baseline artifacts. Using commit eae2abdfc4 for baseline comparison instead. If this seems incorrect, please wait a few minutes and try rerunning the workflow.

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
rome 1.6 MB 0
react-5k 2.7 MB 0
ui-components 4.8 MB 0

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

📝 Benchmark detail: Open

Name Base (3d23891) Current Change
10000_big_production-mode_disable-minimize + exec 13.9 s ± 341 ms 13.9 s ± 343 ms +0.52 %
10000_development-mode + exec 893 ms ± 44 ms 889 ms ± 24 ms -0.49 %
10000_development-mode_hmr + stats 164 ms ± 20 ms 159 ms ± 5.5 ms -3.08 %
10000_development-mode_noop-loader + exec 1.98 s ± 58 ms 1.94 s ± 63 ms -1.82 %
10000_production-mode + exec 988 ms ± 8.8 ms 986 ms ± 15 ms -0.26 %
10000_production-mode_persistent-cold + exec 1.15 s ± 29 ms 1.15 s ± 30 ms +0.12 %
10000_production-mode_persistent-hot + exec 595 ms ± 18 ms 601 ms ± 14 ms +0.87 %
10000_production-mode_source-map + exec 1.16 s ± 22 ms 1.15 s ± 35 ms -0.43 %
arco-pro_development-mode + exec 1.29 s ± 72 ms 1.31 s ± 106 ms +1.76 %
arco-pro_development-mode_hmr + stats 33 ms ± 0.54 ms 33 ms ± 1.1 ms +0.27 %
arco-pro_production-mode + exec 2.39 s ± 120 ms 2.39 s ± 119 ms +0.13 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 2.45 s ± 57 ms 2.5 s ± 153 ms +2.03 %
arco-pro_production-mode_persistent-cold + exec 2.45 s ± 105 ms 2.43 s ± 110 ms -0.75 %
arco-pro_production-mode_persistent-hot + exec 343 ms ± 7.6 ms 343 ms ± 6.3 ms -0.06 %
arco-pro_production-mode_source-map + exec 2.87 s ± 56 ms 2.88 s ± 146 ms +0.20 %
arco-pro_production-mode_traverse-chunk-modules + exec 2.45 s ± 118 ms 2.45 s ± 59 ms -0.37 %
bundled-threejs_development-mode + exec 182 ms ± 3.7 ms 182 ms ± 5.6 ms 0.00 %
bundled-threejs_production-mode + exec 212 ms ± 9.9 ms 210 ms ± 8.1 ms -0.85 %
large-dyn-imports_development-mode + exec 1.12 s ± 36 ms 1.12 s ± 26 ms -0.12 %
large-dyn-imports_production-mode + exec 1.24 s ± 25 ms 1.25 s ± 37 ms +1.13 %
threejs_development-mode_10x + exec 812 ms ± 17 ms 810 ms ± 15 ms -0.20 %
threejs_development-mode_10x_hmr + stats 109 ms ± 2.4 ms 109 ms ± 3 ms +0.17 %
threejs_production-mode_10x + exec 2.91 s ± 34 ms 2.92 s ± 21 ms +0.02 %
threejs_production-mode_10x_persistent-cold + exec 3.02 s ± 29 ms 3.03 s ± 49 ms +0.22 %
threejs_production-mode_10x_persistent-hot + exec 386 ms ± 12 ms 383 ms ± 19 ms -0.57 %
threejs_production-mode_10x_source-map + exec 3.59 s ± 62 ms 3.6 s ± 47 ms +0.13 %
10000_big_production-mode_disable-minimize + rss memory 2032 MiB ± 45.8 MiB 2074 MiB ± 25.6 MiB +2.11 %
10000_development-mode + rss memory 591 MiB ± 17.6 MiB 593 MiB ± 22 MiB +0.40 %
10000_development-mode_hmr + rss memory 816 MiB ± 34 MiB 806 MiB ± 37.9 MiB -1.19 %
10000_development-mode_noop-loader + rss memory 890 MiB ± 16.5 MiB 889 MiB ± 13.5 MiB -0.06 %
10000_production-mode + rss memory 540 MiB ± 19.9 MiB 544 MiB ± 16.6 MiB +0.63 %
10000_production-mode_persistent-cold + rss memory 739 MiB ± 9.44 MiB 737 MiB ± 15.1 MiB -0.21 %
10000_production-mode_persistent-hot + rss memory 628 MiB ± 32.6 MiB 647 MiB ± 18 MiB +2.99 %
10000_production-mode_source-map + rss memory 535 MiB ± 16.3 MiB 523 MiB ± 19 MiB -2.23 %
arco-pro_development-mode + rss memory 484 MiB ± 8.41 MiB 486 MiB ± 9.94 MiB +0.58 %
arco-pro_development-mode_hmr + rss memory 497 MiB ± 7.96 MiB 501 MiB ± 3.24 MiB +0.72 %
arco-pro_production-mode + rss memory 682 MiB ± 14.6 MiB 680 MiB ± 12.4 MiB -0.33 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 697 MiB ± 10.9 MiB 679 MiB ± 60.3 MiB -2.57 %
arco-pro_production-mode_persistent-cold + rss memory 753 MiB ± 8.21 MiB 752 MiB ± 12.4 MiB -0.09 %
arco-pro_production-mode_persistent-hot + rss memory 375 MiB ± 26.9 MiB 366 MiB ± 21.9 MiB -2.48 %
arco-pro_production-mode_source-map + rss memory 762 MiB ± 10.1 MiB 766 MiB ± 21.9 MiB +0.42 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 683 MiB ± 6.68 MiB 686 MiB ± 18.2 MiB +0.41 %
bundled-threejs_development-mode + rss memory 153 MiB ± 11.6 MiB 150 MiB ± 7.34 MiB -2.19 %
bundled-threejs_production-mode + rss memory 177 MiB ± 4 MiB 177 MiB ± 4.65 MiB -0.28 %
large-dyn-imports_development-mode + rss memory 608 MiB ± 13.5 MiB 598 MiB ± 24 MiB -1.67 %
large-dyn-imports_production-mode + rss memory 460 MiB ± 10 MiB 461 MiB ± 9.63 MiB +0.19 %
threejs_development-mode_10x + rss memory 537 MiB ± 19.5 MiB 534 MiB ± 8.49 MiB -0.57 %
threejs_development-mode_10x_hmr + rss memory 672 MiB ± 23 MiB 673 MiB ± 23.9 MiB +0.08 %
threejs_production-mode_10x + rss memory 716 MiB ± 8.7 MiB 723 MiB ± 13.2 MiB +0.99 %
threejs_production-mode_10x_persistent-cold + rss memory 677 MiB ± 25.9 MiB 683 MiB ± 9.39 MiB +0.80 %
threejs_production-mode_10x_persistent-hot + rss memory 472 MiB ± 19.5 MiB 475 MiB ± 6.39 MiB +0.52 %
threejs_production-mode_10x_source-map + rss memory 852 MiB ± 35 MiB 851 MiB ± 34.8 MiB -0.13 %

Base persistent cache hit rate:

  • 10000_production-mode_persistent-cold: 0.00%
  • arco-pro_production-mode_persistent-cold: 0.00%
  • threejs_production-mode_10x_persistent-cold: 0.00%
    Current persistent cache hit rate:
  • 10000_production-mode_persistent-cold: 0.00%
  • arco-pro_production-mode_persistent-cold: 0.00%
  • threejs_production-mode_10x_persistent-cold: 0.00%

@LingyuCoder LingyuCoder force-pushed the codex/optimize-code-splitter-prepare branch from 00d375f to 783f718 Compare May 9, 2026 14:50
@LingyuCoder LingyuCoder marked this pull request as ready for review May 11, 2026 02:24
Copilot AI review requested due to automatic review settings May 11, 2026 02:24
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 focuses on reducing allocations and repeated module-graph work during chunk graph/code splitting preparation, aiming to improve overall compilation performance in rspack_core.

Changes:

  • Preallocates several hot-path Vec/HashMap structures to reduce reallocation overhead.
  • Refactors prepared connection/block mapping construction in the code splitter prepare() path.
  • Adds queue preallocation support to assign_depths and adjusts depth-map initialization strategy.

Reviewed changes

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

File Description
crates/rspack_plugin_esm_library/src/optimize_chunks.rs Preallocates maps/vectors used for dynamic-import chunk short-name assignment.
crates/rspack_core/src/compilation/mod.rs Updates assign_depths to support preallocating its BFS queue (but changes the public signature).
crates/rspack_core/src/compilation/build_chunk_graph/code_splitter.rs Refactors prepared connection/block maps and reduces some per-module graph lookup/allocation overhead.

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

Comment thread crates/rspack_core/src/compilation/mod.rs
Comment thread crates/rspack_core/src/compilation/build_chunk_graph/code_splitter.rs Outdated
Comment thread crates/rspack_core/src/compilation/build_chunk_graph/code_splitter.rs Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

📝 Benchmark detail: Open

Name Base (81aa0bb) Current Change
10000_big_production-mode_disable-minimize + exec 13.9 s ± 362 ms 13.8 s ± 168 ms -0.62 %
10000_development-mode + exec 893 ms ± 23 ms 875 ms ± 16 ms -2.08 %
10000_development-mode_hmr + stats 159 ms ± 5.5 ms 155 ms ± 3.3 ms -2.72 %
10000_development-mode_noop-loader + exec 1.94 s ± 41 ms 1.95 s ± 112 ms +0.49 %
10000_production-mode + exec 999 ms ± 19 ms 999 ms ± 24 ms +0.04 %
10000_production-mode_persistent-cold + exec 1.17 s ± 15 ms 1.14 s ± 11 ms -2.72 %
10000_production-mode_persistent-hot + exec 596 ms ± 16 ms 590 ms ± 16 ms -0.94 %
10000_production-mode_source-map + exec 1.17 s ± 21 ms 1.15 s ± 16 ms -1.46 %
arco-pro_development-mode + exec 1.32 s ± 120 ms 1.27 s ± 55 ms -3.66 %
arco-pro_development-mode_hmr + stats 34 ms ± 0.58 ms 33 ms ± 0.51 ms -0.86 %
arco-pro_production-mode + exec 2.44 s ± 132 ms 2.42 s ± 89 ms -1.16 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 2.48 s ± 104 ms 2.47 s ± 81 ms -0.64 %
arco-pro_production-mode_persistent-cold + exec 2.47 s ± 157 ms 2.43 s ± 86 ms -1.79 %
arco-pro_production-mode_persistent-hot + exec 342 ms ± 5.7 ms 343 ms ± 14 ms +0.35 %
arco-pro_production-mode_source-map + exec 2.85 s ± 133 ms 2.82 s ± 51 ms -1.02 %
arco-pro_production-mode_traverse-chunk-modules + exec 2.48 s ± 142 ms 2.43 s ± 90 ms -1.97 %
bundled-threejs_development-mode + exec 183 ms ± 4.3 ms 183 ms ± 4.9 ms +0.44 %
bundled-threejs_production-mode + exec 213 ms ± 4.3 ms 210 ms ± 6.5 ms -1.50 %
large-dyn-imports_development-mode + exec 1.14 s ± 27 ms 1.11 s ± 45 ms -2.53 %
large-dyn-imports_production-mode + exec 1.26 s ± 36 ms 1.26 s ± 37 ms +0.11 %
threejs_development-mode_10x + exec 812 ms ± 20 ms 814 ms ± 21 ms +0.22 %
threejs_development-mode_10x_hmr + stats 110 ms ± 2.3 ms 109 ms ± 6.6 ms -0.56 %
threejs_production-mode_10x + exec 2.94 s ± 27 ms 2.92 s ± 31 ms -0.75 %
threejs_production-mode_10x_persistent-cold + exec 3.05 s ± 27 ms 3.01 s ± 36 ms -1.30 %
threejs_production-mode_10x_persistent-hot + exec 388 ms ± 14 ms 381 ms ± 8.9 ms -1.85 %
threejs_production-mode_10x_source-map + exec 3.66 s ± 66 ms 3.58 s ± 68 ms -2.02 %
10000_big_production-mode_disable-minimize + rss memory 2091 MiB ± 37.9 MiB 2058 MiB ± 57.5 MiB -1.57 %
10000_development-mode + rss memory 595 MiB ± 10.3 MiB 591 MiB ± 6.86 MiB -0.66 %
10000_development-mode_hmr + rss memory 820 MiB ± 15.5 MiB 825 MiB ± 16.3 MiB +0.56 %
10000_development-mode_noop-loader + rss memory 889 MiB ± 9.57 MiB 887 MiB ± 11.1 MiB -0.26 %
10000_production-mode + rss memory 544 MiB ± 15.3 MiB 542 MiB ± 16 MiB -0.53 %
10000_production-mode_persistent-cold + rss memory 735 MiB ± 12.6 MiB 737 MiB ± 18.5 MiB +0.23 %
10000_production-mode_persistent-hot + rss memory 641 MiB ± 26.7 MiB 639 MiB ± 25.4 MiB -0.42 %
10000_production-mode_source-map + rss memory 536 MiB ± 4.84 MiB 524 MiB ± 30.7 MiB -2.08 %
arco-pro_development-mode + rss memory 488 MiB ± 11.6 MiB 486 MiB ± 10.7 MiB -0.43 %
arco-pro_development-mode_hmr + rss memory 500 MiB ± 6.03 MiB 496 MiB ± 12.1 MiB -0.92 %
arco-pro_production-mode + rss memory 682 MiB ± 6.57 MiB 682 MiB ± 14.4 MiB -0.01 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 696 MiB ± 12.5 MiB 700 MiB ± 8.42 MiB +0.60 %
arco-pro_production-mode_persistent-cold + rss memory 748 MiB ± 12.4 MiB 753 MiB ± 19.3 MiB +0.55 %
arco-pro_production-mode_persistent-hot + rss memory 368 MiB ± 19.4 MiB 373 MiB ± 38.6 MiB +1.46 %
arco-pro_production-mode_source-map + rss memory 758 MiB ± 9.51 MiB 765 MiB ± 32.2 MiB +0.86 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 686 MiB ± 14.1 MiB 686 MiB ± 15.7 MiB +0.04 %
bundled-threejs_development-mode + rss memory 149 MiB ± 5.22 MiB 152 MiB ± 11.2 MiB +2.66 %
bundled-threejs_production-mode + rss memory 178 MiB ± 6.44 MiB 176 MiB ± 2.56 MiB -1.45 %
large-dyn-imports_development-mode + rss memory 603 MiB ± 15.9 MiB 599 MiB ± 18.8 MiB -0.62 %
large-dyn-imports_production-mode + rss memory 460 MiB ± 7.16 MiB 464 MiB ± 6.79 MiB +0.84 %
threejs_development-mode_10x + rss memory 536 MiB ± 25 MiB 539 MiB ± 13.2 MiB +0.65 %
threejs_development-mode_10x_hmr + rss memory 673 MiB ± 9.82 MiB 673 MiB ± 33 MiB 0.00 %
threejs_production-mode_10x + rss memory 722 MiB ± 8.85 MiB 728 MiB ± 15.9 MiB +0.81 %
threejs_production-mode_10x_persistent-cold + rss memory 679 MiB ± 21.5 MiB 682 MiB ± 17.2 MiB +0.53 %
threejs_production-mode_10x_persistent-hot + rss memory 475 MiB ± 11.7 MiB 477 MiB ± 10.4 MiB +0.30 %
threejs_production-mode_10x_source-map + rss memory 838 MiB ± 28.6 MiB 853 MiB ± 32.3 MiB +1.74 %

Base persistent cache hit rate:

  • 10000_production-mode_persistent-cold: 0.00%
  • arco-pro_production-mode_persistent-cold: 0.00%
  • threejs_production-mode_10x_persistent-cold: 0.00%
    Current persistent cache hit rate:
  • 10000_production-mode_persistent-cold: 0.00%
  • arco-pro_production-mode_persistent-cold: 0.00%
  • threejs_production-mode_10x_persistent-cold: 0.00%

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

📝 Rspack Ecosystem CI: Open

suite result
rslib ✅ success
modernjs ❌ failure
rsbuild ❌ failure
rspress ✅ success
rstest ✅ success
plugin ✅ success
rsdoctor ✅ success
examples ✅ success
lynx-stack ❌ failure
devserver ✅ success
rsbuild-rsc-plugin ✅ success

@LingyuCoder LingyuCoder requested a review from JSerFeng May 11, 2026 08:58
@LingyuCoder
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@LingyuCoder LingyuCoder changed the title perf: optimize code splitter prepare perf: reduce code splitter allocation and lookup overhead May 11, 2026
@LingyuCoder LingyuCoder merged commit fc1e4ef into main May 11, 2026
45 checks passed
@LingyuCoder LingyuCoder deleted the codex/optimize-code-splitter-prepare branch May 11, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: performance release: performance related release(mr only)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants