From 78fae9ea34fb95cb6fc16a096c8d6d706fc2684b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 5 Jan 2026 14:48:43 -0800 Subject: [PATCH 1/2] [NFC] Used Mixed Arena in IString interning --- src/support/istring.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/support/istring.cpp b/src/support/istring.cpp index 8a3319b5ee9..59afb06f4cb 100644 --- a/src/support/istring.cpp +++ b/src/support/istring.cpp @@ -15,6 +15,7 @@ */ #include "istring.h" +#include "mixed_arena.h" namespace wasm { @@ -45,9 +46,9 @@ std::string_view IString::interned(std::string_view s, bool reuse) { // The global backing store for interned strings that do not otherwise have // stable addresses. - static std::vector> allocated; + static MixedArena arena; - // Guards access to `globalStrings` and `allocated`. + // Guards access to `globalStrings` and `arena`. static std::mutex mutex; // A thread-local cache of strings to reduce contention. @@ -72,12 +73,10 @@ std::string_view IString::interned(std::string_view s, bool reuse) { // We have a new string, but it doesn't have a stable address. Create a copy // of the data at a stable address we can use. Make sure it is null // terminated so legacy uses that get a C string still work. - allocated.emplace_back(); - auto& data = allocated.back(); - data.reserve(s.size() + 1); - data.insert(data.end(), s.begin(), s.end()); - data.push_back('\0'); - s = std::string_view(allocated.back().data(), s.size()); + char* data = (char*)arena.allocSpace(s.size() + 1, 1); + std::copy(s.begin(), s.end(), data); + data[s.size()] = '\0'; + s = std::string_view(data, s.size()); } // Intern our new string. From a767bcc7576529cdc415d12c6853dc87bc9c08de Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 5 Jan 2026 14:52:34 -0800 Subject: [PATCH 2/2] comment --- src/support/istring.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/support/istring.cpp b/src/support/istring.cpp index 59afb06f4cb..60c8b59be6d 100644 --- a/src/support/istring.cpp +++ b/src/support/istring.cpp @@ -48,7 +48,7 @@ std::string_view IString::interned(std::string_view s, bool reuse) { // stable addresses. static MixedArena arena; - // Guards access to `globalStrings` and `arena`. + // Guards access to `globalStrings`. (note: `arena` is thread-safe anyhow) static std::mutex mutex; // A thread-local cache of strings to reduce contention.