[wasm][serialization] Use unique wire bytes pointers
We were doing the cache lookup using the original {wire_bytes_vec}, but then inserting the module with another copy stored in the {NativeModule}. This causes {NativeModuleCache::Key::operator<} to do a full {memcmp} on the two wire bytes copies. By using the same pointer consistently, we can avoid that costly {memcmp}. R=thibaudm@chromium.org Bug: v8:11164 Change-Id: I19ba1022f700d8da40671818ee2e2ebdbbddd5c0 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2658329 Reviewed-by: Thibaud Michaud <thibaudm@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#72431}
This commit is contained in:
parent
732e22e088
commit
0444497c9a
@ -822,12 +822,15 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
|
||||
if (!IsWasmCodegenAllowed(isolate, isolate->native_context())) return {};
|
||||
if (!IsSupportedVersion(data)) return {};
|
||||
|
||||
ModuleWireBytes wire_bytes(wire_bytes_vec);
|
||||
// Make the copy of the wire bytes early, so we use the same memory for
|
||||
// decoding, lookup in the native module cache, and insertion into the cache.
|
||||
auto owned_wire_bytes = OwnedVector<uint8_t>::Of(wire_bytes_vec);
|
||||
|
||||
// TODO(titzer): module features should be part of the serialization format.
|
||||
WasmEngine* wasm_engine = isolate->wasm_engine();
|
||||
WasmFeatures enabled_features = WasmFeatures::FromIsolate(isolate);
|
||||
ModuleResult decode_result = DecodeWasmModule(
|
||||
enabled_features, wire_bytes.start(), wire_bytes.end(), false,
|
||||
enabled_features, owned_wire_bytes.start(), owned_wire_bytes.end(), false,
|
||||
i::wasm::kWasmOrigin, isolate->counters(), isolate->metrics_recorder(),
|
||||
isolate->GetOrRegisterRecorderContextId(isolate->native_context()),
|
||||
DecodingMethod::kDeserialize, wasm_engine->allocator());
|
||||
@ -836,7 +839,7 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
|
||||
CHECK_NOT_NULL(module);
|
||||
|
||||
auto shared_native_module = wasm_engine->MaybeGetNativeModule(
|
||||
module->origin, wire_bytes_vec, isolate);
|
||||
module->origin, owned_wire_bytes.as_vector(), isolate);
|
||||
if (shared_native_module == nullptr) {
|
||||
const bool kIncludeLiftoff = false;
|
||||
size_t code_size_estimate =
|
||||
@ -850,8 +853,7 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
|
||||
// than the compilation ID of actual compilations, and also different than
|
||||
// the sentinel value of the CompilationState.
|
||||
shared_native_module->compilation_state()->set_compilation_id(-2);
|
||||
shared_native_module->SetWireBytes(
|
||||
OwnedVector<uint8_t>::Of(wire_bytes_vec));
|
||||
shared_native_module->SetWireBytes(std::move(owned_wire_bytes));
|
||||
|
||||
NativeModuleDeserializer deserializer(shared_native_module.get());
|
||||
Reader reader(data + WasmSerializer::kHeaderSize);
|
||||
|
Loading…
Reference in New Issue
Block a user