RegisterServiceWorker takes a few seconds during browser startup |
|
Issue descriptionUpon extension activation, we call SWContext::RegisterServiceWorker for extensions that has service worker based background page: https://cs.chromium.org/chromium/src/extensions/browser/service_worker_task_queue.cc?rcl=1dc552ddcb02514f082f9316008f52e82d86da3c&l=221 This takes several seconds if this is called during browser startup, so the worker starts running after 3-7 seconds in practice (locally). Later during browser lifetime, a new extension install's activation takes less than half a second. I wonder whether this is something SW specific, or this is extension's interaction with SW specific. I'll look into it further, but /cc Matt in case he has any idea?
,
Oct 4
(adding info) I've looked into it, it seems SW registration goes through BrowserThread::PostAfterStartupTask [1]. Didn't know about this method's existence :) Indeed the time to pick a |task| from AfterStartupTask[1] matches the timing (/slowness) I'm seeing for extension Service Workers. I'll look further tomorrow, likely at the very least, will skip calling register for already installed extension at startup. (There's a TODO somewhere for that) [1] https://cs.chromium.org/chromium/src/content/browser/browser_thread_impl.cc?rcl=68b5a64d76886f888e33baddb0640b608beb3042&l=147 [2] https://cs.chromium.org/chromium/src/chrome/browser/after_startup_task_utils.cc?rcl=512a27e206291de8f7bdf452de12b186805e3607&l=45
,
Oct 4
The correct link for [1] ^^^ should have been: https://cs.chromium.org/chromium/src/content/browser/service_worker/service_worker_register_job.cc?rcl=2f7072ffff307c184dc25700eebd16078cbb72b8&l=107
,
Nov 2
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/70f76ac2064343d9bec7b5905e0859c321360dae commit 70f76ac2064343d9bec7b5905e0859c321360dae Author: Istiaque Ahmed <lazyboy@chromium.org> Date: Fri Nov 02 02:59:55 2018 Register SW based script only on first time extension activation. During browser startup, registering a service worker can be slow (in order of a few seconds). We currently register SW based extension's script on every extension activation (when we load extensions), which isn't necessary as SW registrations are suppose to persist across browser restart by design. Add a pref to remember the fact that we have successfully registered an extension's background SW script for a particular version of that extension and use that to decide whether or not to register the SW during OnActivateExtension. This CL will improve SW based extension's startup time. Bug: 889687 Test: Demo browser clock extension doesn't lag much with the change (note that this is requires local modification to chromium, specifically Patchset #2) Change-Id: Icfb7174be27f65a1cb6b8ac6d99ddc6b33fdf1c0 Reviewed-on: https://chromium-review.googlesource.com/c/1265821 Commit-Queue: Istiaque Ahmed <lazyboy@chromium.org> Reviewed-by: Devlin <rdevlin.cronin@chromium.org> Cr-Commit-Position: refs/heads/master@{#604823} [modify] https://crrev.com/70f76ac2064343d9bec7b5905e0859c321360dae/chrome/browser/extensions/service_worker_apitest.cc [add] https://crrev.com/70f76ac2064343d9bec7b5905e0859c321360dae/chrome/test/data/extensions/api_test/service_worker/worker_based_background/registration_at_startup/manifest.json [add] https://crrev.com/70f76ac2064343d9bec7b5905e0859c321360dae/chrome/test/data/extensions/api_test/service_worker/worker_based_background/registration_at_startup/service_worker_background.js [modify] https://crrev.com/70f76ac2064343d9bec7b5905e0859c321360dae/extensions/browser/service_worker_task_queue.cc [modify] https://crrev.com/70f76ac2064343d9bec7b5905e0859c321360dae/extensions/browser/service_worker_task_queue.h
,
Nov 2
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/773a61096c9cf501b863e31a76ab45c5c73d8783 commit 773a61096c9cf501b863e31a76ab45c5c73d8783 Author: Daniel Bratell <bratell@opera.com> Date: Fri Nov 02 11:02:04 2018 [jumbo][extensions] Give two kPrefsName unique names In jumbo builds many cc files compile in the same translation unit which also means that they share the same anonymous namespace. That means that constant names need to be unique in the whole build target even if they are in anonymous namespaces. A service worker extension just introduced a second kPrefsName into extensions/browser which broke some (but not all) jumbo build configurations. This patch renames them both to prevent confusion (from compiler or human). TBR=lazyboy@chromium.org,rdevlin.cronin@chromium.org Bug: 889687 Change-Id: I6d3d44d9941038cc8e2304bc3100c7e681ea18a9 Reviewed-on: https://chromium-review.googlesource.com/c/1314468 Reviewed-by: Daniel Bratell <bratell@opera.com> Commit-Queue: Daniel Bratell <bratell@opera.com> Cr-Commit-Position: refs/heads/master@{#604882} [modify] https://crrev.com/773a61096c9cf501b863e31a76ab45c5c73d8783/extensions/browser/extension_prefs.cc [modify] https://crrev.com/773a61096c9cf501b863e31a76ab45c5c73d8783/extensions/browser/service_worker_task_queue.cc |
|
►
Sign in to add a comment |
|
Comment 1 by lazyboy@chromium.org
, Sep 27Status: Assigned (was: Untriaged)