Implement off-the-main-thread service worker script fetch |
|||
Issue description
In the current implementation, top-level service worker script is fetched from the main thread via WorkerClassicScriptLoader (see WebEmbeddedWorkerImpl::OnShadowPageInitialized()). To avoid dependencies on the main thread, that should be done from the worker thread.
Implementation plan
1) Add a runtime flag like OffMainThreadServiceWorkerScriptFetch, and wrap following steps with flag checks.
2) In WebEmbeddedWorkerImpl::OnShadowPageInitialize(), bypass WorkerClassicScriptLoader creation, and call StartWorkerThread() like the mojom::ScriptType::kModule case.
3) In WebEmbeddedWorkerImpl::StartWorkerThread(), call WorkerThread::ImportClassicScript() instead of WorkerThread::EvaluateClassicScript(). A worker script will be fetched and evaluated on the worker thread.
Testing plan
- Run web_tests with the OffMainThreadServiceWorkerScriptFetch flag. For references, see "omt-worker-fetch" in VirtualTestSuites ("omt-worker-fetch" is the test setting for off-the-main-thread dedicated worker script fetch).
References
- dedicated_worker.cc does the similar thing for off-the-main-thread dedicated worker script fetch. Search the code by RuntimeEnabledFeatures::OffMainThreadWorkerScriptFetchEnabled.
,
Today
(9 hours ago)
,
Today
(5 hours ago)
I'm not fully sure about the new renderer process creation, but I guess this change doesn't affect that because this is the thing within a renderer process. The timing of worker thread initialization will become sooner. In the current implementation, a renderer process fetches a worker script on the main thread, and then starts a worker thread. After this change, a renderer process starts a worker thread first, and then fetches a worker script from the worker thread. This change reduces the number of async tasks on the main thread, so this is expected to improve the startup performance especially when the main thread is busy.
,
Today
(5 hours ago)
,
Today
(5 hours ago)
FYI: We've been working on the same thing for dedicated workers (issue 835717) and shared workers (issue 924041). |
|||
►
Sign in to add a comment |
|||
Comment 1 by wanderview@chromium.org
, Today (13 hours ago)