refactor: reduce lock contention in swc js minimizer#12970
refactor: reduce lock contention in swc js minimizer#12970
Conversation
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.
There was a problem hiding this comment.
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_commentsmap only whenextract_commentsis enabled - Replace global mutex lookups for banner insertion decision with per-asset local
Cell<bool>flag - Guard all uses of
all_extracted_commentswith 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.
|
📝 Benchmark detail: Open
|
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
📦 Binary Size-limit
🎉 Size decreased by 1.13KB from 48.56MB to 48.56MB (⬇️0.00%) |
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
Summary
extract_commentsis enabledCell<bool>) to decide whether banner is neededWhy
Perf profiling on
/home/yj/github/build-tools-performance/cases/react-10kshowed 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:profilingperf record ... react-10kperf report --stdio --no-children -g none