mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-18 18:00:31 +00: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:
parent
5b6fea6c57
commit
4d92c4d71a
Notes:
github-actions[bot]
2026-02-06 11:27:20 +00:00
Author: https://github.com/awesomekling
Commit: 4d92c4d71a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7527
25 changed files with 147 additions and 102 deletions
|
|
@ -73,10 +73,11 @@ void NativeJavaScriptBackedFunction::visit_edges(Visitor& visitor)
|
|||
visitor.visit(m_shared_function_instance_data);
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> NativeJavaScriptBackedFunction::get_stack_frame_size(size_t& registers_and_constants_and_locals_count, size_t& argument_count)
|
||||
ThrowCompletionOr<void> NativeJavaScriptBackedFunction::get_stack_frame_size(size_t& registers_and_locals_count, size_t& constants_count, size_t& argument_count)
|
||||
{
|
||||
auto& bytecode_executable = this->bytecode_executable();
|
||||
registers_and_constants_and_locals_count = bytecode_executable.number_of_registers + bytecode_executable.constants.size() + bytecode_executable.local_variable_names.size();
|
||||
registers_and_locals_count = bytecode_executable.registers_and_locals_count;
|
||||
constants_count = bytecode_executable.constants.size();
|
||||
argument_count = max(argument_count, m_shared_function_instance_data->m_function_length);
|
||||
return {};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue