Open kdy1 opened 2 years ago
I think this can be done by exposing shallow optimizers from swc_ecma_transforms_optimization
, but with a comment that says it's not considered as a public API.
@Austaras How do you think about this?
What shallow optimizer?
Code except visit_mut_children_with(self)
, e.g.
That seems to be good enough for expr_simplier
What would be the potential performance impact of check is global var? It seems like need ctxt.outer()
which need to acquire global lock
We can pre-compute SyntaxContext
and compare it with Ident.span.ctxt
Come to revisit this, I believe proper solution for expr_simplifier
would be separate it into two parts -- AST mangle and evaluate. Former part should be run only once before all pass, and later one should be merged with pure
. I don't know if that would be a break change for the JS side.
I think it's good way to go and I don't think it's a breaking change for js side
Currently, those passes only use the main thread, but those passes are mostly stateless and we need to move logic to minifier anyway, because of side effect check.
I profiled it, and those two passes used 7.5% of main thread execution time
cc @Austaras