1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 02:37:42 +00:00

LibJS: Add caching of this value in ResolveThisBinding instruction

Because "this" value cannot be changed during function execution it is
safe to compute it once and then use for future access.

This optimization makes ai-astar.js run 8% faster.
This commit is contained in:
Aliaksandr Kalenik 2023-07-28 23:59:43 +02:00 committed by Andreas Kling
parent bbd80d2e4d
commit 2bdc69c42c
3 changed files with 12 additions and 2 deletions

View file

@ -732,8 +732,13 @@ ThrowCompletionOr<void> Jump::execute_impl(Bytecode::Interpreter& interpreter) c
ThrowCompletionOr<void> ResolveThisBinding::execute_impl(Bytecode::Interpreter& interpreter) const
{
auto& vm = interpreter.vm();
interpreter.accumulator() = TRY(vm.resolve_this_binding());
if (!interpreter.this_value().has_value()) {
// OPTIMIZATION: Because the value of 'this' cannot be reassigned during a function execution, it's
// resolved once and then saved for subsequent use.
auto& vm = interpreter.vm();
interpreter.this_value() = TRY(vm.resolve_this_binding());
}
interpreter.accumulator() = interpreter.this_value().value();
return {};
}