Skip to content

Commit ccb6eb8

Browse files
authoredMar 24, 2025
perf(es/minifier): Process cons and alt of IfStmt in parallel (#10262)
**Description:** Typically, those are large enough to process in parallel.
1 parent 50c62d1 commit ccb6eb8

File tree

1 file changed

+25
-8
lines changed
  • crates/swc_ecma_minifier/src/compress/pure

1 file changed

+25
-8
lines changed
 

‎crates/swc_ecma_minifier/src/compress/pure/mod.rs

+25-8
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ impl Pure<'_> {
181181
node.visit_mut_with(v);
182182
});
183183
}
184+
185+
fn visit_par_ref<N>(&mut self, nodes: &mut [&mut N])
186+
where
187+
N: for<'aa> VisitMutWith<Pure<'aa>> + Send + Sync,
188+
{
189+
self.maybe_par(0, nodes, |v, node| {
190+
node.visit_mut_with(v);
191+
});
192+
}
184193
}
185194

186195
impl VisitMut for Pure<'_> {
@@ -706,16 +715,24 @@ impl VisitMut for Pure<'_> {
706715
fn visit_mut_if_stmt(&mut self, s: &mut IfStmt) {
707716
s.test.visit_mut_with(self);
708717

709-
{
710-
let ctx = Ctx {
711-
preserve_block: false,
712-
..self.ctx
713-
};
714-
s.cons.visit_mut_with(&mut *self.with_ctx(ctx));
718+
match &mut s.alt {
719+
Some(alt) => {
720+
let ctx = Ctx {
721+
preserve_block: false,
722+
..self.ctx
723+
};
724+
self.with_ctx(ctx)
725+
.visit_par_ref(&mut [&mut *s.cons, &mut **alt]);
726+
}
727+
None => {
728+
let ctx = Ctx {
729+
preserve_block: false,
730+
..self.ctx
731+
};
732+
s.cons.visit_mut_with(&mut *self.with_ctx(ctx));
733+
}
715734
}
716735

717-
s.alt.visit_mut_with(self);
718-
719736
self.optimize_expr_in_bool_ctx(&mut s.test, false);
720737

721738
self.merge_else_if(s);

0 commit comments

Comments
 (0)