mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 18:28:10 +00:00
LibJS: Add the "fast non-local access" optimization to the bytecode VM
The GetVariable bytecode op now caches environment coordinates for fast cross-scope variable lookup.
This commit is contained in:
parent
da98212001
commit
715e7fada8
2 changed files with 24 additions and 3 deletions
|
@ -238,9 +238,27 @@ void ConcatString::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||||
|
|
||||||
void GetVariable::execute_impl(Bytecode::Interpreter& interpreter) const
|
void GetVariable::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||||
{
|
{
|
||||||
auto& vm = interpreter.vm();
|
auto reference = [&] {
|
||||||
auto reference = vm.resolve_binding(interpreter.current_executable().get_identifier(m_identifier));
|
auto const& string = interpreter.current_executable().get_identifier(m_identifier);
|
||||||
if (vm.exception())
|
if (m_cached_environment_coordinate.has_value()) {
|
||||||
|
auto* environment = interpreter.vm().running_execution_context().lexical_environment;
|
||||||
|
for (size_t i = 0; i < m_cached_environment_coordinate->hops; ++i)
|
||||||
|
environment = environment->outer_environment();
|
||||||
|
VERIFY(environment);
|
||||||
|
VERIFY(environment->is_declarative_environment());
|
||||||
|
if (!environment->is_permanently_screwed_by_eval()) {
|
||||||
|
return Reference { *environment, string, interpreter.vm().in_strict_mode(), m_cached_environment_coordinate };
|
||||||
|
}
|
||||||
|
m_cached_environment_coordinate = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
auto reference = interpreter.vm().resolve_binding(string);
|
||||||
|
if (reference.environment_coordinate().has_value())
|
||||||
|
m_cached_environment_coordinate = reference.environment_coordinate();
|
||||||
|
return reference;
|
||||||
|
}();
|
||||||
|
|
||||||
|
if (interpreter.vm().exception())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
interpreter.accumulator() = reference.get_value(interpreter.global_object());
|
interpreter.accumulator() = reference.get_value(interpreter.global_object());
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <LibJS/Bytecode/StringTable.h>
|
#include <LibJS/Bytecode/StringTable.h>
|
||||||
#include <LibJS/Heap/Cell.h>
|
#include <LibJS/Heap/Cell.h>
|
||||||
#include <LibJS/Runtime/Environment.h>
|
#include <LibJS/Runtime/Environment.h>
|
||||||
|
#include <LibJS/Runtime/EnvironmentCoordinate.h>
|
||||||
#include <LibJS/Runtime/Value.h>
|
#include <LibJS/Runtime/Value.h>
|
||||||
|
|
||||||
namespace JS::Bytecode::Op {
|
namespace JS::Bytecode::Op {
|
||||||
|
@ -310,6 +311,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IdentifierTableIndex m_identifier;
|
IdentifierTableIndex m_identifier;
|
||||||
|
|
||||||
|
Optional<EnvironmentCoordinate> mutable m_cached_environment_coordinate;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GetById final : public Instruction {
|
class GetById final : public Instruction {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue