Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions .changeset/five-comics-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_core: patch
swc_ecma_transforms_base: patch
---

perf(es/renamer): Reduce time complexity in case of conflict
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
use indexmap::IndexSet;
#[cfg(feature = "concurrent-renamer")]
use rayon::prelude::*;
use rustc_hash::{FxHashSet, FxHasher};
use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
use swc_atoms::{atom, Atom};
use swc_common::{util::take::Take, Mark, SyntaxContext};
use swc_ecma_ast::*;
Expand Down Expand Up @@ -146,6 +146,7 @@ impl Scope {
) where
R: Renamer,
{
let mut latest_n = FxHashMap::default();
let mut n = 0;

for id in queue {
Expand All @@ -159,7 +160,7 @@ impl Scope {
}

if R::RESET_N {
n = 0;
n = latest_n.get(&id.0).copied().unwrap_or(0);
}

loop {
Expand All @@ -173,6 +174,7 @@ impl Scope {
if cfg!(debug_assertions) {
debug!("Renaming `{}{:?}` to `{}`", id.0, id.1, sym);
}
latest_n.insert(id.0.clone(), n);

reverse.push_entry(sym.clone(), id.clone());
to.insert(id, sym);
Expand Down
Loading