Skip to content

Commit 6671cbe

Browse files
committed
LibJS: Precompute the number of regs/constants/locals in Executable
Instead of doing it again on every call. Minor bump in call performance.
1 parent cdcbbcf commit 6671cbe

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

Libraries/LibJS/Bytecode/Executable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class JS_API Executable final : public Cell {
9292
size_t number_of_registers { 0 };
9393
bool is_strict_mode { false };
9494

95+
size_t registers_and_constants_and_locals_count { 0 };
96+
9597
struct ExceptionHandlers {
9698
size_t start_offset;
9799
size_t end_offset;

Libraries/LibJS/Bytecode/Generator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,8 @@ CodeGenerationErrorOr<GC::Ref<Executable>> Generator::compile(VM& vm, ASTNode co
477477
executable->argument_index_base = number_of_registers + number_of_constants + number_of_locals;
478478
executable->length_identifier = generator.m_length_identifier;
479479

480+
executable->registers_and_constants_and_locals_count = executable->number_of_registers + executable->constants.size() + executable->local_variable_names.size();
481+
480482
generator.m_finished = true;
481483

482484
return executable;

Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::get_stack_frame_size(size_t& r
507507
executable = TRY(Bytecode::compile(vm(), *this));
508508
}
509509
}
510-
registers_and_constants_and_locals_count = executable->number_of_registers + executable->constants.size() + executable->local_variable_names.size();
510+
registers_and_constants_and_locals_count = executable->registers_and_constants_and_locals_count;
511511
argument_count = max(argument_count, formal_parameters().size());
512512
return {};
513513
}

0 commit comments

Comments
 (0)