Skip to content

perf: optimize flag dependency usage#14052

Merged
LingyuCoder merged 1 commit into
mainfrom
perf/flag-dependency-usage
May 15, 2026
Merged

perf: optimize flag dependency usage#14052
LingyuCoder merged 1 commit into
mainfrom
perf/flag-dependency-usage

Conversation

@LingyuCoder

@LingyuCoder LingyuCoder commented May 15, 2026

Copy link
Copy Markdown
Contributor

What changed

  • Avoid allocating boxed usage-filter closures when marking export usage by making set_used_conditionally generic over the predicate.
  • Filter active dependencies while walking dependency blocks in FlagDependencyUsagePlugin instead of first materializing all dependency ids and scanning them again.

Why this should improve performance

FlagDependencyUsagePlugin scales with dependencies and export infos, which are among the highest-cardinality structures in compilation. The previous path performed repeated heap allocation for usage predicates and kept an avoidable temporary dependency list before active-state filtering.

The new path keeps the same observable usage propagation while reducing per-export allocation and one dependency traversal/materialization step.

Expected benefit

  • Lower allocation churn during export usage propagation.
  • Less temporary memory and CPU work while collecting active dependencies for large dependency blocks.
image

@github-actions

github-actions Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

📝 Benchmark detail: Open

Name Base (dbbb525) Current Change
10000_big_production-mode_disable-minimize + exec 13.5 s ± 258 ms 13.5 s ± 178 ms -0.01 %
10000_development-mode + exec 886 ms ± 16 ms 878 ms ± 17 ms -0.90 %
10000_development-mode_hmr + stats 167 ms ± 32 ms 162 ms ± 8.9 ms -3.21 %
10000_development-mode_noop-loader + exec 1.97 s ± 195 ms 1.95 s ± 105 ms -0.79 %
10000_production-mode + exec 989 ms ± 30 ms 985 ms ± 17 ms -0.40 %
10000_production-mode_persistent-cold + exec 1.16 s ± 31 ms 1.16 s ± 31 ms +0.03 %
10000_production-mode_persistent-hot + exec 599 ms ± 14 ms 591 ms ± 12 ms -1.40 %
10000_production-mode_source-map + exec 1.15 s ± 29 ms 1.15 s ± 30 ms +0.02 %
arco-pro_development-mode + exec 1.33 s ± 112 ms 1.31 s ± 109 ms -2.01 %
arco-pro_development-mode_hmr + stats 33 ms ± 0.94 ms 34 ms ± 0.37 ms +0.87 %
arco-pro_production-mode + exec 2.37 s ± 105 ms 2.37 s ± 96 ms -0.07 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 2.4 s ± 33 ms 2.43 s ± 143 ms +1.30 %
arco-pro_production-mode_persistent-cold + exec 2.4 s ± 72 ms 2.44 s ± 132 ms +1.68 %
arco-pro_production-mode_persistent-hot + exec 344 ms ± 6.9 ms 343 ms ± 14 ms -0.12 %
arco-pro_production-mode_source-map + exec 2.83 s ± 145 ms 2.79 s ± 83 ms -1.19 %
arco-pro_production-mode_traverse-chunk-modules + exec 2.4 s ± 113 ms 2.41 s ± 143 ms +0.27 %
bundled-threejs_development-mode + exec 182 ms ± 3.5 ms 182 ms ± 5.7 ms -0.11 %
bundled-threejs_production-mode + exec 212 ms ± 8.2 ms 208 ms ± 5.3 ms -1.89 %
large-dyn-imports_development-mode + exec 1.12 s ± 32 ms 1.11 s ± 17 ms -0.96 %
large-dyn-imports_production-mode + exec 1.26 s ± 28 ms 1.26 s ± 35 ms -0.25 %
threejs_development-mode_10x + exec 825 ms ± 45 ms 822 ms ± 53 ms -0.29 %
threejs_development-mode_10x_hmr + stats 109 ms ± 1.2 ms 109 ms ± 4.9 ms -0.22 %
threejs_production-mode_10x + exec 2.82 s ± 18 ms 2.83 s ± 25 ms +0.41 %
threejs_production-mode_10x_persistent-cold + exec 2.97 s ± 40 ms 3.01 s ± 91 ms +1.40 %
threejs_production-mode_10x_persistent-hot + exec 385 ms ± 18 ms 386 ms ± 9.6 ms +0.10 %
threejs_production-mode_10x_source-map + exec 3.57 s ± 37 ms 3.58 s ± 17 ms +0.21 %
10000_big_production-mode_disable-minimize + rss memory 1981 MiB ± 59.9 MiB 1955 MiB ± 46.2 MiB -1.33 %
10000_development-mode + rss memory 593 MiB ± 16.5 MiB 593 MiB ± 11.4 MiB -0.10 %
10000_development-mode_hmr + rss memory 822 MiB ± 34.8 MiB 805 MiB ± 28.6 MiB -2.05 %
10000_development-mode_noop-loader + rss memory 890 MiB ± 15 MiB 890 MiB ± 10.9 MiB +0.07 %
10000_production-mode + rss memory 535 MiB ± 20.6 MiB 538 MiB ± 16 MiB +0.52 %
10000_production-mode_persistent-cold + rss memory 716 MiB ± 13.3 MiB 701 MiB ± 12.1 MiB -2.03 %
10000_production-mode_persistent-hot + rss memory 635 MiB ± 19.5 MiB 619 MiB ± 5.73 MiB -2.61 %
10000_production-mode_source-map + rss memory 526 MiB ± 44 MiB 526 MiB ± 44.4 MiB -0.11 %
arco-pro_development-mode + rss memory 484 MiB ± 14.2 MiB 484 MiB ± 8.59 MiB +0.05 %
arco-pro_development-mode_hmr + rss memory 502 MiB ± 15.6 MiB 501 MiB ± 11.1 MiB -0.15 %
arco-pro_production-mode + rss memory 684 MiB ± 10.1 MiB 679 MiB ± 4.5 MiB -0.71 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 691 MiB ± 21.1 MiB 684 MiB ± 60.4 MiB -1.08 %
arco-pro_production-mode_persistent-cold + rss memory 745 MiB ± 15.3 MiB 739 MiB ± 10.7 MiB -0.86 %
arco-pro_production-mode_persistent-hot + rss memory 380 MiB ± 26.6 MiB 370 MiB ± 21.6 MiB -2.55 %
arco-pro_production-mode_source-map + rss memory 764 MiB ± 30.5 MiB 763 MiB ± 23.5 MiB -0.08 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 686 MiB ± 10.3 MiB 687 MiB ± 20.2 MiB +0.11 %
bundled-threejs_development-mode + rss memory 151 MiB ± 5.51 MiB 154 MiB ± 7.14 MiB +2.43 %
bundled-threejs_production-mode + rss memory 173 MiB ± 3.79 MiB 174 MiB ± 11.3 MiB +0.65 %
large-dyn-imports_development-mode + rss memory 597 MiB ± 13.8 MiB 600 MiB ± 10.8 MiB +0.61 %
large-dyn-imports_production-mode + rss memory 462 MiB ± 9.19 MiB 460 MiB ± 10.2 MiB -0.35 %
threejs_development-mode_10x + rss memory 537 MiB ± 17.9 MiB 542 MiB ± 13.5 MiB +0.76 %
threejs_development-mode_10x_hmr + rss memory 671 MiB ± 8.32 MiB 668 MiB ± 10.5 MiB -0.39 %
threejs_production-mode_10x + rss memory 719 MiB ± 5.18 MiB 716 MiB ± 12.3 MiB -0.46 %
threejs_production-mode_10x_persistent-cold + rss memory 678 MiB ± 14.4 MiB 675 MiB ± 12.6 MiB -0.42 %
threejs_production-mode_10x_persistent-hot + rss memory 474 MiB ± 8.83 MiB 475 MiB ± 9.41 MiB +0.40 %
threejs_production-mode_10x_source-map + rss memory 822 MiB ± 35.3 MiB 834 MiB ± 23.3 MiB +1.52 %

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 marked this pull request as ready for review May 15, 2026 09:51
@LingyuCoder LingyuCoder requested a review from ahabhgk as a code owner May 15, 2026 09:51
Copilot AI review requested due to automatic review settings May 15, 2026 09:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 optimizes export-usage propagation and dependency traversal in the compilation pipeline, targeting hot paths in FlagDependencyUsagePlugin and export usage marking to reduce allocation and redundant work.

Changes:

  • Replaced boxed predicate allocations in ExportInfoData::set_used_conditionally call sites by making the method accept a generic predicate (impl Fn).
  • Optimized collect_active_dependencies to filter active dependencies during traversal instead of materializing and re-scanning dependency IDs.
  • Removed the now-unneeded UsageFilterFnTy type alias.

Reviewed changes

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

Show a summary per file
File Description
crates/rspack_plugin_mf/src/sharing/shared_used_exports_optimizer_plugin.rs Updates export usage marking to avoid boxed predicate allocation.
crates/rspack_plugin_javascript/src/plugin/flag_dependency_usage_plugin.rs Filters active dependencies inline during block traversal and removes boxed predicates in usage marking.
crates/rspack_core/src/exports/utils.rs Removes UsageFilterFnTy alias now that predicates are no longer boxed.
crates/rspack_core/src/exports/exports_info_setter.rs Updates internal usage marking calls to use non-boxed predicates.
crates/rspack_core/src/exports/export_info_setter.rs Makes set_used_conditionally accept a generic predicate (impl Fn) and updates internal call sites.

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

@github-actions

Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing 253e0e2 to fix(stats): preserve sub-millisecond precision in logger time entries (#14049) by pshu

🎉 Size decreased by 4.00KB from 61.96MB to 61.95MB (⬇️0.01%)

@github-actions

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

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

Generated by Rsdoctor GitHub Action

@codspeed-hq

codspeed-hq Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 34 untouched benchmarks
⏩ 25 skipped benchmarks1


Comparing perf/flag-dependency-usage (253e0e2) with main (19ac553)

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.

@LingyuCoder LingyuCoder enabled auto-merge (squash) May 15, 2026 10:05
@LingyuCoder LingyuCoder merged commit c6bcf3b into main May 15, 2026
36 checks passed
@LingyuCoder LingyuCoder deleted the perf/flag-dependency-usage branch May 15, 2026 10:10
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