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:
Diego Frias 2024-07-27 16:44:36 -07:00 committed by Ali Mohammad Pur
parent 2d95cc01dc
commit dc52998341
Notes: github-actions[bot] 2024-07-28 00:57:26 +00:00
8 changed files with 36 additions and 111 deletions

View file

@ -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 = &section; });
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);