Commit 9f76a336 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by V8 LUCI CQ

[wasm] Faster version of GetExportWrapperIndex

Hashing FunctionSigs can be quite expensive for large modules;
luckily in some cases we can avoid doing that work.

Change-Id: Ia18060b4c27ab34b44bda4bb81ea05299ecb0f49
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3038523
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75819}
parent e9acaed6
...@@ -51,13 +51,23 @@ int MaxNumExportWrappers(const WasmModule* module) { ...@@ -51,13 +51,23 @@ int MaxNumExportWrappers(const WasmModule* module) {
return static_cast<int>(module->signature_map.size()) * 2; return static_cast<int>(module->signature_map.size()) * 2;
} }
// static int GetExportWrapperIndexInternal(const WasmModule* module,
int canonical_sig_index, bool is_import) {
if (is_import) canonical_sig_index += module->signature_map.size();
return canonical_sig_index;
}
int GetExportWrapperIndex(const WasmModule* module, const FunctionSig* sig, int GetExportWrapperIndex(const WasmModule* module, const FunctionSig* sig,
bool is_import) { bool is_import) {
int result = module->signature_map.Find(*sig); int canonical_sig_index = module->signature_map.Find(*sig);
CHECK_GE(result, 0); CHECK_GE(canonical_sig_index, 0);
result += is_import ? module->signature_map.size() : 0; return GetExportWrapperIndexInternal(module, canonical_sig_index, is_import);
return result; }
int GetExportWrapperIndex(const WasmModule* module, uint32_t sig_index,
bool is_import) {
uint32_t canonical_sig_index = module->canonicalized_type_ids[sig_index];
return GetExportWrapperIndexInternal(module, canonical_sig_index, is_import);
} }
// static // static
......
...@@ -396,9 +396,12 @@ size_t EstimateStoredSize(const WasmModule* module); ...@@ -396,9 +396,12 @@ size_t EstimateStoredSize(const WasmModule* module);
V8_EXPORT_PRIVATE int MaxNumExportWrappers(const WasmModule* module); V8_EXPORT_PRIVATE int MaxNumExportWrappers(const WasmModule* module);
// Returns the wrapper index for a function in {module} with signature {sig} // Returns the wrapper index for a function in {module} with signature {sig}
// and origin defined by {is_import}. // or {sig_index} and origin defined by {is_import}.
// Prefer to use the {sig_index} consuming version, as it is much faster.
int GetExportWrapperIndex(const WasmModule* module, const FunctionSig* sig, int GetExportWrapperIndex(const WasmModule* module, const FunctionSig* sig,
bool is_import); bool is_import);
int GetExportWrapperIndex(const WasmModule* module, uint32_t sig_index,
bool is_import);
// Return the byte offset of the function identified by the given index. // Return the byte offset of the function identified by the given index.
// The offset will be relative to the start of the module bytes. // The offset will be relative to the start of the module bytes.
......
...@@ -1469,7 +1469,9 @@ WasmInstanceObject::GetOrCreateWasmExternalFunction( ...@@ -1469,7 +1469,9 @@ WasmInstanceObject::GetOrCreateWasmExternalFunction(
const WasmModule* module = module_object->module(); const WasmModule* module = module_object->module();
const WasmFunction& function = module->functions[function_index]; const WasmFunction& function = module->functions[function_index];
int wrapper_index = int wrapper_index =
GetExportWrapperIndex(module, function.sig, function.imported); GetExportWrapperIndex(module, function.sig_index, function.imported);
DCHECK_EQ(wrapper_index,
GetExportWrapperIndex(module, function.sig, function.imported));
Handle<Object> entry = Handle<Object> entry =
FixedArray::get(module_object->export_wrappers(), wrapper_index, isolate); FixedArray::get(module_object->export_wrappers(), wrapper_index, isolate);
......
...@@ -439,7 +439,8 @@ class WasmRunnerBase : public InitializedHandleScope { ...@@ -439,7 +439,8 @@ class WasmRunnerBase : public InitializedHandleScope {
const char* name = nullptr) { const char* name = nullptr) {
functions_.emplace_back( functions_.emplace_back(
new WasmFunctionCompiler(&zone_, sig, &builder_, name)); new WasmFunctionCompiler(&zone_, sig, &builder_, name));
builder().AddSignature(sig); byte sig_index = builder().AddSignature(sig);
functions_.back()->SetSigIndex(sig_index);
return *functions_.back(); return *functions_.back();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment