Skip to content

Comments

perf(mangler): remove frequencies items if they are unused#18183

Merged
graphite-app[bot] merged 1 commit intomainfrom
01-18-perf_mangler_remove_frequencies_if_there_are_no_symbol_ids
Jan 19, 2026
Merged

perf(mangler): remove frequencies items if they are unused#18183
graphite-app[bot] merged 1 commit intomainfrom
01-18-perf_mangler_remove_frequencies_if_there_are_no_symbol_ids

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Jan 18, 2026

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.

@github-actions github-actions bot added A-minifier Area - Minifier C-performance Category - Solution not expected to change functional behavior, only performance labels Jan 18, 2026
Copy link
Member Author

Dunqing commented Jan 18, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 18, 2026

Merging this PR will improve performance by 50.28%

⚡ 4 improved benchmarks
✅ 34 untouched benchmarks
⏩ 7 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation mangler[react.development.js] 255.6 µs 220.7 µs +15.83%
Simulation mangler[cal.com.tsx] 2.9 ms 2.2 ms +33.18%
Simulation mangler[binder.ts] 710.8 µs 526.3 µs +35.04%
Simulation mangler[RadixUIAdoptionSection.jsx] 13 µs 8.7 µs +50.28%

Comparing 01-18-perf_mangler_remove_frequencies_if_there_are_no_symbol_ids (50f663f) with main (c1c152b)2

Open in CodSpeed

Footnotes

  1. 7 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.

  2. No successful run was found on 01-17-perf_mangler_turn_off_scope_tree_child_ids_for_semanticbuilder (53779b3) during the generation of this report, so main (c1c152b) was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Dunqing Dunqing changed the title perf(mangler): remove frequencies if there are no symbol_ids perf(mangler): remove frequencies items if there are no symbol_ids Jan 19, 2026
@Dunqing Dunqing force-pushed the 01-18-perf_mangler_remove_frequencies_if_there_are_no_symbol_ids branch from a3e2c28 to 50f663f Compare January 19, 2026 02:16
@Dunqing Dunqing force-pushed the 01-17-perf_mangler_turn_off_scope_tree_child_ids_for_semanticbuilder branch from aad5764 to 53779b3 Compare January 19, 2026 02:16
@Dunqing Dunqing changed the title perf(mangler): remove frequencies items if there are no symbol_ids perf(mangler): remove frequencies items if they are unused Jan 19, 2026
@Dunqing Dunqing marked this pull request as ready for review January 19, 2026 02:46
@Dunqing Dunqing requested review from Boshen and sapphi-red January 19, 2026 02:46
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Jan 19, 2026
Copy link
Member

Boshen commented Jan 19, 2026

Merge activity

@graphite-app graphite-app bot changed the base branch from 01-17-perf_mangler_turn_off_scope_tree_child_ids_for_semanticbuilder to graphite-base/18183 January 19, 2026 04:55
@graphite-app graphite-app bot force-pushed the 01-18-perf_mangler_remove_frequencies_if_there_are_no_symbol_ids branch from 50f663f to f738851 Compare January 19, 2026 05:02
@graphite-app graphite-app bot force-pushed the graphite-base/18183 branch from 53779b3 to 727939f Compare January 19, 2026 05:02
@graphite-app graphite-app bot changed the base branch from graphite-base/18183 to main January 19, 2026 05:02
@graphite-app graphite-app bot force-pushed the 01-18-perf_mangler_remove_frequencies_if_there_are_no_symbol_ids branch from f738851 to a425612 Compare January 19, 2026 05:02
@Dunqing Dunqing changed the base branch from main to graphite-base/18183 January 19, 2026 05:24
@Dunqing Dunqing force-pushed the 01-18-perf_mangler_remove_frequencies_if_there_are_no_symbol_ids branch from a425612 to 98612fe Compare January 19, 2026 05:25
@Dunqing Dunqing changed the base branch from graphite-base/18183 to 01-17-perf_mangler_turn_off_scope_tree_child_ids_for_semanticbuilder January 19, 2026 05:25
@Dunqing Dunqing changed the base branch from 01-17-perf_mangler_turn_off_scope_tree_child_ids_for_semanticbuilder to graphite-base/18183 January 19, 2026 05:31
@Dunqing Dunqing force-pushed the 01-18-perf_mangler_remove_frequencies_if_there_are_no_symbol_ids branch from 98612fe to 67ae9c7 Compare January 19, 2026 05:49
@Dunqing Dunqing force-pushed the graphite-base/18183 branch from c61e6d9 to 3c7cd5d Compare January 19, 2026 05:49
@Dunqing Dunqing changed the base branch from graphite-base/18183 to 01-17-perf_mangler_turn_off_scope_tree_child_ids_for_semanticbuilder January 19, 2026 05:49
@graphite-app graphite-app bot changed the base branch from 01-17-perf_mangler_turn_off_scope_tree_child_ids_for_semanticbuilder to graphite-base/18183 January 19, 2026 06:24
@graphite-app graphite-app bot changed the base branch from graphite-base/18183 to main January 19, 2026 06:32
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.
@graphite-app graphite-app bot force-pushed the 01-18-perf_mangler_remove_frequencies_if_there_are_no_symbol_ids branch from 67ae9c7 to 91c143f Compare January 19, 2026 06:32
@graphite-app graphite-app bot merged commit 91c143f into main Jan 19, 2026
21 checks passed
@graphite-app graphite-app bot deleted the 01-18-perf_mangler_remove_frequencies_if_there_are_no_symbol_ids branch January 19, 2026 06:38
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jan 19, 2026
robobun pushed a commit to oven-sh/bun that referenced this pull request Jan 19, 2026
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]>
graphite-app bot pushed a commit that referenced this pull request Jan 19, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minifier C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants