Skip to content

Commit

Permalink
perf(es/minifier): Cache var_or_default calls (#9909)
Browse files Browse the repository at this point in the history
**Description:**

This is a simple fix to ensure that we hash the `Id` only once.
  • Loading branch information
kdy1 authored Jan 21, 2025
1 parent eb84548 commit 4a3be8d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .changeset/six-rats-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_core: patch
swc_ecma_minifier: patch
---

perf(es/minifier): Cache `var_or_default` calls
18 changes: 8 additions & 10 deletions crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,15 @@ where
};

if let Some(left) = left {
let v = self.data.var_or_default(left.clone());
for id in collect_infects_from(
&n.right,
AliasConfig {
marks: self.marks,
..Default::default()
},
) {
self.data
.var_or_default(left.clone())
.add_infects_to(id.clone());
v.add_infects_to(id.clone());
}
}
}
Expand Down Expand Up @@ -743,16 +742,15 @@ where
self.used_recursively.remove(&id);

{
let v = self.data.var_or_default(id);
for id in collect_infects_from(
&n.function,
AliasConfig {
marks: self.marks,
..Default::default()
},
) {
self.data
.var_or_default(n.ident.to_id())
.add_infects_to(id.clone());
v.add_infects_to(id.clone());
}
}
}
Expand All @@ -770,14 +768,15 @@ where
n.visit_children_with(self);

{
let v = self.data.var_or_default(n_id.to_id());
for id in collect_infects_from(
&n.function,
AliasConfig {
marks: self.marks,
..Default::default()
},
) {
self.data.var_or_default(n_id.to_id()).add_infects_to(id);
v.add_infects_to(id);
}
}
self.used_recursively.remove(&n_id.to_id());
Expand Down Expand Up @@ -1262,16 +1261,15 @@ where

for decl in &n.decls {
if let (Pat::Ident(var), Some(init)) = (&decl.name, decl.init.as_deref()) {
let v = self.data.var_or_default(var.to_id());
for id in collect_infects_from(
init,
AliasConfig {
marks: self.marks,
..Default::default()
},
) {
self.data
.var_or_default(var.to_id())
.add_infects_to(id.clone());
v.add_infects_to(id.clone());
}
}
}
Expand Down

0 comments on commit 4a3be8d

Please sign in to comment.