Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 37640aba9e2b0e54cd39a4bc9b5c815730f3f36d
https://github.com/WebKit/WebKit/commit/37640aba9e2b0e54cd39a4bc9b5c815730f3f36d
Author: Chris Dumez <[email protected]>
Date: 2026-05-22 (Fri, 22 May 2026)
Changed paths:
M Source/WebKit/Platform/IPC/Connection.h
M Source/WebKit/UIProcess/API/APIHTTPCookieStore.cpp
M Source/WebKit/UIProcess/API/APIHTTPCookieStore.h
M Source/WebKit/UIProcess/API/Cocoa/WKHTTPCookieStore.mm
M Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp
M Source/WebKit/UIProcess/AuxiliaryProcessProxy.h
M Source/WebKit/UIProcess/WebProcessProxy.cpp
M Source/WebKit/UIProcess/WebProcessProxy.h
Log Message:
-----------
Safari's main thread is blocked for 58ms reading cookies
https://bugs.webkit.org/show_bug.cgi?id=314994
rdar://177212630
Reviewed by Alex Christensen.
The IPC reply for `WebCookieManager::GetAllCookies` and `GetCookies` is
currently
dispatched on the main thread, where the per-cookie work in
`coreCookiesToNSCookies()` (decoding `Vector<WebCore::Cookie>` from IPC bytes
and constructing one `NSHTTPCookie` per entry) compounds into a ~60ms hang
when the cookie store is large.
To avoid this:
- Add `IPC::Connection::AsyncReplyHandlerWithDispatcher` /
`makeAsyncReplyHandlerWithDispatcher` /
`sendMessageWithAsyncReplyWithDispatcher`
to the public section of `Connection`, mirroring how their
non-dispatcher counterparts are already public.
- Add `AuxiliaryProcessProxy::sendWithAsyncReplyOnDispatcher()` that
forwards to the connection's `sendWithAsyncReplyOnDispatcher` and
preserves the existing launching-state queuing behavior via a new
`PendingMessageWithDispatcher` vector.
- Add an optional `RefPtr<WorkQueue> replyQueue` parameter to
`API::HTTPCookieStore::cookies()` and `cookiesForURL()`. When provided,
the IPC reply (and therefore the `Vector<WebCore::Cookie>` decoding)
is dispatched on that queue. App-bound-domain resolution still happens
on the main thread before sending the IPC, with the resolved domain
set captured (via `crossThreadCopy()`) for filtering on the queue
with no additional main-thread hop. On non-iOS builds, no filtering
is needed and the IPC reply is delivered straight to the queue.
- In `WKHTTPCookieStore`, route `-getAllCookies:` and `-getCookiesForURL:`
through a dedicated `cookieConversionQueueSingleton()`, build the
`NSArray<NSHTTPCookie *>` there, then dispatch back to the main run
loop to invoke the user's completion block.
No new tests, covered by existing WKHTTPCookieStore API tests.
* Source/WebKit/Platform/IPC/Connection.h:
Move `AsyncReplyHandlerWithDispatcher`, `makeAsyncReplyHandlerWithDispatcher`,
and `sendMessageWithAsyncReplyWithDispatcher` from the private section to the
public section so external callers (e.g. `AuxiliaryProcessProxy`) can use them.
* Source/WebKit/UIProcess/API/APIHTTPCookieStore.cpp:
(API::filterCookiesByAppBoundDomains): New file-scope helper using
`WTF::compactMap()` to filter a cookie vector against an app-bound domain set.
(API::HTTPCookieStore::filterAppBoundCookies):
(API::HTTPCookieStore::fetchCookies): New private template factoring out the
shared body of `cookies()` and `cookiesForURL()`. When `replyQueue` is null
the existing main-thread path is preserved verbatim. When non-null, on
`ENABLE(APP_BOUND_DOMAINS)` we resolve the domains on main, then send the
IPC with the reply on the work queue and filter inline there using the
captured set; otherwise we send the IPC with the reply on the work queue
without any filtering.
(API::HTTPCookieStore::cookies):
(API::HTTPCookieStore::cookiesForURL): Now one-line wrappers around
`fetchCookies()`. Parameter type switched to `Function<...>` since the
callback may run off the construction thread.
* Source/WebKit/UIProcess/API/APIHTTPCookieStore.h:
* Source/WebKit/UIProcess/API/Cocoa/WKHTTPCookieStore.mm:
(cookieConversionQueueSingleton): New static `WorkQueue` for cookie
conversion work.
(-[WKHTTPCookieStore getAllCookies:]):
(-[WKHTTPCookieStore getCookiesForURL:completionHandler:]): Pass the
conversion queue to `cookies()` / `cookiesForURL()`. Build the
`NSArray<NSHTTPCookie *>` on the queue and dispatch back to the main
run loop to invoke the user's block.
* Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp:
(WebKit::AuxiliaryProcessProxy::sendMessageWithDispatcher): New helper
mirroring `sendMessage`, with launching-state queuing into
`m_pendingMessagesWithDispatcher`.
(WebKit::AuxiliaryProcessProxy::didFinishLaunching): Drain
`m_pendingMessagesWithDispatcher` after `m_pendingMessages`.
(WebKit::AuxiliaryProcessProxy::replyToPendingMessages): Also invoke null
replies for queued dispatcher-routed handlers.
* Source/WebKit/UIProcess/AuxiliaryProcessProxy.h:
(WebKit::AuxiliaryProcessProxy::sendWithAsyncReplyOnDispatcher):
Canonical link: https://commits.webkit.org/313783@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications