perf: optimize flag dependency usage#14052
Conversation
|
📝 Benchmark detail: Open
Base persistent cache hit rate:
|
There was a problem hiding this comment.
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_conditionallycall sites by making the method accept a generic predicate (impl Fn). - Optimized
collect_active_dependenciesto filter active dependencies during traversal instead of materializing and re-scanning dependency IDs. - Removed the now-unneeded
UsageFilterFnTytype 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.
📦 Binary Size-limit
🎉 Size decreased by 4.00KB from 61.96MB to 61.95MB (⬇️0.01%) |
Rsdoctor Bundle Diff AnalysisFound 6 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
Merging this PR will not alter performance
Comparing Footnotes
|
What changed
set_used_conditionallygeneric over the predicate.FlagDependencyUsagePlugininstead of first materializing all dependency ids and scanning them again.Why this should improve performance
FlagDependencyUsagePluginscales 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