Skip to content

Commit 0279914

Browse files
authored
perf(es/renamer): Reduce time complexity in case of conflict (#10749)
1 parent 1eace01 commit 0279914

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

.changeset/five-comics-deliver.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_core: patch
3+
swc_ecma_transforms_base: patch
4+
---
5+
6+
perf(es/renamer): Reduce time complexity in case of conflict

crates/swc_ecma_transforms_base/src/rename/analyzer/scope.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
use indexmap::IndexSet;
1010
#[cfg(feature = "concurrent-renamer")]
1111
use rayon::prelude::*;
12-
use rustc_hash::{FxHashSet, FxHasher};
12+
use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
1313
use swc_atoms::{atom, Atom};
1414
use swc_common::{util::take::Take, Mark, SyntaxContext};
1515
use swc_ecma_ast::*;
@@ -146,6 +146,7 @@ impl Scope {
146146
) where
147147
R: Renamer,
148148
{
149+
let mut latest_n = FxHashMap::default();
149150
let mut n = 0;
150151

151152
for id in queue {
@@ -159,7 +160,7 @@ impl Scope {
159160
}
160161

161162
if R::RESET_N {
162-
n = 0;
163+
n = latest_n.get(&id.0).copied().unwrap_or(0);
163164
}
164165

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

177179
reverse.push_entry(sym.clone(), id.clone());
178180
to.insert(id, sym);

0 commit comments

Comments
 (0)