1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 11:25:09 +00:00

LibJS: Do less work in successfully cached GetByValue* ops

If we have a cached environment coordinate that hasn't been screwed
by eval(), we can get the value directly without instantiating a
Reference.

15% speed-up on Octane/zlib.js :^)
This commit is contained in:
Andreas Kling 2023-10-07 18:15:49 +02:00
parent 6f1f0710f8
commit ae4e46a037

View file

@ -812,26 +812,23 @@ ThrowCompletionOr<void> GetVariable::execute_impl(Bytecode::Interpreter& interpr
{ {
auto& vm = interpreter.vm(); auto& vm = interpreter.vm();
auto get_reference = [&]() -> ThrowCompletionOr<Reference> { if (m_cached_environment_coordinate.has_value()) {
auto const& string = interpreter.current_executable().get_identifier(m_identifier); auto environment = vm.running_execution_context().lexical_environment;
if (m_cached_environment_coordinate.has_value()) { for (size_t i = 0; i < m_cached_environment_coordinate->hops; ++i)
auto environment = vm.running_execution_context().lexical_environment; environment = environment->outer_environment();
for (size_t i = 0; i < m_cached_environment_coordinate->hops; ++i) VERIFY(environment);
environment = environment->outer_environment(); VERIFY(environment->is_declarative_environment());
VERIFY(environment); if (!environment->is_permanently_screwed_by_eval()) {
VERIFY(environment->is_declarative_environment()); interpreter.accumulator() = TRY(verify_cast<DeclarativeEnvironment>(*environment).get_binding_value_direct(vm, m_cached_environment_coordinate.value().index, vm.in_strict_mode()));
if (!environment->is_permanently_screwed_by_eval()) { return {};
return Reference { *environment, string, vm.in_strict_mode(), m_cached_environment_coordinate };
}
m_cached_environment_coordinate = {};
} }
m_cached_environment_coordinate = {};
}
auto reference = TRY(vm.resolve_binding(string)); auto const& string = interpreter.current_executable().get_identifier(m_identifier);
if (reference.environment_coordinate().has_value()) auto reference = TRY(vm.resolve_binding(string));
m_cached_environment_coordinate = reference.environment_coordinate(); if (reference.environment_coordinate().has_value())
return reference; m_cached_environment_coordinate = reference.environment_coordinate();
};
auto reference = TRY(get_reference());
interpreter.accumulator() = TRY(reference.get_value(vm)); interpreter.accumulator() = TRY(reference.get_value(vm));
return {}; return {};
} }
@ -840,26 +837,28 @@ ThrowCompletionOr<void> GetCalleeAndThisFromEnvironment::execute_impl(Bytecode::
{ {
auto& vm = interpreter.vm(); auto& vm = interpreter.vm();
auto get_reference = [&]() -> ThrowCompletionOr<Reference> { if (m_cached_environment_coordinate.has_value()) {
auto const& string = interpreter.current_executable().get_identifier(m_identifier); auto environment = vm.running_execution_context().lexical_environment;
if (m_cached_environment_coordinate.has_value()) { for (size_t i = 0; i < m_cached_environment_coordinate->hops; ++i)
auto environment = vm.running_execution_context().lexical_environment; environment = environment->outer_environment();
for (size_t i = 0; i < m_cached_environment_coordinate->hops; ++i) VERIFY(environment);
environment = environment->outer_environment(); VERIFY(environment->is_declarative_environment());
VERIFY(environment); if (!environment->is_permanently_screwed_by_eval()) {
VERIFY(environment->is_declarative_environment()); interpreter.reg(m_callee_reg) = TRY(verify_cast<DeclarativeEnvironment>(*environment).get_binding_value_direct(vm, m_cached_environment_coordinate.value().index, vm.in_strict_mode()));
if (!environment->is_permanently_screwed_by_eval()) { Value this_value = js_undefined();
return Reference { *environment, string, vm.in_strict_mode(), m_cached_environment_coordinate }; if (auto base_object = environment->with_base_object())
} this_value = base_object;
m_cached_environment_coordinate = {}; interpreter.reg(m_this_reg) = this_value;
return {};
} }
m_cached_environment_coordinate = {};
}
auto const& string = interpreter.current_executable().get_identifier(m_identifier);
auto reference = TRY(vm.resolve_binding(string));
if (reference.environment_coordinate().has_value())
m_cached_environment_coordinate = reference.environment_coordinate();
auto reference = TRY(vm.resolve_binding(string));
if (reference.environment_coordinate().has_value())
m_cached_environment_coordinate = reference.environment_coordinate();
return reference;
};
auto reference = TRY(get_reference());
interpreter.reg(m_callee_reg) = TRY(reference.get_value(vm)); interpreter.reg(m_callee_reg) = TRY(reference.get_value(vm));
Value this_value = js_undefined(); Value this_value = js_undefined();