perf(minifier): take return argument directly when converting arrow fn (#26830)

Co-authored-by: Cameron Clark <cameron.clark@hey.com>
This commit is contained in:
ArmanoandCameron Clark authored and GitHub committed 2026-09-22 11:24:19 +00:00
1 parent 929e154c0c
commit de8af47874
3 files changed
+16 -20

No files matched your search

+1 -1
View File
@@ -631,7 +631,7 @@ impl<'a> Traverse<'a> for PeepholeOptimizations {
Self::remove_unused_assignment_expr(expr, ctx);
}
Expression::SequenceExpression(_) => Self::remove_sequence_expression(expr, ctx),
Expression::ArrowFunctionExpression(e) => Self::substitute_arrow_expression(e, ctx),
Expression::ArrowFunctionExpression(e) => Self::substitute_arrow_expression(e),
Expression::FunctionExpression(e) => Self::try_remove_name_from_functions(e, ctx),
Expression::ClassExpression(e) => Self::try_remove_name_from_classes(e, ctx),
Expression::NewExpression(e) => {
@@ -199,16 +199,12 @@ impl<'a> PeepholeOptimizations {
}
/// `() => { return foo })` -> `() => foo`
pub fn substitute_arrow_expression(
arrow_expr: &mut ArrowFunctionExpression<'a>,
ctx: &TraverseCtx<'a>,
) {
pub fn substitute_arrow_expression(arrow_expr: &mut ArrowFunctionExpression<'a>) {
if let Some(body) = arrow_expr.get_function_body_mut()
&& body.directives.is_empty()
&& body.statements.len() == 1
&& let Statement::ReturnStatement(return_statement) = &mut body.statements[0]
&& let Some(expr) =
return_statement.argument.as_mut().map(|argument| argument.take_in(ctx))
&& let Some(expr) = return_statement.argument.take()
{
arrow_expr.body = ArrowFunctionBody::from(expr);
}
@@ -5,9 +5,9 @@ checker.ts:
sys deallocs: 122
sys alloc bytes: 14996287 # 15.00 MB
sys peak growth: 10169560 # 10.17 MB
arena allocs: 56215
arena allocs: 56184
arena reallocs: 5084
arena size: 16317648 # 16.32 MB
arena size: 16316976 # 16.32 MB
App.tsx:
file size: 415342 # 415.34 kB
@@ -16,9 +16,9 @@ App.tsx:
sys deallocs: 61
sys alloc bytes: 2128539 # 2.13 MB
sys peak growth: 1612427 # 1.61 MB
arena allocs: 7488
arena allocs: 7452
arena reallocs: 920
arena size: 2684416 # 2.68 MB
arena size: 2683840 # 2.68 MB
RadixUIAdoptionSection.jsx:
file size: 2520 # 2.52 kB
@@ -27,9 +27,9 @@ RadixUIAdoptionSection.jsx:
sys deallocs: 21
sys alloc bytes: 17400 # 17.40 kB
sys peak growth: 11628 # 11.63 kB
arena allocs: 16
arena allocs: 15
arena reallocs: 0
arena size: 35120 # 35.12 kB
arena size: 35104 # 35.10 kB
pdf.mjs:
file size: 567296 # 567.30 kB
@@ -38,9 +38,9 @@ pdf.mjs:
sys deallocs: 2427
sys alloc bytes: 5313795 # 5.31 MB
sys peak growth: 3693355 # 3.69 MB
arena allocs: 19523
arena allocs: 19499
arena reallocs: 2574
arena size: 5708848 # 5.71 MB
arena size: 5708368 # 5.71 MB
antd.js:
file size: 6686316 # 6.69 MB
@@ -51,7 +51,7 @@ antd.js:
sys peak growth: 19934725 # 19.93 MB
arena allocs: 181686
arena reallocs: 34406
arena size: 43045192 # 43.05 MB
arena size: 43044360 # 43.04 MB
binder.ts:
file size: 193077 # 193.08 kB
@@ -60,9 +60,9 @@ binder.ts:
sys deallocs: 33
sys alloc bytes: 963008 # 963.01 kB
sys peak growth: 657404 # 657.40 kB
arena allocs: 2922
arena allocs: 2919
arena reallocs: 244
arena size: 1074976 # 1.07 MB
arena size: 1074912 # 1.07 MB
kitchen-sink.tsx:
file size: 732898 # 732.90 kB
@@ -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: 31152
arena allocs: 31129
arena reallocs: 3012
arena size: 8444304 # 8.44 MB
arena size: 8443808 # 8.44 MB