perf(mangler): remove frequencies items if they are unused#18183
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
Merging this PR will improve performance by 50.28%
Performance Changes
Comparing Footnotes
|
frequencies if there are no symbol_idsfrequencies items if there are no symbol_ids
a3e2c28 to
50f663f
Compare
aad5764 to
53779b3
Compare
frequencies items if there are no symbol_idsfrequencies items if they are unused
Merge activity
|
50f663f to
f738851
Compare
53779b3 to
727939f
Compare
f738851 to
a425612
Compare
a425612 to
98612fe
Compare
98612fe to
67ae9c7
Compare
c61e6d9 to
3c7cd5d
Compare
Remove the `frequencies` item that has no symbol_id, which means the slot doesn't have a symbol that needs to be renamed. This can prevent the construction of a never-used name.
67ae9c7 to
91c143f
Compare
In MinifyRenamer, avoid generating names for slots where the symbol use count is zero. These represent declared symbols that are never actually used (e.g., tree-shaken away or declared but not referenced). We filter out zero-count slots before adding to the sorted array, avoiding unnecessary sorting and iteration overhead. This is particularly beneficial when nested scopes are tree-shaken, as their pre-allocated symbol slots would otherwise still be processed. Ported from oxc: oxc-project/oxc#18183 Co-Authored-By: Claude Opus 4.5 <[email protected]>
…uency slots (#18225) #18183 introduced a bug when removing empty frequency slots. The code used `truncate` after sorting: ```rust frequencies.sort_unstable_by_key(|x| std::cmp::Reverse(x.frequency)); if let Some(idx) = frequencies.iter().position(|x| x.symbol_ids.is_empty()) { frequencies.truncate(idx); } ``` The problem is that `sort_unstable_by_key` doesn't guarantee order for items with equal keys. When multiple slots have `frequency: 0`, some have symbols (that need renaming but have no references), and some are empty. Since the sort order is unstable, an empty slot could appear **before** a non-empty slot, and `truncate` would incorrectly remove valid slots. This fix uses `retain` instead, and moves it before the sort for better efficiency (sorting fewer elements): ```rust frequencies.retain(|x| !x.symbol_ids.is_empty()); frequencies.sort_unstable_by_key(|x| std::cmp::Reverse(x.frequency)); ``` Note for reviewer: I've locally tested in the `monitor-oxc`; there is no naming collision after this.

Remove the
frequenciesitem that has no symbol_id, which means the slot doesn't have a symbol that needs to be renamed. This can prevent the construction of a never-used name.