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

Maintain timing for worker start/ready, for navigation requests. #1575

Merged
merged 10 commits into from
May 13, 2021

Conversation

noamr
Copy link
Contributor

@noamr noamr commented Mar 28, 2021

The timing when worker is started or ready are web-accessible via
the navigation timing API (https://w3c.github.io/navigation-timing/).

workerStart is specified to be the time when the service worker is run.

In Chromium and Gecko, worker ready time (exposed as fetchStart)
is set to the right before the time when the Fetch event can be
dispatched for the newly created worker.

In preparation for w3c/navigation-timing#136


Preview | Diff

@noamr
Copy link
Contributor Author

noamr commented Mar 29, 2021

@jakearchibald @wanderview r?

@jakearchibald jakearchibald self-assigned this Apr 8, 2021
@jakearchibald
Copy link
Contributor

Sorry for the delay, I've been on leave. I'll try to get to this this week, or early next week.

@wanderview
Copy link
Member

Sorry, I missed I was tagged here. I generally defer to the editors to do spec reviews.

Copy link
Contributor

@jakearchibald jakearchibald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, and sorry for the delay reviewing. @mfalken and I took a look.

It isn't clear to me how these values will be read. I'm slightly worried that there's one service worker, therefore one "start time" and one "ready time", but many requests. It feels like "start time" and "ready time" might be overwritten by another request in a race.

Maybe these values should instead be associated with the response, since the timing is from the perspective of the request/response. But I'm just guessing, because I'm not sure how these values will be used.

For instance, if the service worker was started a year ago, and never closed for some reason, should "worker start" be the time a year ago, or should it be the time a given request decided it needed a service worker?

docs/index.bs Outdated
@@ -2971,6 +2975,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
1. Let |preloadResponse| be a new [=promise=].
1. Let |workerRealm| be null.
1. Let |eventHandled| be null.
1. Let |crossOriginIsolatedCapability| be |request|'s [=request/client=]'s [=environment settings object/cross-origin isolated capability=].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has someone familiar with isolation looked at this? Two timings are taken, once from "in parallel", and another from the service worker thread. Neither of these are the request's client, so does the request's client's cross-origin isolated capability apply here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's how things are done in FETCH. Not sure if it applies to service workers. in the same way. @annevk ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting as there might be a mismatch between the service worker agent and the requesting agent. I suspect we have to consult both and only if they are both true you would get the high-resolution time. Does that make sense?

That might be a change from what is implemented today as that probably only considers the requesting agent.

(Fetch uses the requesting agent exclusively as it doesn't create any agents of its own.)

docs/index.bs Outdated Show resolved Hide resolved
docs/index.bs Outdated
@@ -3020,6 +3025,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
1. If |shouldSoftUpdate| is true, then [=in parallel=] run the [=Soft Update=] algorithm with |registration|.
1. Return null.
1. If |activeWorker|'s <a>state</a> is "`activating`", wait for |activeWorker|'s <a>state</a> to become "`activated`".
1. Let |workerStartTime| be the [=coarsened shared current time=] given <var>crossOriginIsolatedCapability</var>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous step (If |activeWorker|'s <a>state</a> is "activating") probably should be included in this measurement, since we've decided we need a service worker, but it might not be ready. If the site is seeing long delays due to activation delays, that feels important.

docs/index.bs Outdated Show resolved Hide resolved
@wanderview
Copy link
Member

For instance, if the service worker was started a year ago, and never closed for some reason, should "worker start" be the time a year ago, or should it be the time a given request decided it needed a service worker?

Yea, I thought it would be the time the request decided it needed a service worker if the worker was already running.

@noamr
Copy link
Contributor Author

noamr commented Apr 9, 2021

Thanks for the PR, and sorry for the delay reviewing. @mfalken and I took a look.

It isn't clear to me how these values will be read. I'm slightly worried that there's one service worker, therefore one "start time" and one "ready time", but many requests. It feels like "start time" and "ready time" might be overwritten by another request in a race.

OK, I will change it to mean the "first" start/ready time. These values are only meant for Navigation Timing, I'll prepare a Navigation Timing PR that reads them to make it clearer. (they would have inter-dependencies so this one would have to go in first).

Maybe these values should instead be associated with the response, since the timing is from the perspective of the request/response. But I'm just guessing, because I'm not sure how these values will be used.

For instance, if the service worker was started a year ago, and never closed for some reason, should "worker start" be the time a year ago, or should it be the time a given request decided it needed a service worker?

The service worker's start time would be a year ago, but Navigation Timing would expose the later time between that time and the time FETCH has handed control over to the service worker.

@noamr
Copy link
Contributor Author

noamr commented Apr 11, 2021

I've refactored the PR, I agree that it makes much more sense to associate the info with the response rather than with the worker.
w3c/navigation-timing#143 is the navigation timing PR that shows how this info is going to be used. To complete the picture, we would need to modify two additional specs:

  • FETCH would have to send SW-FETCH the crossOriginIsolatedCapability as the second argument.
  • HTML would have to send the response's service worker timing when creating the navigation timing entry.

There are probably more ways to accomplish the same results, I went with the way that made the most sense to me but I'm open to refactor given an alternative approach.

docs/index.bs Outdated

Service workers mark certain points in times, that are later exposed by the {{PerformanceNavigationTiming|navigation timing}} API.

A [=/response=] has an associated null or [=service worker timing info=] <dfn export for=response>service worker timing</dfn>, initially set to null.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if we defined this in Fetch and SW just does the marking. Mainly to keep response defined in a single place.

Is it correct that this information gets lost if a network error is returned instead at some point?

Copy link
Contributor Author

@noamr noamr Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if we defined this in Fetch and SW just does the marking. Mainly to keep response defined in a single place.

OK. I was trying to make it so that FETCH doesn't have to be modified every time we add a new service-worker metric. Should the struct live in FETCH as well?

Is it correct that this information gets lost if a network error is returned instead at some point?

This is only exposed through Navigation Timing. So, if there's a network error, the document won't be loaded and these values would be meaningless. In other words, correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's okay to keep the struct here to make that easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jakearchibald I want to make sure we're OK with how this whole process works, and then I'll publish:

  1. A SW PR that defines the new struct
  2. A FETCH PR that associates the struct with a response and adds arguments to the SW FETCH call
  3. The marking part of the SW PR

Copy link
Contributor

@jakearchibald jakearchibald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes, but generally LGTM

docs/index.bs Outdated Show resolved Hide resolved
docs/index.bs Outdated Show resolved Hide resolved
docs/index.bs Outdated Show resolved Hide resolved
docs/index.bs Outdated Show resolved Hide resolved
docs/index.bs Outdated
@@ -2958,6 +2974,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe

: Input
:: |request|, a [=/request=]
:: |crossOriginIsolatedCapability|, a boolean
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't clear to me which client this isolation refers to. Maybe it should just be useHighResPerformanceTimers or something which makes the scope of its usage clear?

docs/index.bs Outdated
@@ -193,15 +193,31 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
* Detects abnormal operation: such as infinite loops and tasks exceeding imposed time limits (if any) while handling the events.
</section>

<section>
<section>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unintentional change?

docs/index.bs Outdated Show resolved Hide resolved
noamr added a commit to noamr/ServiceWorker that referenced this pull request Apr 15, 2021
to report worker-specific timing information to Navigation Timing.

In preparation for w3c#1575
jakearchibald pushed a commit that referenced this pull request Apr 27, 2021
to report worker-specific timing information to Navigation Timing.

In preparation for #1575
@jakearchibald
Copy link
Contributor

Give me a nudge when this is ready to go

@noamr
Copy link
Contributor Author

noamr commented Apr 27, 2021

Give me a nudge when this is ready to go

Thanks, will do! first I need to wait for the refs to apply and post a FETCH PR.

noamr added a commit to noamr/fetch that referenced this pull request May 9, 2021
In preparation for w3c/ServiceWorker#1575
and w3c/navigation-timing#143

This will allow exposing the service worker timing
as part of the Navigation Timing API.
annevk pushed a commit to whatwg/fetch that referenced this pull request May 10, 2021
noamr and others added 6 commits May 10, 2021 15:15
The timing when worker is started or ready are web-accessible via
the navigation timing API (https://w3c.github.io/navigation-timing/).

`workerStart` is specified to be the time when the service worker is run.

In Chromium and Gecko, `worker ready time` (exposed as `fetchStart`)
is set to the right before the time when the Fetch event can be
dispatched for the newly created worker.

In preparation for w3c/navigation-timing#136
Co-authored-by: Jake Archibald <jaffathecake@gmail.com>
Co-authored-by: Jake Archibald <jaffathecake@gmail.com>
Temporarily remove response association, as that moves to FETCH.
@noamr noamr force-pushed the nav-time-integ branch from fd4c075 to e556803 Compare May 11, 2021 06:23
@noamr
Copy link
Contributor Author

noamr commented May 11, 2021

Give me a nudge when this is ready to go

Nudge @jakearchibald :)

noamr added a commit to noamr/html that referenced this pull request May 11, 2021
Service Workers now expose a "service worker timing info" that
is associated with a request. HTML should pass it to Navigation Timing
together with the other info.

See also w3c/navigation-timing#143
and w3c/ServiceWorker#1575
@annevk
Copy link
Member

annevk commented May 11, 2021

What about #1575 (comment)?

@noamr
Copy link
Contributor Author

noamr commented May 12, 2021

What about #1575 (comment)?

Fixed in new revision.

docs/index.bs Outdated Show resolved Hide resolved
@jakearchibald jakearchibald merged commit 4b5d041 into w3c:main May 13, 2021
@jakearchibald
Copy link
Contributor

Thank you @noamr!

noamr added a commit to noamr/html that referenced this pull request Jun 24, 2021
Service Workers now expose a "service worker timing info" that
is associated with a request. HTML should pass it to Navigation Timing
together with the other info.

See also w3c/navigation-timing#143
and w3c/ServiceWorker#1575
annevk pushed a commit to whatwg/html that referenced this pull request Jul 21, 2021
Amend the parameters passed when creating the navigation timing info entry to include the service worker timing info. Also, pass 0 for redirectCount When cross-origin redirects occurred as part of the navigation.

See also w3c/navigation-timing#143 and w3c/ServiceWorker#1575.
mfreed7 pushed a commit to mfreed7/html that referenced this pull request Jun 3, 2022
Amend the parameters passed when creating the navigation timing info entry to include the service worker timing info. Also, pass 0 for redirectCount When cross-origin redirects occurred as part of the navigation.

See also w3c/navigation-timing#143 and w3c/ServiceWorker#1575.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants