Skip to content

fix: optimize concatenated module code generation hot paths#13375

Merged
LingyuCoder merged 9 commits intomainfrom
codex/optimize-find-new-name
Mar 18, 2026
Merged

fix: optimize concatenated module code generation hot paths#13375
LingyuCoder merged 9 commits intomainfrom
codex/optimize-find-new-name

Conversation

@LingyuCoder
Copy link
Copy Markdown
Contributor

@LingyuCoder LingyuCoder commented Mar 16, 2026

Summary

  • avoid cloning large ReplaceSource instances during final source assembly by moving info.source and chunk_init_fragments out of module_to_info_map
  • avoid re-hashing large concatenated outputs by using a ConcatenatedModule-specific code generation hash fast path based on the precomputed module hash plus lightweight metadata
  • move teardown of large concatenation state off the critical path by asynchronously dropping module_to_info_map, NameAllocator, escaped_names, escaped_identifiers, and changes after they are no longer needed

Checklist

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

Copilot AI review requested due to automatic review settings March 16, 2026 11:36
@github-actions github-actions Bot added team The issue/pr is created by the member of Rspack. release: bug fix release: bug related release(mr only) labels Mar 16, 2026
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

Reduces ConcatenatedModule code generation overhead by optimizing name allocation and moving an expensive map teardown (module_to_info_map) off the hot path via background drop, with added unit tests to lock in identifier-splitting and name-conflict behavior.

Changes:

  • Optimized find_new_name (both NameAllocator and standalone) by reusing string buffers and avoiding repeated identifier-start checks/allocation.
  • Swapped out module_to_info_map and dropped the old map on a blocking thread using fast_set to reduce critical-path teardown cost.
  • Added unit tests for split_readable_identifier ordering and find_new_name conflict-resolution stability.

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 16, 2026

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Change
react-10k 5.7 MB 0
react-1k 826.2 KB 0
react-5k 2.7 MB 0
rome 984.2 KB 0
ui-components 2.3 MB 0

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 16, 2026

📦 Binary Size-limit

Comparing f3c4e43 to feat: tree shaking for inlined members access dynamic import (#13381) by Gengkun

❌ Size increased by 21.63KB from 48.70MB to 48.72MB (⬆️0.04%)

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 16, 2026

Merging this PR will not alter performance

✅ 16 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing codex/optimize-find-new-name (f3c4e43) with main (6dd75d2)

Open in CodSpeed

Footnotes

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

@LingyuCoder LingyuCoder force-pushed the codex/optimize-find-new-name branch from 871cbaa to 1f70962 Compare March 17, 2026 04:35
@web-infra-dev web-infra-dev deleted a comment from github-actions Bot Mar 17, 2026
@web-infra-dev web-infra-dev deleted a comment from github-actions Bot Mar 17, 2026
@web-infra-dev web-infra-dev deleted a comment from github-actions Bot Mar 17, 2026
@web-infra-dev web-infra-dev deleted a comment from github-actions Bot Mar 17, 2026
@web-infra-dev web-infra-dev deleted a comment from github-actions Bot Mar 17, 2026
@web-infra-dev web-infra-dev deleted a comment from github-actions Bot Mar 17, 2026
@LingyuCoder LingyuCoder changed the title fix: reduce concatenated module code generation overhead fix: optimize concatenated module code generation hot paths Mar 17, 2026
@web-infra-dev web-infra-dev deleted a comment from github-actions Bot Mar 17, 2026
@LingyuCoder LingyuCoder force-pushed the codex/optimize-find-new-name branch from fffa8ba to 54750ea Compare March 17, 2026 08:52
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Mar 17, 2026

Deploying rspack with  Cloudflare Pages  Cloudflare Pages

Latest commit: 54750ea
Status: ✅  Deploy successful!
Preview URL: https://c604c313.rspack-v2.pages.dev
Branch Preview URL: https://codex-optimize-find-new-name.rspack-v2.pages.dev

View logs

@LingyuCoder LingyuCoder force-pushed the codex/optimize-find-new-name branch from 54750ea to b67ec06 Compare March 17, 2026 09:24
@web-infra-dev web-infra-dev deleted a comment from github-actions Bot Mar 17, 2026
@web-infra-dev web-infra-dev deleted a comment from github-actions Bot Mar 17, 2026
@web-infra-dev web-infra-dev deleted a comment from github-actions Bot Mar 17, 2026
@LingyuCoder LingyuCoder force-pushed the codex/optimize-find-new-name branch from b67ec06 to f3c4e43 Compare March 17, 2026 11:05
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 17, 2026

📝 Benchmark detail: Open

Name Base (6dd75d2) Current Change
10000_big_production-mode_disable-minimize + exec 14.3 s ± 190 ms 14.1 s ± 162 ms -1.51 %
10000_development-mode + exec 939 ms ± 7.5 ms 934 ms ± 26 ms -0.60 %
10000_development-mode_hmr + stats 180 ms ± 3.3 ms 176 ms ± 7.3 ms -1.94 %
10000_development-mode_noop-loader + exec 2.1 s ± 88 ms 2.09 s ± 186 ms -0.52 %
10000_production-mode + exec 1.1 s ± 28 ms 1.06 s ± 14 ms -4.06 %
10000_production-mode_persistent-cold + exec 1.35 s ± 19 ms 1.31 s ± 44 ms -2.86 %
10000_production-mode_persistent-hot + exec 960 ms ± 26 ms 934 ms ± 13 ms -2.75 %
10000_production-mode_source-map + exec 1.28 s ± 16 ms 1.23 s ± 16 ms -4.18 %
arco-pro_development-mode + exec 1.35 s ± 62 ms 1.33 s ± 61 ms -1.23 %
arco-pro_development-mode_hmr + stats 37 ms ± 0.89 ms 36 ms ± 0.79 ms -2.00 %
arco-pro_production-mode + exec 2.45 s ± 62 ms 2.42 s ± 114 ms -1.20 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 2.52 s ± 102 ms 2.48 s ± 135 ms -1.66 %
arco-pro_production-mode_persistent-cold + exec 2.53 s ± 50 ms 2.51 s ± 45 ms -0.71 %
arco-pro_production-mode_persistent-hot + exec 1.39 s ± 47 ms 1.39 s ± 33 ms -0.45 %
arco-pro_production-mode_source-map + exec 2.98 s ± 104 ms 2.87 s ± 127 ms -3.85 %
arco-pro_production-mode_traverse-chunk-modules + exec 2.48 s ± 41 ms 2.49 s ± 58 ms +0.51 %
bundled-threejs_development-mode + exec 187 ms ± 1.6 ms 185 ms ± 2.9 ms -0.96 %
bundled-threejs_production-mode + exec 220 ms ± 8.3 ms 215 ms ± 2 ms -2.09 %
large-dyn-imports_development-mode + exec 1.18 s ± 32 ms 1.17 s ± 26 ms -1.20 %
large-dyn-imports_production-mode + exec 1.33 s ± 39 ms 1.33 s ± 55 ms -0.11 %
threejs_development-mode_10x + exec 849 ms ± 19 ms 838 ms ± 18 ms -1.32 %
threejs_development-mode_10x_hmr + stats 120 ms ± 3 ms 116 ms ± 3.8 ms -2.98 %
threejs_production-mode_10x + exec 3.09 s ± 43 ms 3.02 s ± 26 ms -2.34 %
threejs_production-mode_10x_persistent-cold + exec 3.34 s ± 75 ms 3.19 s ± 67 ms -4.64 %
threejs_production-mode_10x_persistent-hot + exec 2.61 s ± 34 ms 2.53 s ± 19 ms -3.16 %
threejs_production-mode_10x_source-map + exec 3.9 s ± 26 ms 3.76 s ± 48 ms -3.60 %
10000_big_production-mode_disable-minimize + rss memory 1988 MiB ± 41.7 MiB 2019 MiB ± 17.8 MiB +1.59 %
10000_development-mode + rss memory 593 MiB ± 15.3 MiB 595 MiB ± 13.6 MiB +0.23 %
10000_development-mode_hmr + rss memory 812 MiB ± 45.4 MiB 801 MiB ± 30.4 MiB -1.32 %
10000_development-mode_noop-loader + rss memory 893 MiB ± 12.4 MiB 894 MiB ± 18.2 MiB +0.13 %
10000_production-mode + rss memory 544 MiB ± 14.1 MiB 543 MiB ± 24.5 MiB -0.31 %
10000_production-mode_persistent-cold + rss memory 727 MiB ± 12.3 MiB 738 MiB ± 10.9 MiB +1.60 %
10000_production-mode_persistent-hot + rss memory 642 MiB ± 39.9 MiB 626 MiB ± 62.2 MiB -2.51 %
10000_production-mode_source-map + rss memory 564 MiB ± 6.01 MiB 561 MiB ± 11.6 MiB -0.39 %
arco-pro_development-mode + rss memory 478 MiB ± 3.81 MiB 475 MiB ± 8.73 MiB -0.50 %
arco-pro_development-mode_hmr + rss memory 494 MiB ± 9.55 MiB 492 MiB ± 7.43 MiB -0.34 %
arco-pro_production-mode + rss memory 668 MiB ± 4.34 MiB 676 MiB ± 27.5 MiB +1.09 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 687 MiB ± 15 MiB 691 MiB ± 6.55 MiB +0.61 %
arco-pro_production-mode_persistent-cold + rss memory 739 MiB ± 14.3 MiB 744 MiB ± 10.3 MiB +0.67 %
arco-pro_production-mode_persistent-hot + rss memory 529 MiB ± 30.5 MiB 521 MiB ± 16.2 MiB -1.58 %
arco-pro_production-mode_source-map + rss memory 764 MiB ± 4.76 MiB 764 MiB ± 24.9 MiB +0.05 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 673 MiB ± 19.6 MiB 659 MiB ± 67.3 MiB -2.08 %
bundled-threejs_development-mode + rss memory 157 MiB ± 4.09 MiB 158 MiB ± 9.8 MiB +0.16 %
bundled-threejs_production-mode + rss memory 177 MiB ± 7.37 MiB 181 MiB ± 8.96 MiB +1.76 %
large-dyn-imports_development-mode + rss memory 592 MiB ± 41.7 MiB 602 MiB ± 15.8 MiB +1.71 %
large-dyn-imports_production-mode + rss memory 456 MiB ± 7.14 MiB 465 MiB ± 6.22 MiB +2.12 %
threejs_development-mode_10x + rss memory 533 MiB ± 11.8 MiB 527 MiB ± 11 MiB -1.11 %
threejs_development-mode_10x_hmr + rss memory 673 MiB ± 21.9 MiB 676 MiB ± 9.44 MiB +0.47 %
threejs_production-mode_10x + rss memory 713 MiB ± 19.7 MiB 726 MiB ± 14.1 MiB +1.92 %
threejs_production-mode_10x_persistent-cold + rss memory 850 MiB ± 11 MiB 839 MiB ± 20.4 MiB -1.28 %
threejs_production-mode_10x_persistent-hot + rss memory 611 MiB ± 7.22 MiB 609 MiB ± 6.15 MiB -0.21 %
threejs_production-mode_10x_source-map + rss memory 842 MiB ± 43.2 MiB 850 MiB ± 23.2 MiB +0.98 %

@LingyuCoder LingyuCoder requested a review from JSerFeng March 18, 2026 03:24
@LingyuCoder LingyuCoder enabled auto-merge (squash) March 18, 2026 03:33
@JSerFeng
Copy link
Copy Markdown
Contributor

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f3c4e4394c

ℹ️ 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".

Comment thread crates/rspack_core/src/compilation/code_generation/mod.rs
@LingyuCoder LingyuCoder merged commit 6c0987b into main Mar 18, 2026
47 checks passed
@LingyuCoder LingyuCoder deleted the codex/optimize-find-new-name branch March 18, 2026 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants