From a06441c88ced162a9ac52220a4514151bc1bf2e4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 11 May 2024 19:32:33 +0200 Subject: [PATCH] LibJS/Bytecode: Defer GetGlobal identifier lookup until cache misses This way we avoid looking up the identifier when the cache hits. --- Userland/Libraries/LibJS/Bytecode/CommonImplementations.h | 4 +++- Userland/Libraries/LibJS/Bytecode/Interpreter.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h index bc3ff25c0b..7e6e23c3f4 100644 --- a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h +++ b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h @@ -231,7 +231,7 @@ inline ThrowCompletionOr get_by_value(VM& vm, Optionalinternal_get(property_key, base_value)); } -inline ThrowCompletionOr get_global(Bytecode::Interpreter& interpreter, DeprecatedFlyString const& identifier, GlobalVariableCache& cache) +inline ThrowCompletionOr get_global(Interpreter& interpreter, IdentifierTableIndex identifier_index, GlobalVariableCache& cache) { auto& vm = interpreter.vm(); auto& binding_object = interpreter.global_object(); @@ -246,6 +246,8 @@ inline ThrowCompletionOr get_global(Bytecode::Interpreter& interpreter, D cache.environment_serial_number = declarative_record.environment_serial_number(); + auto& identifier = interpreter.current_executable().get_identifier(identifier_index); + if (vm.running_execution_context().script_or_module.has>()) { // NOTE: GetGlobal is used to access variables stored in the module environment and global environment. // The module environment is checked first since it precedes the global environment in the environment chain. diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index d89c9a7661..4569817379 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -1264,7 +1264,7 @@ ThrowCompletionOr GetCalleeAndThisFromEnvironment::execute_impl(Bytecode:: ThrowCompletionOr GetGlobal::execute_impl(Bytecode::Interpreter& interpreter) const { - interpreter.set(dst(), TRY(get_global(interpreter, interpreter.current_executable().get_identifier(m_identifier), interpreter.current_executable().global_variable_caches[m_cache_index]))); + interpreter.set(dst(), TRY(get_global(interpreter, m_identifier, interpreter.current_executable().global_variable_caches[m_cache_index]))); return {}; }