mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-03 13:02:09 +02:00
LibWeb+LibJS: Skip function environment allocation if possible
If a function has the following properties: - uses only local variables and registers - does not use `this` - does not use `new.target` - does not use `super` - does not use direct eval() calls then it is possible to entirely skip function environment allocation because it will never be used This change adds gathering of information whether a function needs to access `this` from environment and updates `prepare_for_ordinary_call()` to skip allocation when possible. For now, this optimisation is too aggressively blocked; e.g. if `this` is used in a function scope, then all functions in outer scopes have to allocate an environment. It could be improved in the future, although this implementation already allows skipping >80% of environment allocations on Discord, GitHub and Twitter.
This commit is contained in:
committed by
Andreas Kling
parent
aede010096
commit
4d5823a5bc
Notes:
sideshowbarker
2024-07-17 06:20:50 +09:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/SerenityOS/serenity/commit/4d5823a5bc Pull-request: https://github.com/SerenityOS/serenity/pull/24194
@@ -266,7 +266,7 @@ static JS::ThrowCompletionOr<JS::Value> execute_a_function_body(Web::Page& page,
|
||||
// The result of parsing global scope above.
|
||||
// strict
|
||||
// The result of parsing strict above.
|
||||
auto function = JS::ECMAScriptFunctionObject::create(realm, "", move(source_text), function_expression->body(), function_expression->parameters(), function_expression->function_length(), function_expression->local_variables_names(), &global_scope, nullptr, function_expression->kind(), function_expression->is_strict_mode(), function_expression->might_need_arguments_object(), contains_direct_call_to_eval);
|
||||
auto function = JS::ECMAScriptFunctionObject::create(realm, "", move(source_text), function_expression->body(), function_expression->parameters(), function_expression->function_length(), function_expression->local_variables_names(), &global_scope, nullptr, function_expression->kind(), function_expression->is_strict_mode(), function_expression->uses_this(), function_expression->might_need_arguments_object(), contains_direct_call_to_eval);
|
||||
|
||||
// 9. Let completion be Function.[[Call]](window, parameters) with function as the this value.
|
||||
// NOTE: This is not entirely clear, but I don't think they mean actually passing `function` as
|
||||
|
||||
Reference in New Issue
Block a user