Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move service worker registration and worker state updates out of main thread for service worker contexts #2115

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

youennf
Copy link
Contributor

@youennf youennf commented Jul 6, 2022

9e9572d

Move service worker registration and worker state updates out of main thread for service worker contexts
https://bugs.webkit.org/show_bug.cgi?id=242383
rdar://problem/96510954

Reviewed by NOBODY (OOPS!).

We are now handling some of the IPC message going to service workers on a background queue.
Some other messages to service workers are going through main thread as they are WebSWClientConnection messages.
This includes worker/registration state updates.

To make things more tight, we are now handling WebSWClientConnection messages on the same queue as WebSWContextManagerConnection.
When messages are to be sent to service workers, we directly hop to the service worker thread.
This allows the service worker messages to use the same path in WebSWClientConnection and WebSWContextManagerConnection.
For WebSWClientConnection messages that require getting to other workers or documents, we keep hopping to main thread.
Minor drive-by fix to make sure to call the completion handler in SWContextManager::fireNotificationEvent in case the worker is not there.

Changes are covered by existing tests.

* Source/WebCore/workers/Worker.cpp:
* Source/WebCore/workers/service/SWClientConnection.cpp:
(WebCore::SWClientConnection::jobRejectedInServer):
(WebCore::SWClientConnection::registrationJobResolvedInServer):
(WebCore::SWClientConnection::startScriptFetchForServer):
(WebCore::SWClientConnection::refreshImportedScripts):
(WebCore::SWClientConnection::postMessageToServiceWorkerClient):
(WebCore::forAllDedicatedAndSharedWorkers):
(WebCore::doUpdateRegistrationState):
(WebCore::SWClientConnection::updateRegistrationState):
(WebCore::doUpdateWorkerState):
(WebCore::SWClientConnection::updateWorkerState):
(WebCore::doFireUpdateFoundEvent):
(WebCore::SWClientConnection::fireUpdateFoundEvent):
(WebCore::doSetRegistrationLastUpdateTime):
(WebCore::SWClientConnection::setRegistrationLastUpdateTime):
(WebCore::doSetRegistrationUpdateViaCache):
(WebCore::SWClientConnection::setRegistrationUpdateViaCache):
(WebCore::SWClientConnection::notifyClientsOfControllerChange):
(WebCore::SWClientConnection::registerServiceWorkerClients):
(WebCore::forAllWorkers): Deleted.
* Source/WebCore/workers/service/SWClientConnection.h:
* Source/WebCore/workers/service/ServiceWorkerRegistrationData.h:
* Source/WebCore/workers/service/WorkerSWClientConnection.h:
* Source/WebCore/workers/service/context/SWContextManager.cpp:
(WebCore::SWContextManager::fireNotificationEvent):
(WebCore::SWContextManager::fireInstallEvent): Deleted.
(WebCore::SWContextManager::fireActivateEvent): Deleted.
* Source/WebCore/workers/service/context/SWContextManager.h:
* Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp:
(WebCore::ServiceWorkerFetch::dispatchFetchEvent):
* Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp:
(WebCore::ServiceWorkerThreadProxy::fireInstallEvent):
(WebCore::ServiceWorkerThreadProxy::fireActivateEvent):
* Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h:
* Source/WebCore/workers/shared/context/SharedWorkerContextManager.cpp:
* Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp:
(WebKit::NetworkProcessConnection::didReceiveMessage):
(WebKit::NetworkProcessConnection::didReceiveSyncMessage):
(WebKit::NetworkProcessConnection::serviceWorkerConnection):
* Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp:
(WebKit::WebSWClientConnection::~WebSWClientConnection):
(WebKit::WebSWClientConnection::establishConnection):
(WebKit::WebSWClientConnection::closeConnection):
(WebKit::WebSWClientConnection::messageSenderConnection const):
(WebKit::WebSWClientConnection::scheduleJobInServer):
(WebKit::WebSWClientConnection::finishFetchingScriptInServer):
(WebKit::WebSWClientConnection::addServiceWorkerRegistrationInServer):
(WebKit::WebSWClientConnection::removeServiceWorkerRegistrationInServer):
(WebKit::WebSWClientConnection::scheduleUnregisterJobInServer):
(WebKit::WebSWClientConnection::mayHaveServiceWorkerRegisteredForOrigin const):
(WebKit::WebSWClientConnection::setSWOriginTableSharedMemory):
(WebKit::WebSWClientConnection::setSWOriginTableIsImported):
(WebKit::WebSWClientConnection::runOrDelayTaskForImport):
(WebKit::WebSWClientConnection::whenRegistrationReady):
(WebKit::WebSWClientConnection::setServiceWorkerClientIsControlled):
(WebKit::WebSWClientConnection::connectionToServerLost):
(WebKit::WebSWClientConnection::clear):
(WebKit::WebSWClientConnection::terminateWorkerForTesting):
(WebKit::WebSWClientConnection::whenServiceWorkerIsTerminatedForTesting):
(WebKit::WebSWClientConnection::updateThrottleState):
(WebKit::WebSWClientConnection::storeRegistrationsOnDiskForTesting):
(WebKit::WebSWClientConnection::subscribeToPushService):
(WebKit::WebSWClientConnection::unsubscribeFromPushService):
(WebKit::WebSWClientConnection::getPushSubscription):
(WebKit::WebSWClientConnection::getPushPermissionState):
(WebKit::WebSWClientConnection::getNotifications):
(WebKit::WebSWClientConnection::enableNavigationPreload):
(WebKit::WebSWClientConnection::disableNavigationPreload):
(WebKit::WebSWClientConnection::setNavigationPreloadHeaderValue):
(WebKit::WebSWClientConnection::getNavigationPreloadState):
(WebKit::WebSWClientConnection::focusServiceWorkerClient):
(WebKit::WebSWClientConnection::refreshImportedScripts):
* Source/WebKit/WebProcess/Storage/WebSWClientConnection.h:
* Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp:
(WebKit::WebSWContextManagerConnection::sharedQueue):
(WebKit::m_userContentController):
(WebKit::WebSWContextManagerConnection::establishConnection):
(WebKit::WebSWContextManagerConnection::installServiceWorker):
(WebKit::WebSWContextManagerConnection::cancelFetch):
(WebKit::WebSWContextManagerConnection::continueDidReceiveFetchResponse):
(WebKit::WebSWContextManagerConnection::startFetch):
(WebKit::WebSWContextManagerConnection::postMessageToServiceWorker):
(WebKit::WebSWContextManagerConnection::fireInstallEvent):
(WebKit::WebSWContextManagerConnection::fireActivateEvent):
(WebKit::WebSWContextManagerConnection::firePushEvent):
(WebKit::WebSWContextManagerConnection::fireNotificationEvent):
(WebKit::WebSWContextManagerConnection::terminateWorker):
(WebKit::WebSWContextManagerConnection::didSaveScriptsToDisk):
(WebKit::WebSWContextManagerConnection::convertFetchToDownload):
(WebKit::WebSWContextManagerConnection::navigationPreloadIsReady):
(WebKit::WebSWContextManagerConnection::navigationPreloadFailed):
(WebKit::WebSWContextManagerConnection::skipWaitingCompleted):
(WebKit::WebSWContextManagerConnection::matchAllCompleted):
(WebKit::WebSWContextManagerConnection::setThrottleState):
(WebKit::m_queue): Deleted.
* Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h:
* Source/WebKit/WebProcess/WebProcess.cpp:
(WebKit::WebProcess::ensureNetworkProcessConnection):

… thread for service worker contexts

https://bugs.webkit.org/show_bug.cgi?id=242383
rdar://problem/96510954

Reviewed by NOBODY (OOPS!).

We are now handling some of the IPC message going to service workers on a background queue.
Some other messages to service workers are going through main thread as they are WebSWClientConnection messages.
This includes worker/registration state updates.

To make things more tight, we are now handling WebSWClientConnection messages on the same queue as WebSWContextManagerConnection.
When messages are to be sent to service workers, we directly hop to the service worker thread.
This allows the service worker messages to use the same path in WebSWClientConnection and WebSWContextManagerConnection.
For WebSWClientConnection messages that require getting to other workers or documents, we keep hopping to main thread.
Minor drive-by fix to make sure to call the completion handler in SWContextManager::fireNotificationEvent in case the worker is not there.

Changes are covered by existing tests.

* Source/WebCore/workers/Worker.cpp:
* Source/WebCore/workers/service/SWClientConnection.cpp:
(WebCore::SWClientConnection::jobRejectedInServer):
(WebCore::SWClientConnection::registrationJobResolvedInServer):
(WebCore::SWClientConnection::startScriptFetchForServer):
(WebCore::SWClientConnection::refreshImportedScripts):
(WebCore::SWClientConnection::postMessageToServiceWorkerClient):
(WebCore::forAllDedicatedAndSharedWorkers):
(WebCore::doUpdateRegistrationState):
(WebCore::SWClientConnection::updateRegistrationState):
(WebCore::doUpdateWorkerState):
(WebCore::SWClientConnection::updateWorkerState):
(WebCore::doFireUpdateFoundEvent):
(WebCore::SWClientConnection::fireUpdateFoundEvent):
(WebCore::doSetRegistrationLastUpdateTime):
(WebCore::SWClientConnection::setRegistrationLastUpdateTime):
(WebCore::doSetRegistrationUpdateViaCache):
(WebCore::SWClientConnection::setRegistrationUpdateViaCache):
(WebCore::SWClientConnection::notifyClientsOfControllerChange):
(WebCore::SWClientConnection::registerServiceWorkerClients):
(WebCore::forAllWorkers): Deleted.
* Source/WebCore/workers/service/SWClientConnection.h:
* Source/WebCore/workers/service/ServiceWorkerRegistrationData.h:
* Source/WebCore/workers/service/WorkerSWClientConnection.h:
* Source/WebCore/workers/service/context/SWContextManager.cpp:
(WebCore::SWContextManager::fireNotificationEvent):
(WebCore::SWContextManager::fireInstallEvent): Deleted.
(WebCore::SWContextManager::fireActivateEvent): Deleted.
* Source/WebCore/workers/service/context/SWContextManager.h:
* Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp:
(WebCore::ServiceWorkerFetch::dispatchFetchEvent):
* Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp:
(WebCore::ServiceWorkerThreadProxy::fireInstallEvent):
(WebCore::ServiceWorkerThreadProxy::fireActivateEvent):
* Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h:
* Source/WebCore/workers/shared/context/SharedWorkerContextManager.cpp:
* Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp:
(WebKit::NetworkProcessConnection::didReceiveMessage):
(WebKit::NetworkProcessConnection::didReceiveSyncMessage):
(WebKit::NetworkProcessConnection::serviceWorkerConnection):
* Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp:
(WebKit::WebSWClientConnection::~WebSWClientConnection):
(WebKit::WebSWClientConnection::establishConnection):
(WebKit::WebSWClientConnection::closeConnection):
(WebKit::WebSWClientConnection::messageSenderConnection const):
(WebKit::WebSWClientConnection::scheduleJobInServer):
(WebKit::WebSWClientConnection::finishFetchingScriptInServer):
(WebKit::WebSWClientConnection::addServiceWorkerRegistrationInServer):
(WebKit::WebSWClientConnection::removeServiceWorkerRegistrationInServer):
(WebKit::WebSWClientConnection::scheduleUnregisterJobInServer):
(WebKit::WebSWClientConnection::mayHaveServiceWorkerRegisteredForOrigin const):
(WebKit::WebSWClientConnection::setSWOriginTableSharedMemory):
(WebKit::WebSWClientConnection::setSWOriginTableIsImported):
(WebKit::WebSWClientConnection::runOrDelayTaskForImport):
(WebKit::WebSWClientConnection::whenRegistrationReady):
(WebKit::WebSWClientConnection::setServiceWorkerClientIsControlled):
(WebKit::WebSWClientConnection::connectionToServerLost):
(WebKit::WebSWClientConnection::clear):
(WebKit::WebSWClientConnection::terminateWorkerForTesting):
(WebKit::WebSWClientConnection::whenServiceWorkerIsTerminatedForTesting):
(WebKit::WebSWClientConnection::updateThrottleState):
(WebKit::WebSWClientConnection::storeRegistrationsOnDiskForTesting):
(WebKit::WebSWClientConnection::subscribeToPushService):
(WebKit::WebSWClientConnection::unsubscribeFromPushService):
(WebKit::WebSWClientConnection::getPushSubscription):
(WebKit::WebSWClientConnection::getPushPermissionState):
(WebKit::WebSWClientConnection::getNotifications):
(WebKit::WebSWClientConnection::enableNavigationPreload):
(WebKit::WebSWClientConnection::disableNavigationPreload):
(WebKit::WebSWClientConnection::setNavigationPreloadHeaderValue):
(WebKit::WebSWClientConnection::getNavigationPreloadState):
(WebKit::WebSWClientConnection::focusServiceWorkerClient):
(WebKit::WebSWClientConnection::refreshImportedScripts):
* Source/WebKit/WebProcess/Storage/WebSWClientConnection.h:
* Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp:
(WebKit::WebSWContextManagerConnection::sharedQueue):
(WebKit::m_userContentController):
(WebKit::WebSWContextManagerConnection::establishConnection):
(WebKit::WebSWContextManagerConnection::installServiceWorker):
(WebKit::WebSWContextManagerConnection::cancelFetch):
(WebKit::WebSWContextManagerConnection::continueDidReceiveFetchResponse):
(WebKit::WebSWContextManagerConnection::startFetch):
(WebKit::WebSWContextManagerConnection::postMessageToServiceWorker):
(WebKit::WebSWContextManagerConnection::fireInstallEvent):
(WebKit::WebSWContextManagerConnection::fireActivateEvent):
(WebKit::WebSWContextManagerConnection::firePushEvent):
(WebKit::WebSWContextManagerConnection::fireNotificationEvent):
(WebKit::WebSWContextManagerConnection::terminateWorker):
(WebKit::WebSWContextManagerConnection::didSaveScriptsToDisk):
(WebKit::WebSWContextManagerConnection::convertFetchToDownload):
(WebKit::WebSWContextManagerConnection::navigationPreloadIsReady):
(WebKit::WebSWContextManagerConnection::navigationPreloadFailed):
(WebKit::WebSWContextManagerConnection::skipWaitingCompleted):
(WebKit::WebSWContextManagerConnection::matchAllCompleted):
(WebKit::WebSWContextManagerConnection::setThrottleState):
(WebKit::m_queue): Deleted.
* Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h:
* Source/WebKit/WebProcess/WebProcess.cpp:
(WebKit::WebProcess::ensureNetworkProcessConnection):
@youennf youennf self-assigned this Jul 6, 2022
@youennf youennf added Service Workers Component for Service Workers bugs. WebKit Nightly Build labels Jul 6, 2022
@webkit-early-warning-system webkit-early-warning-system added the merging-blocked Applied to prevent a change from being merged label Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merging-blocked Applied to prevent a change from being merged Service Workers Component for Service Workers bugs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants