mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-19 15:32:31 +00:00
LibWasm: Remove Module::functions
`Module::functions` created clones of all of the functions in the module. It provided a _slightly_ better API, but ended up costing around 40ms when instantiating spidermonkey.
This commit is contained in:
parent
2d95cc01dc
commit
dc52998341
Notes:
github-actions[bot]
2024-07-28 00:57:26 +00:00
Author: https://github.com/dzfrias
Commit: dc52998341
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/874
Reviewed-by: https://github.com/alimpfard ✅
8 changed files with 36 additions and 111 deletions
|
@ -14,14 +14,14 @@
|
|||
|
||||
namespace Wasm {
|
||||
|
||||
Optional<FunctionAddress> Store::allocate(ModuleInstance& module, Module::Function const& function)
|
||||
Optional<FunctionAddress> Store::allocate(ModuleInstance& module, CodeSection::Code const& code, TypeIndex type_index)
|
||||
{
|
||||
FunctionAddress address { m_functions.size() };
|
||||
if (function.type().value() > module.types().size())
|
||||
if (type_index.value() > module.types().size())
|
||||
return {};
|
||||
|
||||
auto& type = module.types()[function.type().value()];
|
||||
m_functions.empend(WasmFunction { type, module, function });
|
||||
auto& type = module.types()[type_index.value()];
|
||||
m_functions.empend(WasmFunction { type, module, code });
|
||||
return address;
|
||||
}
|
||||
|
||||
|
@ -223,15 +223,24 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
|
|||
auxiliary_instance.functions().append(*ptr);
|
||||
}
|
||||
|
||||
Vector<FunctionAddress> module_functions;
|
||||
module_functions.ensure_capacity(module.functions().size());
|
||||
FunctionSection const* function_section { nullptr };
|
||||
module.for_each_section_of_type<FunctionSection>([&](FunctionSection const& section) { function_section = §ion; });
|
||||
|
||||
for (auto& func : module.functions()) {
|
||||
auto address = m_store.allocate(main_module_instance, func);
|
||||
VERIFY(address.has_value());
|
||||
auxiliary_instance.functions().append(*address);
|
||||
module_functions.append(*address);
|
||||
}
|
||||
Vector<FunctionAddress> module_functions;
|
||||
if (function_section)
|
||||
module_functions.ensure_capacity(function_section->types().size());
|
||||
|
||||
module.for_each_section_of_type<CodeSection>([&](auto& code_section) {
|
||||
size_t i = 0;
|
||||
for (auto& code : code_section.functions()) {
|
||||
auto type_index = function_section->types()[i];
|
||||
auto address = m_store.allocate(main_module_instance, code, type_index);
|
||||
VERIFY(address.has_value());
|
||||
auxiliary_instance.functions().append(*address);
|
||||
module_functions.append(*address);
|
||||
++i;
|
||||
}
|
||||
});
|
||||
|
||||
BytecodeInterpreter interpreter(m_stack_info);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue