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): Skip complex inline operations if possible #9972

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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/quick-needles-sing.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): Skip complex inline operations if possible
9 changes: 4 additions & 5 deletions crates/swc_ecma_minifier/src/compress/optimize/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ impl Optimizer<'_> {
&& !usage.used_as_ref
{
if let Expr::Array(arr) = init {
self.vars.inline_with_multi_replacer(arr);
inlined_into_init = true;

if arr.elems.len() < 32
&& arr.elems.iter().all(|e| match e {
Some(ExprOrSpread { spread: None, expr }) => match &**expr {
Expand All @@ -119,6 +116,8 @@ impl Optimizer<'_> {
_ => false,
})
{
inlined_into_init = true;
self.vars.inline_with_multi_replacer(arr);
report_change!(
"inline: Decided to store '{}{:?}' for array access",
ident.sym,
Expand Down Expand Up @@ -656,8 +655,6 @@ impl Optimizer<'_> {
// Inline very simple functions.
match decl {
Decl::Fn(f) if self.options.inline >= 2 && f.ident.sym != *"arguments" => {
self.vars.inline_with_multi_replacer(&mut f.function.body);

if let Some(body) = &f.function.body {
if !usage.used_recursively
// only callees can be inlined multiple times
Expand All @@ -683,6 +680,8 @@ impl Optimizer<'_> {
f.ident.ctxt
);

self.vars.inline_with_multi_replacer(&mut f.function.body);

for i in collect_infects_from(
&f.function,
AliasConfig::default()
Expand Down
Loading