Skip to content

Commit

Permalink
perf(es/minifier): Adjust parallel threshold (#9872)
Browse files Browse the repository at this point in the history
**Description:**

I profiled each one each time by using `--save-baseline` and `--baseline`, and selected the options that produces the best result.
  • Loading branch information
kdy1 authored Jan 13, 2025
1 parent 46e3d77 commit d5d856c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
7 changes: 7 additions & 0 deletions .changeset/tasty-mugs-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
swc_ecma_minifier: minor
swc_core: minor
swc_ecma_transforms_optimization: minor
---

perf(es/minifier): Make `Finalizer` more parallel
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/compress/pure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl Pure<'_> {
where
N: for<'aa> VisitMutWith<Pure<'aa>> + Send + Sync,
{
self.maybe_par(cpu_count(), nodes, |v, node| {
self.maybe_par(cpu_count() * 8, nodes, |v, node| {
node.visit_mut_with(v);
});
}
Expand Down
14 changes: 7 additions & 7 deletions crates/swc_ecma_minifier/src/pass/precompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use swc_ecma_transforms_base::perf::{Parallel, ParallelExt};
use swc_ecma_utils::{ExprCtx, ExprExt, Value::Known};
use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith};

use crate::CPU_COUNT;
use crate::HEAVY_TASK_PARALLELS;

/// Optimizer invoked before invoking compressor.
///
Expand Down Expand Up @@ -60,37 +60,37 @@ impl VisitMut for PrecompressOptimizer {
}

fn visit_mut_stmts(&mut self, n: &mut Vec<Stmt>) {
self.maybe_par(*CPU_COUNT, n, |v, n| {
self.maybe_par(*HEAVY_TASK_PARALLELS, n, |v, n| {
n.visit_mut_with(v);
});
}

fn visit_mut_module_items(&mut self, n: &mut Vec<ModuleItem>) {
self.maybe_par(*CPU_COUNT, n, |v, n| {
self.maybe_par(*HEAVY_TASK_PARALLELS, n, |v, n| {
n.visit_mut_with(v);
});
}

fn visit_mut_exprs(&mut self, n: &mut Vec<Box<Expr>>) {
self.maybe_par(*CPU_COUNT, n, |v, n| {
self.maybe_par(*HEAVY_TASK_PARALLELS, n, |v, n| {
n.visit_mut_with(v);
});
}

fn visit_mut_opt_vec_expr_or_spreads(&mut self, n: &mut Vec<Option<ExprOrSpread>>) {
self.maybe_par(*CPU_COUNT, n, |v, n| {
self.maybe_par(*HEAVY_TASK_PARALLELS, n, |v, n| {
n.visit_mut_with(v);
});
}

fn visit_mut_expr_or_spreads(&mut self, n: &mut Vec<ExprOrSpread>) {
self.maybe_par(*CPU_COUNT, n, |v, n| {
self.maybe_par(*HEAVY_TASK_PARALLELS, n, |v, n| {
n.visit_mut_with(v);
});
}

fn visit_mut_var_declarators(&mut self, n: &mut Vec<VarDeclarator>) {
self.maybe_par(*CPU_COUNT, n, |v, n| {
self.maybe_par(*HEAVY_TASK_PARALLELS, n, |v, n| {
n.visit_mut_with(v);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1219,31 +1219,31 @@ impl VisitMut for Remover {
}

fn visit_mut_prop_or_spreads(&mut self, n: &mut Vec<PropOrSpread>) {
self.maybe_par(cpu_count(), n, |v, n| {
self.maybe_par(cpu_count() * 8, n, |v, n| {
n.visit_mut_with(v);
})
}

fn visit_mut_expr_or_spreads(&mut self, n: &mut Vec<ExprOrSpread>) {
self.maybe_par(cpu_count(), n, |v, n| {
self.maybe_par(cpu_count() * 8, n, |v, n| {
n.visit_mut_with(v);
})
}

fn visit_mut_opt_vec_expr_or_spreads(&mut self, n: &mut Vec<Option<ExprOrSpread>>) {
self.maybe_par(cpu_count(), n, |v, n| {
self.maybe_par(cpu_count() * 8, n, |v, n| {
n.visit_mut_with(v);
})
}

fn visit_mut_exprs(&mut self, n: &mut Vec<Box<Expr>>) {
self.maybe_par(cpu_count(), n, |v, n| {
self.maybe_par(cpu_count() * 8, n, |v, n| {
n.visit_mut_with(v);
})
}

fn visit_mut_var_declarators(&mut self, n: &mut Vec<VarDeclarator>) {
self.maybe_par(cpu_count(), n, |v, n| {
self.maybe_par(cpu_count() * 8, n, |v, n| {
n.visit_mut_with(v);
})
}
Expand All @@ -1261,7 +1261,7 @@ impl Remover {

let mut new_stmts = Vec::with_capacity(stmts.len());

self.maybe_par(cpu_count(), &mut *stmts, |visitor, stmt| {
self.maybe_par(cpu_count() * 8, &mut *stmts, |visitor, stmt| {
visitor.normal_block = true;
stmt.visit_mut_with(visitor);
});
Expand Down
12 changes: 6 additions & 6 deletions crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ impl TreeShaker {
}
}

self.visit_mut_par(cpu_count(), stmts);
self.visit_mut_par(cpu_count() * 8, stmts);

stmts.retain(|s| match s.as_stmt() {
Some(Stmt::Empty(..)) => false,
Expand Down Expand Up @@ -845,11 +845,11 @@ impl VisitMut for TreeShaker {
}

fn visit_mut_expr_or_spreads(&mut self, n: &mut Vec<ExprOrSpread>) {
self.visit_mut_par(cpu_count(), n);
self.visit_mut_par(cpu_count() * 8, n);
}

fn visit_mut_exprs(&mut self, n: &mut Vec<Box<Expr>>) {
self.visit_mut_par(cpu_count(), n);
self.visit_mut_par(cpu_count() * 8, n);
}

fn visit_mut_for_head(&mut self, n: &mut ForHead) {
Expand Down Expand Up @@ -947,11 +947,11 @@ impl VisitMut for TreeShaker {
}

fn visit_mut_opt_vec_expr_or_spreads(&mut self, n: &mut Vec<Option<ExprOrSpread>>) {
self.visit_mut_par(cpu_count(), n);
self.visit_mut_par(cpu_count() * 8, n);
}

fn visit_mut_prop_or_spreads(&mut self, n: &mut Vec<PropOrSpread>) {
self.visit_mut_par(cpu_count(), n);
self.visit_mut_par(cpu_count() * 8, n);
}

fn visit_mut_script(&mut self, m: &mut Script) {
Expand Down Expand Up @@ -1095,7 +1095,7 @@ impl VisitMut for TreeShaker {
}

fn visit_mut_var_declarators(&mut self, n: &mut Vec<VarDeclarator>) {
self.visit_mut_par(cpu_count(), n);
self.visit_mut_par(cpu_count() * 8, n);

n.retain(|v| {
if v.name.is_invalid() {
Expand Down

0 comments on commit d5d856c

Please sign in to comment.