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() ...@@ -2106,10 +2106,7 @@ WasmCodeRefScope::WasmCodeRefScope()
WasmCodeRefScope::~WasmCodeRefScope() { WasmCodeRefScope::~WasmCodeRefScope() {
DCHECK_EQ(this, current_code_refs_scope); DCHECK_EQ(this, current_code_refs_scope);
current_code_refs_scope = previous_scope_; current_code_refs_scope = previous_scope_;
std::vector<WasmCode*> code_ptrs; WasmCode::DecrementRefCount(VectorOf(code_ptrs_));
code_ptrs.reserve(code_ptrs_.size());
code_ptrs.assign(code_ptrs_.begin(), code_ptrs_.end());
WasmCode::DecrementRefCount(VectorOf(code_ptrs));
} }
// static // static
...@@ -2117,9 +2114,8 @@ void WasmCodeRefScope::AddRef(WasmCode* code) { ...@@ -2117,9 +2114,8 @@ void WasmCodeRefScope::AddRef(WasmCode* code) {
DCHECK_NOT_NULL(code); DCHECK_NOT_NULL(code);
WasmCodeRefScope* current_scope = current_code_refs_scope; WasmCodeRefScope* current_scope = current_code_refs_scope;
DCHECK_NOT_NULL(current_scope); DCHECK_NOT_NULL(current_scope);
auto entry = current_scope->code_ptrs_.insert(code); current_scope->code_ptrs_.push_back(code);
// If we added a new entry, increment the ref counter. code->IncRef();
if (entry.second) code->IncRef();
} }
const char* GetRuntimeStubName(WasmCode::RuntimeStubId stub_id) { const char* GetRuntimeStubName(WasmCode::RuntimeStubId stub_id) {
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <set> #include <set>
#include <unordered_set>
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -926,7 +925,7 @@ class V8_EXPORT_PRIVATE V8_NODISCARD WasmCodeRefScope { ...@@ -926,7 +925,7 @@ class V8_EXPORT_PRIVATE V8_NODISCARD WasmCodeRefScope {
private: private:
WasmCodeRefScope* const previous_scope_; 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 // 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