Skip to content

refactor: reduce lock contention in swc js minimizer#12970

Open
hardfist wants to merge 2 commits intomainfrom
refactor/minimizer-extract-comments-lock
Open

refactor: reduce lock contention in swc js minimizer#12970
hardfist wants to merge 2 commits intomainfrom
refactor/minimizer-extract-comments-lock

Conversation

@hardfist
Copy link
Contributor

@hardfist hardfist commented Feb 6, 2026

Summary

  • avoid allocating global extracted-comments map unless extract_comments is enabled
  • avoid per-asset global mutex lookup for banner insertion
  • use per-asset local flag (Cell<bool>) to decide whether banner is needed

Why

Perf profiling on /home/yj/github/build-tools-performance/cases/react-10k showed lock contention in minimization path.

Before/after from perf (cycles:uk, --no-children):

  • std::sys::sync::mutex::futex::Mutex::lock_contended: 0.85% -> 0.60%
  • swc_ecma_minifier compress::pure visit_mut_expr: 1.01% -> 0.65%

Observed compile time in the same profiling scenario:

  • 249 ms -> 229 ms (single run)

Validation

  • pnpm run build:binding:profiling
  • perf record ... react-10k
  • perf report --stdio --no-children -g none

Only allocate and lock extracted-comments map when extract_comments is enabled, and use per-asset local state for banner decision.

Perf check on react-10k case showed reduced Mutex::lock_contended hotspot and improved compile time in profiling run.
Copilot AI review requested due to automatic review settings February 6, 2026 09:26
@github-actions github-actions bot added release: refactor team The issue/pr is created by the member of Rspack. labels Feb 6, 2026
Copy link
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 refactors the SWC JavaScript minimizer to reduce lock contention during parallel asset processing by optimizing how extracted comments are tracked and how banner insertion decisions are made.

Changes:

  • Conditionally allocate the global all_extracted_comments map only when extract_comments is enabled
  • Replace global mutex lookups for banner insertion decision with per-asset local Cell<bool> flag
  • Guard all uses of all_extracted_comments with Option checks

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

Avoid exists+remove_file before create_write_stream in BridgeFileSystem::write_file to cut extra filesystem round-trips on write path.
@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

📝 Benchmark detail: Open

Name Base (2026-02-06 5b579bb) Current Change
10000_big_production-mode_disable-minimize + exec 13.9 s ± 83 ms 13.9 s ± 110 ms +0.08 %
10000_development-mode + exec 1.09 s ± 28 ms 1.1 s ± 36 ms +1.79 %
10000_development-mode_hmr + stats 195 ms ± 3.7 ms 202 ms ± 15 ms +3.39 %
10000_development-mode_noop-loader + exec 2.11 s ± 42 ms 2.11 s ± 27 ms -0.05 %
10000_production-mode + exec 1.2 s ± 52 ms 1.21 s ± 25 ms +0.77 %
10000_production-mode_persistent-cold + exec 1.39 s ± 21 ms 1.4 s ± 39 ms +1.25 %
10000_production-mode_persistent-hot + exec 1.01 s ± 41 ms 1.02 s ± 28 ms +0.91 %
arco-pro_development-mode + exec 1.35 s ± 77 ms 1.34 s ± 71 ms -0.62 %
arco-pro_development-mode_hmr + stats 39 ms ± 0.91 ms 38 ms ± 0.39 ms -2.47 %
arco-pro_production-mode + exec 2.4 s ± 63 ms 2.4 s ± 64 ms +0.23 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 2.47 s ± 77 ms 2.48 s ± 83 ms +0.52 %
arco-pro_production-mode_persistent-cold + exec 2.51 s ± 114 ms 2.47 s ± 80 ms -1.67 %
arco-pro_production-mode_persistent-hot + exec 1.41 s ± 21 ms 1.42 s ± 24 ms +0.92 %
arco-pro_production-mode_traverse-chunk-modules + exec 2.43 s ± 38 ms 2.44 s ± 95 ms +0.73 %
large-dyn-imports_development-mode + exec 1.34 s ± 38 ms 1.34 s ± 42 ms -0.06 %
large-dyn-imports_production-mode + exec 1.44 s ± 49 ms 1.45 s ± 59 ms +1.03 %
threejs_development-mode_10x + exec 1.19 s ± 12 ms 1.19 s ± 8.3 ms +0.64 %
threejs_development-mode_10x_hmr + stats 127 ms ± 2.6 ms 123 ms ± 3.6 ms -3.56 %
threejs_production-mode_10x + exec 3.3 s ± 42 ms 3.29 s ± 52 ms -0.48 %
threejs_production-mode_10x_persistent-cold + exec 3.44 s ± 46 ms 3.39 s ± 32 ms -1.60 %
threejs_production-mode_10x_persistent-hot + exec 2.83 s ± 23 ms 2.8 s ± 23 ms -0.75 %
10000_big_production-mode_disable-minimize + rss memory 2308 MiB ± 220 MiB 2334 MiB ± 270 MiB +1.13 %
10000_development-mode + rss memory 661 MiB ± 17.3 MiB 670 MiB ± 33.1 MiB +1.39 %
10000_development-mode_hmr + rss memory 854 MiB ± 12.2 MiB 832 MiB ± 10.7 MiB -2.57 %
10000_development-mode_noop-loader + rss memory 975 MiB ± 35.4 MiB 963 MiB ± 25 MiB -1.24 %
10000_production-mode + rss memory 560 MiB ± 7.08 MiB 561 MiB ± 7.31 MiB +0.09 %
10000_production-mode_persistent-cold + rss memory 805 MiB ± 14.4 MiB 783 MiB ± 19.4 MiB -2.70 %
10000_production-mode_persistent-hot + rss memory 758 MiB ± 16.8 MiB 752 MiB ± 18.3 MiB -0.78 %
arco-pro_development-mode + rss memory 550 MiB ± 49.4 MiB 527 MiB ± 50 MiB -4.18 %
arco-pro_development-mode_hmr + rss memory 481 MiB ± 10.3 MiB 474 MiB ± 19.1 MiB -1.28 %
arco-pro_production-mode + rss memory 612 MiB ± 56.4 MiB 598 MiB ± 31.7 MiB -2.31 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 633 MiB ± 66.1 MiB 621 MiB ± 57.3 MiB -1.95 %
arco-pro_production-mode_persistent-cold + rss memory 677 MiB ± 19.9 MiB 683 MiB ± 51.4 MiB +0.93 %
arco-pro_production-mode_persistent-hot + rss memory 438 MiB ± 60.6 MiB 484 MiB ± 9.66 MiB +10.54 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 590 MiB ± 84.1 MiB 603 MiB ± 31.7 MiB +2.05 %
large-dyn-imports_development-mode + rss memory 687 MiB ± 21.1 MiB 681 MiB ± 19.6 MiB -0.81 %
large-dyn-imports_production-mode + rss memory 508 MiB ± 5.46 MiB 505 MiB ± 7.85 MiB -0.68 %
threejs_development-mode_10x + rss memory 548 MiB ± 13.5 MiB 545 MiB ± 9.01 MiB -0.49 %
threejs_development-mode_10x_hmr + rss memory 778 MiB ± 21.8 MiB 769 MiB ± 23.2 MiB -1.12 %
threejs_production-mode_10x + rss memory 683 MiB ± 16.3 MiB 677 MiB ± 9.09 MiB -0.90 %
threejs_production-mode_10x_persistent-cold + rss memory 833 MiB ± 24.7 MiB 806 MiB ± 16.4 MiB -3.16 %
threejs_production-mode_10x_persistent-hot + rss memory 658 MiB ± 22.3 MiB 644 MiB ± 21.5 MiB -2.15 %

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 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 825.4 KB 0
react-5k 2.7 MB 0
rome 984.2 KB 0
ui-components 2.2 MB 0

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

📦 Binary Size-limit

Comparing c523f3c to chore: use httpClient to mock test server (#12962) by pshu

🎉 Size decreased by 1.13KB from 48.56MB to 48.56MB (⬇️0.00%)

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 6, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing refactor/minimizer-extract-comments-lock (c523f3c) with main (c938a59)

Summary

✅ 16 untouched benchmarks
⏩ 1 skipped benchmark1

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: refactor team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant