perf(es/minifier): Make more passes parallel (#4821)

This commit is contained in:
Donny/강동윤 2022-05-27 15:48:08 +09:00 committed by GitHub
parent 01e90a650c
commit 4b27df9f12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 58 deletions

View File

@ -1,6 +1,6 @@
use swc_common::{util::take::Take, Spanned, DUMMY_SP};
use swc_ecma_ast::*;
use swc_ecma_utils::{prepend_stmt, undefined, StmtExt, StmtLike};
use swc_ecma_utils::{undefined, StmtExt, StmtLike};
use swc_ecma_visit::{noop_visit_type, Visit, VisitWith};
use super::Optimizer;
@ -41,58 +41,6 @@ where
}
}
pub(super) fn merge_else_if(&mut self, s: &mut IfStmt) {
if let Some(Stmt::If(IfStmt {
span: span_of_alt,
test: test_of_alt,
cons: cons_of_alt,
alt: Some(alt_of_alt),
..
})) = s.alt.as_deref_mut()
{
match &**cons_of_alt {
Stmt::Return(..) | Stmt::Continue(ContinueStmt { label: None, .. }) => {}
_ => return,
}
match &mut **alt_of_alt {
Stmt::Block(..) => {}
Stmt::Expr(..) => {
*alt_of_alt = Box::new(Stmt::Block(BlockStmt {
span: DUMMY_SP,
stmts: vec![*alt_of_alt.take()],
}));
}
_ => {
return;
}
}
self.changed = true;
report_change!("if_return: Merging `else if` into `else`");
match &mut **alt_of_alt {
Stmt::Block(alt_of_alt) => {
prepend_stmt(
&mut alt_of_alt.stmts,
Stmt::If(IfStmt {
span: *span_of_alt,
test: test_of_alt.take(),
cons: cons_of_alt.take(),
alt: None,
}),
);
}
_ => {
unreachable!()
}
}
s.alt = Some(alt_of_alt.take());
}
}
pub(super) fn merge_if_returns(
&mut self,
stmts: &mut Vec<Stmt>,

View File

@ -2039,8 +2039,6 @@ where
self.negate_if_stmt(n);
self.merge_nested_if(n);
self.merge_else_if(n);
}
#[cfg_attr(feature = "debug", tracing::instrument(skip_all))]

View File

@ -1,5 +1,6 @@
use swc_common::{util::take::Take, DUMMY_SP};
use swc_ecma_ast::*;
use swc_ecma_utils::prepend_stmt;
use super::Pure;
use crate::compress::util::{is_fine_for_if_cons, negate};
@ -125,4 +126,56 @@ impl Pure<'_> {
*stmts = new;
}
pub(super) fn merge_else_if(&mut self, s: &mut IfStmt) {
if let Some(Stmt::If(IfStmt {
span: span_of_alt,
test: test_of_alt,
cons: cons_of_alt,
alt: Some(alt_of_alt),
..
})) = s.alt.as_deref_mut()
{
match &**cons_of_alt {
Stmt::Return(..) | Stmt::Continue(ContinueStmt { label: None, .. }) => {}
_ => return,
}
match &mut **alt_of_alt {
Stmt::Block(..) => {}
Stmt::Expr(..) => {
*alt_of_alt = Box::new(Stmt::Block(BlockStmt {
span: DUMMY_SP,
stmts: vec![*alt_of_alt.take()],
}));
}
_ => {
return;
}
}
self.changed = true;
report_change!("if_return: Merging `else if` into `else`");
match &mut **alt_of_alt {
Stmt::Block(alt_of_alt) => {
prepend_stmt(
&mut alt_of_alt.stmts,
Stmt::If(IfStmt {
span: *span_of_alt,
test: test_of_alt.take(),
cons: cons_of_alt.take(),
alt: None,
}),
);
}
_ => {
unreachable!()
}
}
s.alt = Some(alt_of_alt.take());
}
}
}

View File

@ -459,6 +459,8 @@ impl VisitMut for Pure<'_> {
s.visit_mut_children_with(self);
self.optimize_expr_in_bool_ctx(&mut s.test, false);
self.merge_else_if(s);
}
fn visit_mut_member_expr(&mut self, e: &mut MemberExpr) {

View File

@ -216,7 +216,6 @@ export/name_cache_mangle_export_default_class/input.js
export/name_cache_mangle_export_default_function/input.js
export/name_cache_mangle_local_import_and_export_aliases/input.js
functions/duplicate_arg_var/input.js
functions/empty_body/input.js
functions/hoist_funs/input.js
functions/hoist_funs_strict/input.js
functions/inline_1/input.js

View File

@ -1,4 +1,3 @@
function f() {
function noop() {}
return noop;
return function noop() {};
}