mirror of
https://github.com/aphrody-labs/oxc.git
synced 2026-10-17 21:07:02 +00:00
perf(minifier): optimize unused expression removal in minimize_if (#27545)
If minimized expression can be removed fold it to `;` without waiting
for next pass or other minifications to clean this code path
eg. folds `if (0) {}` to `;` instead of first folding it to `0;`
This commit is contained in:
1 parent
7730e14c8e
commit
cd1c192c45
2 files changed
+9
-4
No files matched your search
@@ -20,8 +20,13 @@ impl<'a> PeepholeOptimizations {
|
||||
ctx.replace_statement_with(stmt, |stmt, ctx| {
|
||||
let Statement::IfStatement(if_stmt) = stmt else { unreachable!() };
|
||||
let IfStatement { mut test, span, .. } = if_stmt.unbox();
|
||||
Self::remove_unused_expression(&mut test, ctx);
|
||||
Statement::new_expression_statement(span, test, ctx)
|
||||
if Self::remove_unused_expression(&mut test, ctx) {
|
||||
// `if (0) {}` => `;`
|
||||
ctx.drop_expression(&test);
|
||||
Statement::new_empty_statement(span, ctx)
|
||||
} else {
|
||||
Statement::new_expression_statement(span, test, ctx)
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ App.tsx:
|
||||
sys deallocs: 61
|
||||
sys alloc bytes: 2128539 # 2.13 MB
|
||||
sys peak growth: 1612427 # 1.61 MB
|
||||
arena allocs: 7727
|
||||
arena allocs: 7726
|
||||
arena reallocs: 920
|
||||
arena size: 2782336 # 2.78 MB
|
||||
|
||||
@@ -71,6 +71,6 @@ kitchen-sink.tsx:
|
||||
sys deallocs: 1854
|
||||
sys alloc bytes: 5304252 # 5.30 MB
|
||||
sys peak growth: 3707425 # 3.71 MB
|
||||
arena allocs: 31107
|
||||
arena allocs: 31106
|
||||
arena reallocs: 3012
|
||||
arena size: 8461040 # 8.46 MB
|
||||
Reference in new issue
Block a user