From 49d2a8df23bef320170866ae38a3c8a64a42c8c1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 20 Mar 2025 08:51:45 -0500 Subject: [PATCH] LibJS: Elide empty lexical environments for parameter evaluation If all the parameter default values end up in locals, the lexical environment we create to hold them would never be used for anything, and so we can elide it and avoid the GC work. --- Libraries/LibJS/Bytecode/Generator.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Libraries/LibJS/Bytecode/Generator.cpp b/Libraries/LibJS/Bytecode/Generator.cpp index 40ceadb568c..87b3687a9c4 100644 --- a/Libraries/LibJS/Bytecode/Generator.cpp +++ b/Libraries/LibJS/Bytecode/Generator.cpp @@ -33,7 +33,15 @@ Generator::Generator(VM& vm, GC::Ptr function, M CodeGenerationErrorOr Generator::emit_function_declaration_instantiation(ECMAScriptFunctionObject const& function) { if (function.m_has_parameter_expressions) { - emit(); + bool has_non_local_parameters = false; + for (auto const& parameter_name : function.m_parameter_names) { + if (parameter_name.value == ECMAScriptFunctionObject::ParameterIsLocal::No) { + has_non_local_parameters = true; + break; + } + } + if (has_non_local_parameters) + emit(); } for (auto const& parameter_name : function.m_parameter_names) {