Skip to content

Commit

Permalink
LibJS/Bytecode: Defer GetGlobal identifier lookup until cache misses
Browse files Browse the repository at this point in the history
This way we avoid looking up the identifier when the cache hits.
  • Loading branch information
awesomekling committed May 13, 2024
1 parent 6ec4d6f commit a06441c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Userland/Libraries/LibJS/Bytecode/CommonImplementations.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ inline ThrowCompletionOr<Value> get_by_value(VM& vm, Optional<DeprecatedFlyStrin
return TRY(object->internal_get(property_key, base_value));
}

inline ThrowCompletionOr<Value> get_global(Bytecode::Interpreter& interpreter, DeprecatedFlyString const& identifier, GlobalVariableCache& cache)
inline ThrowCompletionOr<Value> get_global(Interpreter& interpreter, IdentifierTableIndex identifier_index, GlobalVariableCache& cache)
{
auto& vm = interpreter.vm();
auto& binding_object = interpreter.global_object();
Expand All @@ -246,6 +246,8 @@ inline ThrowCompletionOr<Value> 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<NonnullGCPtr<Module>>()) {
// 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.
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibJS/Bytecode/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ ThrowCompletionOr<void> GetCalleeAndThisFromEnvironment::execute_impl(Bytecode::

ThrowCompletionOr<void> 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 {};
}

Expand Down

0 comments on commit a06441c

Please sign in to comment.