Skip to content

Truly independent web browser

LibWeb: Keep caches of GC objects per agent

Andreas Klinga0b8b83fda71
diff --git a/Libraries/LibWeb/Crypto/CryptoKey.cpp b/Libraries/LibWeb/Crypto/CryptoKey.cpp
index 90bafd41524..bca606496bc 100644
--- a/Libraries/LibWeb/Crypto/CryptoKey.cpp
+++ b/Libraries/LibWeb/Crypto/CryptoKey.cpp
@@ -32,7 +32,7 @@ struct CryptoKeyCacheEntry {
static Vector<CryptoKeyCacheEntry>& crypto_key_caches()
{
- static NeverDestroyed<Vector<CryptoKeyCacheEntry>> caches;
+ static thread_local NeverDestroyed<Vector<CryptoKeyCacheEntry>> caches;
return *caches;
}
diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
index f1ae7f22f84..b7a8bc281ef 100644
--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
@@ -92,7 +92,7 @@
namespace Web::Fetch::Fetching {
-static bool g_http_memory_cache_enabled = false;
+static Atomic<bool, AK::MemoryOrder::memory_order_relaxed> g_http_memory_cache_enabled { false };
// In test mode, RequestServer's disk cache stores only the responses to requests that ask for it with a header, which a
// page cannot add to a navigation request. Tests can have every navigation request ask for it.
@@ -199,10 +199,11 @@ public:
return it->value.ptr();
}
+ // NB: Each agent has one, as a cache entry can only be used on one thread.
static HTTPCache& the()
{
- static HTTPCache& cache = *new HTTPCache;
- return cache;
+ static thread_local NeverDestroyed<HTTPCache> cache;
+ return *cache;
}
void clear_cache()
diff --git a/Libraries/LibWeb/HTML/MessageEvent.cpp b/Libraries/LibWeb/HTML/MessageEvent.cpp
index 872b2a2bcbb..acb21eabc03 100644
--- a/Libraries/LibWeb/HTML/MessageEvent.cpp
+++ b/Libraries/LibWeb/HTML/MessageEvent.cpp
@@ -23,7 +23,7 @@ GC_DEFINE_ALLOCATOR(MessageEvent);
static Bindings::WrapperWorldWeakValueCacheMap<MessageEvent, JS::Array>& message_event_ports_caches()
{
- static NeverDestroyed<Bindings::WrapperWorldWeakValueCacheMap<MessageEvent, JS::Array>> caches;
+ static thread_local NeverDestroyed<Bindings::WrapperWorldWeakValueCacheMap<MessageEvent, JS::Array>> caches;
return *caches;
}
diff --git a/Libraries/LibWeb/HTML/Scripting/CompiledScriptCache.cpp b/Libraries/LibWeb/HTML/Scripting/CompiledScriptCache.cpp
index 413054464dc..14ab1fcb209 100644
--- a/Libraries/LibWeb/HTML/Scripting/CompiledScriptCache.cpp
+++ b/Libraries/LibWeb/HTML/Scripting/CompiledScriptCache.cpp
@@ -15,7 +15,7 @@ static constexpr size_t compiled_script_cache_size_limit = 128 * MiB;
CompiledScriptCache& CompiledScriptCache::the()
{
- static NeverDestroyed<CompiledScriptCache> cache;
+ static thread_local NeverDestroyed<CompiledScriptCache> cache;
return *cache;
}
diff --git a/Libraries/LibWeb/HTML/Scripting/CompiledScriptCache.h b/Libraries/LibWeb/HTML/Scripting/CompiledScriptCache.h
index 3afbf86c558..b836b7d6cc7 100644
--- a/Libraries/LibWeb/HTML/Scripting/CompiledScriptCache.h
+++ b/Libraries/LibWeb/HTML/Scripting/CompiledScriptCache.h
@@ -27,7 +27,7 @@ struct CompiledScriptCacheKey {
bool operator==(CompiledScriptCacheKey const&) const = default;
};
-// The compiled scripts of this process, which a script that loads again links into its own realm instead of being
+// The compiled scripts of this agent, which a script that loads again links into its own realm instead of being
// parsed and compiled again. Entries are found after a fetch completed, by the decoded source text the fetch came up
// with, so they answer nothing that the checks of a fetch decide, and can not stand in for different source text.
class WEB_API CompiledScriptCache {
diff --git a/Libraries/LibWeb/PerformanceTimeline/PerformanceObserver.cpp b/Libraries/LibWeb/PerformanceTimeline/PerformanceObserver.cpp
index 8f4e20d9469..dd081415937 100644
--- a/Libraries/LibWeb/PerformanceTimeline/PerformanceObserver.cpp
+++ b/Libraries/LibWeb/PerformanceTimeline/PerformanceObserver.cpp
@@ -31,7 +31,7 @@ GC_DEFINE_ALLOCATOR(PerformanceObserver);
static Bindings::WrapperWorldWeakValueCacheMap<JS::Object, JS::Object>& supported_entry_types_caches()
{
- static NeverDestroyed<Bindings::WrapperWorldWeakValueCacheMap<JS::Object, JS::Object>> caches;
+ static thread_local NeverDestroyed<Bindings::WrapperWorldWeakValueCacheMap<JS::Object, JS::Object>> caches;
return *caches;
}
diff --git a/Libraries/LibWeb/ServiceWorker/ServiceWorkerContainer.cpp b/Libraries/LibWeb/ServiceWorker/ServiceWorkerContainer.cpp
index 7785930144a..13ec254b66a 100644
--- a/Libraries/LibWeb/ServiceWorker/ServiceWorkerContainer.cpp
+++ b/Libraries/LibWeb/ServiceWorker/ServiceWorkerContainer.cpp
@@ -37,7 +37,7 @@ struct ServiceWorkerContainerReadyPromiseCacheEntry {
static Vector<ServiceWorkerContainerReadyPromiseCacheEntry>& service_worker_container_ready_promise_caches()
{
- static NeverDestroyed<Vector<ServiceWorkerContainerReadyPromiseCacheEntry>> caches;
+ static thread_local NeverDestroyed<Vector<ServiceWorkerContainerReadyPromiseCacheEntry>> caches;
return *caches;
}