mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
LibJS: Use local variables to store function parameters in some cases
Using local variables to store function parameters makes Kraken tests run 7-10% faster. For now this optimization is limited to only be applied if: - Parameter does not use destructuring assignment - None of the function params has default value - There is no access to "arguments" variable inside function body
This commit is contained in:
parent
2e81cc4cf7
commit
b1af91d8c4
Notes:
sideshowbarker
2024-07-17 00:47:29 +09:00
Author: https://github.com/kalenikaliaksandr
Commit: b1af91d8c4
Pull-request: https://github.com/SerenityOS/serenity/pull/19858
2 changed files with 28 additions and 6 deletions
|
@ -77,9 +77,15 @@ public:
|
|||
{
|
||||
ScopePusher scope_pusher(parser, &function_body, ScopeLevel::FunctionTopLevel, ScopeType::Function);
|
||||
scope_pusher.m_function_parameters = parameters;
|
||||
|
||||
auto has_parameters_with_default_values = false;
|
||||
for (auto& parameter : parameters) {
|
||||
parameter.binding.visit(
|
||||
[&](Identifier const& identifier) {
|
||||
if (parameter.default_value)
|
||||
has_parameters_with_default_values = true;
|
||||
scope_pusher.register_identifier(identifier);
|
||||
scope_pusher.m_function_parameters_candidates_for_local_variables.set(identifier.string());
|
||||
scope_pusher.m_forbidden_lexical_names.set(identifier.string());
|
||||
},
|
||||
[&](NonnullRefPtr<BindingPattern const> const& binding_pattern) {
|
||||
|
@ -89,6 +95,11 @@ public:
|
|||
}));
|
||||
});
|
||||
}
|
||||
|
||||
if (has_parameters_with_default_values) {
|
||||
scope_pusher.m_function_parameters_candidates_for_local_variables.clear();
|
||||
}
|
||||
|
||||
return scope_pusher;
|
||||
}
|
||||
|
||||
|
@ -313,6 +324,10 @@ public:
|
|||
scope_has_declaration = false;
|
||||
}
|
||||
|
||||
if (m_type == ScopeType::Function && !m_contains_access_to_arguments_object && m_function_parameters_candidates_for_local_variables.contains(identifier_group_name)) {
|
||||
scope_has_declaration = true;
|
||||
}
|
||||
|
||||
if (scope_has_declaration) {
|
||||
if (function_declaration)
|
||||
continue;
|
||||
|
@ -413,6 +428,7 @@ private:
|
|||
Vector<NonnullRefPtr<FunctionDeclaration const>> m_functions_to_hoist;
|
||||
|
||||
HashTable<DeprecatedFlyString> m_bound_names;
|
||||
HashTable<DeprecatedFlyString> m_function_parameters_candidates_for_local_variables;
|
||||
|
||||
struct IdentifierGroup {
|
||||
bool captured_by_nested_function { false };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue