Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(mangler): use sort_unstable_by_key instead of sort_by #5948

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions crates/oxc_mangler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl Mangler {
let generate_name = if self.options.debug { debug_name } else { base54 };
let mut count = 0;
for _ in 0..total_number_of_slots {
names.push(loop {
let name = loop {
let name = generate_name(count);
count += 1;
// Do not mangle keywords and unresolved references
Expand All @@ -140,7 +140,8 @@ impl Mangler {
{
break name;
}
});
};
names.push(name);
}

// Group similar symbols for smaller gzipped file
Expand Down Expand Up @@ -173,7 +174,7 @@ impl Mangler {
// sorting by slot enables us to sort by the order at which the vars first appear in the source
// (this is possible because the slots are discovered currently in a DFS method which is the same order
// as variables appear in the source code)
symbols_renamed_in_this_batch.sort_by(|a, b| a.slot.cmp(&b.slot));
symbols_renamed_in_this_batch.sort_unstable_by_key(|a| a.slot);

// here we just zip the iterator of symbols to rename with the iterator of new names for the next for loop
let symbols_to_rename_with_new_names =
Expand Down Expand Up @@ -209,7 +210,7 @@ impl Mangler {
symbol_table.get_resolved_reference_ids(symbol_id).len();
frequencies[index].symbol_ids.push(symbol_id);
}
frequencies.sort_by_key(|x| (std::cmp::Reverse(x.frequency)));
frequencies.sort_unstable_by_key(|x| std::cmp::Reverse(x.frequency));
frequencies
}
}
Expand Down