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(es/minifier): Cache var_or_default calls #9909

Merged
merged 2 commits into from
Jan 21, 2025
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/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
Loading