mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
LibJS: Skip initializing constant slots in ExecutionContext
Every function call allocates an ExecutionContext with a trailing array of Values for registers, locals, constants, and arguments. Previously, the constructor would initialize all slots to js_special_empty_value(), but constant slots were then immediately overwritten by the interpreter copying in values from the Executable before execution began. To eliminate this redundant initialization, we rearrange the layout from [registers | constants | locals] to [registers | locals | constants]. This groups registers and locals together at the front, allowing us to initialize only those slots while leaving constant slots uninitialized until they're populated with their actual values. This reduces the per-call initialization cost from O(registers + locals + constants) to O(registers + locals). Also tightens up the types involved (size_t -> u32) and adds VERIFYs to guard against overflow when computing the combined slot counts, and to ensure the total fits within the 29-bit operand index field.
This commit is contained in:
committed by
Andreas Kling
parent
5b6fea6c57
commit
4d92c4d71a
Notes:
github-actions[bot]
2026-02-06 11:27:20 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/4d92c4d71a3 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7527
@@ -252,7 +252,7 @@ void ECMAScriptFunctionObject::initialize(Realm& realm)
|
||||
}
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> ECMAScriptFunctionObject::get_stack_frame_size(size_t& registers_and_constants_and_locals_count, size_t& argument_count)
|
||||
ThrowCompletionOr<void> ECMAScriptFunctionObject::get_stack_frame_size(size_t& registers_and_locals_count, size_t& constants_count, size_t& argument_count)
|
||||
{
|
||||
auto& executable = shared_data().m_executable;
|
||||
if (!executable) {
|
||||
@@ -262,7 +262,8 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::get_stack_frame_size(size_t& r
|
||||
executable = TRY(Bytecode::compile(vm(), shared_data(), Bytecode::BuiltinAbstractOperationsEnabled::No));
|
||||
}
|
||||
}
|
||||
registers_and_constants_and_locals_count = executable->registers_and_constants_and_locals_count;
|
||||
registers_and_locals_count = executable->registers_and_locals_count;
|
||||
constants_count = executable->constants.size();
|
||||
argument_count = max(argument_count, formal_parameters().size());
|
||||
return {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user