New issue
Advanced search Search tips

Issue 924043 link

Starred by 3 users

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug

Blocked on:
issue 906850

Blocking:
issue 538751


Participants' hotlists:
Worker-OffTheMainThread


Sign in to add a comment

Implement off-the-main-thread service worker script fetch

Project Member Reported by nhiroki@chromium.org, Today (21 hours ago)

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.
 

Comment 1 by wanderview@chromium.org, Today (13 hours ago)

Out of curiosity, how will this interact with new renderer process creation?  Will the SW script loads, worker thread, or other initialization work be started sooner or later compared to today in that case?

The UMA data for the unready/new process case is much slower, so I was just wondering how these changes would work there.

Internal link:

https://uma.googleplex.com/p/chrome/timeline_v2?sid=3a2b9af42ad1c2edfc5c8a211397e8b7

Comment 2 by hirosh...@chromium.org, Today (9 hours ago)

Blockedon: 906850

Comment 3 by nhiroki@google.com, 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. 

Comment 4 by nhiroki@chromium.org, Today (5 hours ago)

Blocking: 538751

Comment 5 by nhiroki@chromium.org, 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