New issue
Advanced search Search tips

Issue 921289 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: Jan 16
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

consider creating the ServiceWorkerSubresourceLoaderFactory eagerly

Project Member Reported by wanderview@chromium.org, Jan 12

Issue description

Currently it seems we start creating the ServiceWorkerSubresourceLoaderFactory the first time we need to create a URLLoader for ResourceLoader.  This then fires a task to a background thread to wire up the mojo connection to the service worker

I've noticed on a site with performance issues that there is a long "ServiceWorker Preparation" time for the first stylesheet loaded by the preload scanner.  I wonder if this delay is due to the time required to execute this background setup work necessary to communicate with the service worker.

Would it be possible to eagerly create the ServiceWorkerSubresourceLoaderFactory when the DocumentLoader is first created so that it has some time to run in the background before the preload scanner issues its first request? 
 
Work-in-progress CL:

https://chromium-review.googlesource.com/c/chromium/src/+/1407671

I haven't had time to take a lot of measurements, but initial testing looks promising.  The "ServiceWorker Preparation" time of the google sheets core stylesheet drops from 18ms to 9ms at the median.  That was only 10 samples in each mode on my fast laptop, though.  I'll do a more thorough measurement on the slow laptop Monday.
Looks good to investigate. Not sure whether SWSubresourceLoaderFactory creation is included in "ServiceWorker Preparation". It looks like "SW Preparation" is calculated by ResourceResponseInfo::service_worker_ready_time - service_worker_start_time (which are set in subresource requests in S13nSW by ServiceWorkerSubresourceLoader).
https://cs.chromium.org/chromium/src/third_party/blink/renderer/devtools/front_end/network/RequestTimingView.js?l=154&rcl=dd05131f5782853146226091e1c4d1209c47e2bb
Ah, good point.  So if this change has any effect, if any, then it will just show up in COV.

I'm unsure of what to make of the high "ServiceWorker Preparation" times, though.  It seems like the worker should be running since the navigation FetchEvent was handled.  I wonder if there is can be some delay with mojo creating the pipe for the connector to the service worker.
Maybe its because we lazily call EnsureControllerConnection() on the first DispatchFetchEvent:

https://cs.chromium.org/chromium/src/content/renderer/service_worker/controller_service_worker_connector.cc?l=33&rcl=dd05131f5782853146226091e1c4d1209c47e2bb

I'll try adding a step to my CL to eagerly call that as well.
So far I'm not really seeing any benefit here.  I'm going to try to dig into chrome://tracing to see whats going on.
#c4 doesn't matter because we get the connection in the initial subresource params.  EnsureControllerConnection() is essentially a no-op in this case.
I mean GetControllerServiceWorker() can just return the ControllerServiceWorker without calling the remote EnsureControllerServiceWorker() mojo call.
Owner: ----
I can't measure any benefit here:

https://docs.google.com/spreadsheets/d/15HzaL0NgCZ3yynS5bzIfWilKUnOm0EZtVT2EdaYcPU0/edit?usp=sharing

I'm going to leave this open in case any thinks we should do it anyway, but it would be a bit speculative.  Feel free to WONTFIX.

Comment 9 by falken@chromium.org, Jan 16 (6 days ago)

Status: WontFix (was: Untriaged)
To follow up here, wanderview@ found the high Preparation time was the queuing time fo the fetch event.  I think S13nSW changed the meaning of SW Preparation but we can revisit that in another bug. I'll wontfix for now, we can reopen if we discover bottlenecks in traces.

Sign in to add a comment