mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-19 02:10:26 +00:00
This patch introduces a cookie cache in the WebContent process to reduce blocking IPC calls when JS accesses document.cookie. The UI process now maintains a cookie version counter per-domain in shared memory. When JS reads document.cookie, we check whether we have a valid cached cookie by comparing the current shared version to the last used version. If they match, the cached cookie is returned without IPC. This optimization is based on Chromium's shared versioning, in which it was observed that 87% of document.cookie accesses were redundant. See: https://blog.chromium.org/2024/06/introducing-shared-memory-versioning-to.html Note that this cache only supports document.cookie, not HTTP Cookie headers. HTTP cookies are attached to requests with varying URLs and paths. The cookies that match the document URL might not match the request URL, which we wouldn't know from WebContent. So attaching the cached document cookie would be incorrect. On https://twinings.co.uk, we see approximately 600 document.cookie requests while the page loads. This patch reduces the time spent in the document.cookie getter from ~45ms to 2-3ms.
47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibCore/System.h>
|
|
#include <LibWeb/Worker/WebWorkerClient.h>
|
|
|
|
namespace Web::HTML {
|
|
|
|
void WebWorkerClient::die()
|
|
{
|
|
// FIXME: Notify WorkerAgent that the worker is dead
|
|
}
|
|
|
|
void WebWorkerClient::did_close_worker()
|
|
{
|
|
if (on_worker_close)
|
|
on_worker_close();
|
|
}
|
|
|
|
Messages::WebWorkerClient::DidRequestCookieResponse WebWorkerClient::did_request_cookie(URL::URL url, Cookie::Source source)
|
|
{
|
|
if (on_request_cookie)
|
|
return on_request_cookie(url, source);
|
|
return Cookie::VersionedCookie {};
|
|
}
|
|
|
|
Messages::WebWorkerClient::RequestWorkerAgentResponse WebWorkerClient::request_worker_agent(Web::Bindings::AgentType worker_type)
|
|
{
|
|
if (on_request_worker_agent)
|
|
return on_request_worker_agent(worker_type);
|
|
return IPC::File {};
|
|
}
|
|
|
|
WebWorkerClient::WebWorkerClient(NonnullOwnPtr<IPC::Transport> transport)
|
|
: IPC::ConnectionToServer<WebWorkerClientEndpoint, WebWorkerServerEndpoint>(*this, move(transport))
|
|
{
|
|
}
|
|
|
|
IPC::File WebWorkerClient::clone_transport()
|
|
{
|
|
return MUST(m_transport->clone_for_transfer());
|
|
}
|
|
|
|
}
|