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

fix(es/minifier): Fix performance issues & bugs #1988

Closed
wants to merge 84 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
70081fb
WIP: Pass &mut to base54 calculator
kdy1 Jul 31, 2021
5f844a2
Update test refs
kdy1 Jul 31, 2021
52bb824
Add a test for performance
kdy1 Jul 31, 2021
a6992f2
Add a test lib
kdy1 Jul 31, 2021
01fe088
Fix chars
kdy1 Jul 31, 2021
b3685af
Split tests
kdy1 Jul 31, 2021
7c068d6
Seems like #1987 is not about mangler
kdy1 Jul 31, 2021
7a9b0cb
debug
kdy1 Jul 31, 2021
24e0208
antd
kdy1 Jul 31, 2021
4ee15a4
Update test refs
kdy1 Jul 31, 2021
e7614fa
Remove logs on release build
kdy1 Jul 31, 2021
d5bc88f
Change log level
kdy1 Jul 31, 2021
ed67891
Change log level
kdy1 Jul 31, 2021
1ed761c
Bump version
kdy1 Jul 31, 2021
edb5ce0
less chaged
kdy1 Jul 31, 2021
6052e62
Add dbg!
kdy1 Jul 31, 2021
55abe27
Fix expr simplifier
kdy1 Jul 31, 2021
69f03a6
Remove dbg!
kdy1 Jul 31, 2021
c597d64
More
kdy1 Aug 1, 2021
ad8daf9
fixup
kdy1 Aug 1, 2021
5235b21
Remove d3
kdy1 Aug 1, 2021
75582aa
Update tets refs
kdy1 Aug 1, 2021
a5f4cb6
Log level
kdy1 Aug 1, 2021
899949a
Don't parse source map if not required
kdy1 Aug 1, 2021
1a5d0ce
Fix infinite loop
kdy1 Aug 1, 2021
b54d069
Depend on ahash
kdy1 Aug 1, 2021
8f06ee7
Remove unused
kdy1 Aug 1, 2021
4557546
Use ahash for analyzer
kdy1 Aug 1, 2021
7ecc020
Small optimization: Ignore nested ids
kdy1 Aug 1, 2021
8e98e79
Add compress/pure.rs
kdy1 Aug 1, 2021
7853c68
Add pure optimizer
kdy1 Aug 1, 2021
f7b4f6a
Use rayon
kdy1 Aug 1, 2021
7fe47d6
WIP: Pure visitor
kdy1 Aug 1, 2021
8e712e5
Bool optimizer is stateless
kdy1 Aug 1, 2021
41319cc
Add ctx for pure
kdy1 Aug 1, 2021
a5e625d
Move more to pure
kdy1 Aug 1, 2021
6d53260
Some threshold for parallel
kdy1 Aug 1, 2021
ac14d76
More pure comparison
kdy1 Aug 1, 2021
0e1f78b
More paralleization
kdy1 Aug 1, 2021
48d6fb8
Parallelize dropping of `""`
kdy1 Aug 1, 2021
4175024
Mark more operations as pure
kdy1 Aug 1, 2021
78854e1
Mark more operations as pure
kdy1 Aug 1, 2021
b97c1d4
Mark `eval_opt_chain` as pure
kdy1 Aug 1, 2021
0f7a022
Mark `concat_str` as pure
kdy1 Aug 1, 2021
814fbd6
Change order
kdy1 Aug 1, 2021
de6a1dd
Disable inling to see timings
kdy1 Aug 1, 2021
24e9ba8
`optimize_arrow_method_prop` is pure
kdy1 Aug 1, 2021
fd38f5c
Less inlining for investigation
kdy1 Aug 1, 2021
0524355
Use better logic for inlining
kdy1 Aug 1, 2021
5b01bee
Reduce deps
kdy1 Aug 2, 2021
ceecbbd
Remove noinline
kdy1 Aug 2, 2021
d6627ce
Use more memory to prevent rehasing
kdy1 Aug 2, 2021
ff2d4ac
Add a test
kdy1 Aug 2, 2021
ec68718
Move
kdy1 Aug 2, 2021
faf2479
Revert issue testing because it's fast
kdy1 Aug 2, 2021
e20695f
Revert pre-allocation
kdy1 Aug 2, 2021
e93c112
Make expr simplifier configurable
kdy1 Aug 2, 2021
3340092
Don't inject vars using expr simplifier
kdy1 Aug 2, 2021
b70fe4d
Change order
kdy1 Aug 2, 2021
598c05c
Don't clone
kdy1 Aug 2, 2021
705e3b6
wasm
kdy1 Aug 2, 2021
b5d87ac
pure optimizer: More parallelization
kdy1 Aug 2, 2021
a6becdf
Increase max par depth
kdy1 Aug 2, 2021
03cc0e5
precompress: Split scopes if possible
kdy1 Aug 2, 2021
aed7c0a
Reduce antd
kdy1 Aug 2, 2021
fbb5fb9
Fix precompress
kdy1 Aug 2, 2021
78dc4e0
Prepare using `done`.
kdy1 Aug 2, 2021
8a08e84
Small cleanup
kdy1 Aug 2, 2021
a472420
Small opt
kdy1 Aug 2, 2021
a0e9dfe
Split marks
kdy1 Aug 2, 2021
02bbe8f
Add Pure.modified_node
kdy1 Aug 2, 2021
c227793
pure optimizer: Track ast modifications
kdy1 Aug 2, 2021
87cbf38
Store mark in pure optimizer
kdy1 Aug 2, 2021
c7dff2b
Use swc globals
kdy1 Aug 2, 2021
7340c2f
Add respan
kdy1 Aug 2, 2021
da38d70
Track from pure optimizer
kdy1 Aug 2, 2021
b81e4b4
optimizer: Track if node is finished
kdy1 Aug 2, 2021
4b669ca
Fix respan impl for ident
kdy1 Aug 2, 2021
31d0adf
Remove reduced antd
kdy1 Aug 2, 2021
12eafd1
Fix tracking of `done`
kdy1 Aug 2, 2021
b4131bc
Add an assertion
kdy1 Aug 2, 2021
314cb0b
Add more assertions & remove mark correctly
kdy1 Aug 2, 2021
70a4978
Add esbuild-three
kdy1 Aug 2, 2021
a243f8a
Better check
kdy1 Aug 2, 2021
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
Prev Previous commit
Next Next commit
Mark more operations as pure
kdy1 committed Aug 1, 2021
commit 78854e15d75973f7b34c1902395ff533baf6f0ce
46 changes: 0 additions & 46 deletions ecmascript/minifier/src/compress/optimize/evaluate.rs
Original file line number Diff line number Diff line change
@@ -950,52 +950,6 @@ impl Optimizer<'_> {
}
}

///
/// - `Object(1) && 1 && 2` => `Object(1) && 2`.
pub(super) fn optimize_bin_and_or(&mut self, e: &mut BinExpr) {
if !self.options.evaluate {
return;
}
if e.left.is_invalid() || e.right.is_invalid() {
return;
}

match e.op {
op!("&&") | op!("||") => {}
_ => return,
}

match &mut *e.left {
Expr::Bin(left) => {
if left.op != e.op {
return;
}
// Remove rhs of lhs if possible.

let v = left.right.as_pure_bool();
if let Known(v) = v {
// As we used as_pure_bool, we can drop it.
if v && e.op == op!("&&") {
self.changed = true;
log::debug!("Removing `b` from `a && b && c` because b is always truthy");

left.right.take();
return;
}

if !v && e.op == op!("||") {
self.changed = true;
log::debug!("Removing `b` from `a || b || c` because b is always falsy");

left.right.take();
return;
}
}
}
_ => return,
}
}

fn eval_opt_chain(&mut self, e: &mut Expr) {
let opt = match e {
Expr::OptChain(e) => e,
2 changes: 0 additions & 2 deletions ecmascript/minifier/src/compress/optimize/mod.rs
Original file line number Diff line number Diff line change
@@ -1510,8 +1510,6 @@ impl VisitMut for Optimizer<'_> {

self.optimize_bin_operator(n);

self.optimize_bin_and_or(n);

self.optimize_null_or_undefined_cmp(n);

if n.op == op!(bin, "+") {
50 changes: 50 additions & 0 deletions ecmascript/minifier/src/compress/pure/evaluate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use super::Pure;
use swc_ecma_ast::*;
use swc_ecma_transforms_base::ext::MapWithMut;
use swc_ecma_utils::{ExprExt, Value::Known};

impl Pure<'_> {
///
/// - `Object(1) && 1 && 2` => `Object(1) && 2`.
pub(super) fn drop_useless_logical_operands(&mut self, e: &mut BinExpr) {
if !self.options.evaluate {
return;
}
if e.left.is_invalid() || e.right.is_invalid() {
return;
}

match e.op {
op!("&&") | op!("||") => {}
_ => return,
}

match &mut *e.left {
Expr::Bin(left) => {
if left.op != e.op {
return;
}
// Remove rhs of lhs if possible.

let v = left.right.as_pure_bool();
if let Known(v) = v {
// As we used as_pure_bool, we can drop it.
if v && e.op == op!("&&") {
log::debug!("Removing `b` from `a && b && c` because b is always truthy");

left.right.take();
return;
}

if !v && e.op == op!("||") {
log::debug!("Removing `b` from `a || b || c` because b is always falsy");

left.right.take();
return;
}
}
}
_ => return,
}
}
}
3 changes: 3 additions & 0 deletions ecmascript/minifier/src/compress/pure/mod.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith};
mod bools;
mod conditionals;
mod ctx;
mod evaluate;
mod strings;

pub(super) fn pure_optimizer<'a>(options: &'a CompressOptions) -> impl 'a + VisitMut + Repeated {
@@ -79,6 +80,8 @@ impl VisitMut for Pure<'_> {
e.visit_mut_children_with(self);

self.compress_cmp_of_typeof_with_lit(e);

self.drop_useless_logical_operands(e);
}

fn visit_mut_cond_expr(&mut self, e: &mut CondExpr) {