Commit 698508e1 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Improve performance of WasmCodeRefScope

Holding an unordered set is surprisingly inefficient for large sets.
Switching to just a vector makes e.g. deserialization of large modules
30% faster. We pay in terms of memory usage though, so if there is ever
a use case where we are storing the same code objects multiple times, we
might want do add a deduplication algorithm which cleans up the vector
every now and then.

R=thibaudm@chromium.org

Bug: v8:11164
Change-Id: I3983ee7f6f04ea7678b8da49fb5cec369693dbc3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2647260
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72325}
parent e4a9a790
......@@ -2106,10 +2106,7 @@ WasmCodeRefScope::WasmCodeRefScope()
WasmCodeRefScope::~WasmCodeRefScope() {
DCHECK_EQ(this, current_code_refs_scope);
current_code_refs_scope = previous_scope_;
std::vector<WasmCode*> code_ptrs;
code_ptrs.reserve(code_ptrs_.size());
code_ptrs.assign(code_ptrs_.begin(), code_ptrs_.end());
WasmCode::DecrementRefCount(VectorOf(code_ptrs));
WasmCode::DecrementRefCount(VectorOf(code_ptrs_));
}
// static
......@@ -2117,9 +2114,8 @@ void WasmCodeRefScope::AddRef(WasmCode* code) {
DCHECK_NOT_NULL(code);
WasmCodeRefScope* current_scope = current_code_refs_scope;
DCHECK_NOT_NULL(current_scope);
auto entry = current_scope->code_ptrs_.insert(code);
// If we added a new entry, increment the ref counter.
if (entry.second) code->IncRef();
current_scope->code_ptrs_.push_back(code);
code->IncRef();
}
const char* GetRuntimeStubName(WasmCode::RuntimeStubId stub_id) {
......
......@@ -9,7 +9,6 @@
#include <map>
#include <memory>
#include <set>
#include <unordered_set>
#include <utility>
#include <vector>
......@@ -926,7 +925,7 @@ class V8_EXPORT_PRIVATE V8_NODISCARD WasmCodeRefScope {
private:
WasmCodeRefScope* const previous_scope_;
std::unordered_set<WasmCode*> code_ptrs_;
std::vector<WasmCode*> code_ptrs_;
};
// Similarly to a global handle, a {GlobalWasmCodeRef} stores a single
......
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