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

Explainer for Timing Information of Static Routing API #25

Merged
merged 3 commits into from
May 13, 2024

Conversation

quasi-mod
Copy link
Contributor

This PR adds the explainer for timing information for Static Routing API.
I will post the explainer in this comment as well for review purposes (the image might be broken due to link
issues. All the images are contained within the PR).


Explainer for timing info for Static Routing API

Authors

Participate

Abstract

  • Introduce timing info for the ServiceWorker Static Routing API in Resource Timing API and Navigation Timing API.

Background

The ServiceWorker Static Routing API

The startup of ServiceWorkers, a web platform feature that brings application-like
experience to users, is known to be a slow process. If the ServiceWorker intercepts loading the page
resources, web users may need to wait for the startup to complete in order for the page loading to start.

Service Worker Static Routing API was introduced to mitigate this issue by letting the
developers selectively choose whether the ServiceWorker should intercept the
navigation, and allow them to specify when to not run ServiceWorker.
In addition, it allows the developers to offload simple ServiceWorker operations
like cache look up. i.e. they can return resources from CacheStorage without running
ServiceWorkers.

Timing Info of ServiceWorkers

Service Worker provides timing information to mark certain points
in time. This is exposed and used by the navigation timing API
as well as the resource timing API. It currently records two times:

  • Start time
  • Fetch event dispatch time

However, it currently does not have any fields related to the ServiceWorker Static
Routing API. Developers would benefit from having fields that provide information such as:

  • the matched route (the route that the Static Routing API evaluated)
  • the actual source from which the resource was retrieved
  • the time it took to match the route

This information will allow developers to measure the latency incurred by the Static
Routing API such as router evaluation time or time required to conduct cache lookup,
or determine if the matched source is the final source used (can find out if the
matched source failed to get the resource or not, and which source was used as
the alternative).

Proposal

Overview of ResourceTiming

We add the following two timing information:

  • workerRouterEvaluationStart
    • A DOMHighResTimeStamp, initially 0
    • Time to start matching a request with registered router rules
  • workerCacheLookupStart
    • A DOMHighResTimeStamp, initially 0
    • Time to start looking up the cache storage if the source is "cache"

In addition to the timestamp information, we also add the following two route source information:

  • matchedRouterSource
    • A RouterSource, initially empty string
    • The enum string of the matched source (the source of result of router evaluation)
      • This shall match to "network", "cache", "fetch-event", or "race-network-and-fetch-handler". If no rule is matched, it shall be an empty string.
  • finalRouterSource
    • A RouterSource, initially empty string
    • The enum string of the used source
      • This shall match to "network", "cache", or "fetch-event"
      • When a matched router source exists, this should match to the MatchedRouterSource, unless in "race-network-and-fetch-handler", where the winner of the race will be the final source (either "network" or "fetch-event"). Otherwise, it should remain as an empty string.

Example code

Fetch Rule Specified

ResourceTiming (fetch-event)

// Add route inside ServiceWorker
addEventListener('install', (event) => {
  event.addRoutes({
    condition: {
      urlPattern: {pathname: "/form/*"}
    },
    source: "fetch-event"
  });
})
// Measure routerEvaluationTime 
let timing = window.performance.timing;
let routerEvaluationTime = 0.0;
switch (timing.finalRouteSource) {
  case "network":
    // Indicates that the fetch fallback to network.
    routerEvaluationTime = timing.fetchStart - timing.workerRouterEvaluationStart;
    break;
  case 'fetch-event':
    routerEvaluationTime = timing.workerStart - timing.workerRouterEvaluationStart;
    break;
  case "cache":
    // UNREACHABLE
    break;
}

Network Rule Specified

ResourceTiming (network)

// Add route inside ServiceWorker
addEventListener('install', (event) => {
  event.addRoutes({
    condition: {
      urlPattern: {pathname: "/form/*"}
    },
    source: "network"
  });
})
// Measure routerEvaluationTime 
let timing = window.performance.timing;
let routerEvaluationTime = 0.0;
switch (timing.finalRouteSource) {
  case "network":
    // Routed to network
    routerEvaluationTime = timing.fetchStart - timing.workerRouterEvaluationStart;
    break;
  case "cache":
  case "fetch-event":
    // UNREACHABLE
    break;
}

Race Rule Specified

ResourceTiming (race-network-and-fetch-event)

// Add route inside ServiceWorker
addEventListener('install', (event) => {
  event.addRoutes({
    condition: {
      urlPattern: {pathname: "/form/*"}
    },
    source: "race-network-and-fetch-event"
  });
})
// Measure routerEvaluationTime 
let timing = window.performance.timing;
let routerEvaluationTime = 0.0;
switch (timing.finalRouteSource) {
  case "network":
    // Indicates that the network has won the race, 
    // or the fetch event has failed.
    routerEvaluationTime = timing.fetchStart - timing.workerRouterEvaluationStart;
    break;
  case 'fetch-event':
    // Indicates that the fetch has won the race.
    routerEvaluationTime = timing.workerStart - timing.workerRouterEvaluationStart;
    break;
  case "cache":
    // UNREACHABLE
    break;
}

Cache Rule Specified

ResourceTiming (cache)

// Add route inside ServiceWorker
addEventListener('install', (event) => {
  event.addRoutes({
    condition: {
      urlPattern: {pathname: "/form/*"}
    },
    source: "cache"
  });
})
// Measure routerEvaluationTime and cacheLookupTime
let timing = window.performance.timing;
let routerEvaluationTime = 0.0;
let cacheLookupTime = 0.0;
switch (timing.FinalRouteSource) {
  case "network":
    // Cache miss. Fallback to network. 
    routerEvaluationTime = timing.cacheLookupStart - timing.routerEvaluationStart;
    cacheLookupTime = time.fetchStart - time.workerCacheLookupStart;
    break;
  case "cache":
    // Cache Hit.
    routerEvaluationTime =
        timing.cacheLookupStart - timing.workerRouterEvaluationStart;
    cacheLookupTime =
        time.responseStart - time.cacheLookupStart;
  case "fetch-event":
    // UNREACHABLE
    break;
}

Recorded timing per matched route

As mentioned above, the recorded fields will be different depending on the matched source. The fields to be recorded per source is as follows (✔ indicates recorded, ✘ indicates not recorded).

RouterEvaluationStart CacheLookupStart fetchStart
Matched Source Fetch
Network
Race (Network vs Fetch)
Cache
None Matched

Correspondence of the Matched Source Type and the Actual Source Type

In some situations, the actual source type will be different from the matched source
type. This includes cases such as "race-network-and-fetch-event" where the result
of the race will be the actual route, or "cache" where a cache miss occurs.

The full list of correspondence of the matched source type and the actual source
type is as follows:

Actual Source
Fetch Network Cache
Matched Source Fetch Fetch (Success) Network

(Fallback: Fetch handler is invalid)

N/A
Network N/A Network (Success) N/A
Race (Network vs Fetch) Fetch

(Fetch win)

Network

(Network win or Fetch fallback)

N/A
Cache N/A Network

(Fallback: Cache Missed)

Cache

(Cache hit)

None matched N/A (null) N/A (null) N/A

Discussions

What to include in actual source when there is no matched source

When no matching rule is found, matchedRouterSource is an empty string, and we use
the ServiceWorker to fetch the resources. To indicate this case, there is a
discussion on what the finalRouterSource field should contain. We came up with
two possible solutions:

  1. Set empty string to finalRouterSource as well
  2. Set the actual source to finalRouteSource ("fetch-event" or "network", if it falls back)

We are currently planning to pursue Solution 1.

Solution 2 does expose more information to developers, but the exposed information
is independent from ServiceWorker Static Routing API as it is about whether
ServiceWorker fetch has succeeded or not. Although this should be taken into
consideration in the future, we concluded that such information would be out of
scope of Timing Info for the API.

fetchStart on Cache Hit

When the cache is specified as the source and the resource is found in the cache
(cache hit), no fetch operation is performed. Therefore, fetchStart will not be set.

@quasi-mod quasi-mod changed the title Explainer for resource timing of Static Routing API Explainer for Timing Information of Static Routing API May 10, 2024
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 10, 2024
This CL adds WPTs for Service Worker Static Routing API Resource Timing.
It conducts a set of tests to determine if the resource timing is
correctly working on each source type, and on main and sub-resources.

Explainer: WICG/service-worker-static-routing-api#25
Bug: 41496865
Change-Id: Ide7d352d4824b9491645964febb6522ffe71aafb
@yoshisatoyanagisawa yoshisatoyanagisawa merged commit 4ad7468 into WICG:main May 13, 2024
1 check passed
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 15, 2024
This CL adds WPTs for Service Worker Static Routing API Resource Timing.
It conducts a set of tests to determine if the resource timing is
correctly working on each source type, and on main and sub-resources.

Explainer: WICG/service-worker-static-routing-api#25
Bug: 41496865
Change-Id: Ide7d352d4824b9491645964febb6522ffe71aafb
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 15, 2024
This CL adds WPTs for Service Worker Static Routing API Resource Timing.
It conducts a set of tests to determine if the resource timing is
correctly working on each source type, and on main and sub-resources.

Explainer: WICG/service-worker-static-routing-api#25
Bug: 41496865
Change-Id: Ide7d352d4824b9491645964febb6522ffe71aafb
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 16, 2024
This CL adds WPTs for Service Worker Static Routing API Resource Timing.
It conducts a set of tests to determine if the resource timing is
correctly working on each source type, and on main and sub-resources.

Explainer: WICG/service-worker-static-routing-api#25
Bug: 41496865
Change-Id: Ide7d352d4824b9491645964febb6522ffe71aafb
aarongable pushed a commit to chromium/chromium that referenced this pull request May 20, 2024
This CL adds the relevant fields of load timing information for
ServiceWorker Static Routing API. In detail, it adds two fields:
`service_worker_router_evaluation_start` which tracks the time when
router evaluation started, and `service_worker_cache_lookup_start` which
tracks when the cache lookup started when the source is matched to
`cache`.

Explainer: WICG/service-worker-static-routing-api#25
Bug: 41496865
Change-Id: I9dd0566ad1f4f726f8b1d2f5258f0bca657070da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5524581
Reviewed-by: Shunya Shishido <sisidovski@chromium.org>
Reviewed-by: Yoshisato Yanagisawa <yyanagisawa@chromium.org>
Commit-Queue: Keita Suzuki <suzukikeita@chromium.org>
Reviewed-by: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1303195}
aarongable pushed a commit to chromium/chromium that referenced this pull request May 20, 2024
This CL adds timing information for ServiceWorker Static Routing API
timing information. It adds two new fields to Resource Timing API and
Navigation Timing API: RouterEvaluationStart and CacheLookupStart. This
allows for developers to measure time such as time required for router
evaluation, or cache lookup.

Explainer: WICG/service-worker-static-routing-api#25
Bug: 41496865

Change-Id: I533d5ed96ce0fd013bf9ed2c2830dc389a2ea7db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5505211
Reviewed-by: Yoshisato Yanagisawa <yyanagisawa@chromium.org>
Reviewed-by: Kouhei Ueno <kouhei@chromium.org>
Reviewed-by: Takashi Toyoshima <toyoshim@chromium.org>
Reviewed-by: Shunya Shishido <sisidovski@chromium.org>
Commit-Queue: Keita Suzuki <suzukikeita@chromium.org>
Reviewed-by: Minoru Chikamune <chikamune@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1303197}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 20, 2024
This CL adds WPTs for Service Worker Static Routing API Resource Timing.
It conducts a set of tests to determine if the resource timing is
correctly working on each source type, and on main and sub-resources.

Explainer: WICG/service-worker-static-routing-api#25
Bug: 41496865
Change-Id: Ide7d352d4824b9491645964febb6522ffe71aafb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5521193
Reviewed-by: Minoru Chikamune <chikamune@chromium.org>
Reviewed-by: Yoshisato Yanagisawa <yyanagisawa@chromium.org>
Reviewed-by: Shunya Shishido <sisidovski@chromium.org>
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Keita Suzuki <suzukikeita@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1303199}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 20, 2024
This CL adds WPTs for Service Worker Static Routing API Resource Timing.
It conducts a set of tests to determine if the resource timing is
correctly working on each source type, and on main and sub-resources.

Explainer: WICG/service-worker-static-routing-api#25
Bug: 41496865
Change-Id: Ide7d352d4824b9491645964febb6522ffe71aafb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5521193
Reviewed-by: Minoru Chikamune <chikamune@chromium.org>
Reviewed-by: Yoshisato Yanagisawa <yyanagisawa@chromium.org>
Reviewed-by: Shunya Shishido <sisidovski@chromium.org>
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Keita Suzuki <suzukikeita@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1303199}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request May 23, 2024
…g API Resource Timing, a=testonly

Automatic update from web-platform-tests
Add WPTs for ServiceWorker Static Routing API Resource Timing

This CL adds WPTs for Service Worker Static Routing API Resource Timing.
It conducts a set of tests to determine if the resource timing is
correctly working on each source type, and on main and sub-resources.

Explainer: WICG/service-worker-static-routing-api#25
Bug: 41496865
Change-Id: Ide7d352d4824b9491645964febb6522ffe71aafb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5521193
Reviewed-by: Minoru Chikamune <chikamune@chromium.org>
Reviewed-by: Yoshisato Yanagisawa <yyanagisawa@chromium.org>
Reviewed-by: Shunya Shishido <sisidovski@chromium.org>
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Keita Suzuki <suzukikeita@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1303199}

--

wpt-commits: 1b18480d9b8d67d7e9eefa225277443503b2199b
wpt-pr: 46182
jamienicol pushed a commit to jamienicol/gecko that referenced this pull request May 24, 2024
…g API Resource Timing, a=testonly

Automatic update from web-platform-tests
Add WPTs for ServiceWorker Static Routing API Resource Timing

This CL adds WPTs for Service Worker Static Routing API Resource Timing.
It conducts a set of tests to determine if the resource timing is
correctly working on each source type, and on main and sub-resources.

Explainer: WICG/service-worker-static-routing-api#25
Bug: 41496865
Change-Id: Ide7d352d4824b9491645964febb6522ffe71aafb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5521193
Reviewed-by: Minoru Chikamune <chikamune@chromium.org>
Reviewed-by: Yoshisato Yanagisawa <yyanagisawa@chromium.org>
Reviewed-by: Shunya Shishido <sisidovski@chromium.org>
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Keita Suzuki <suzukikeita@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1303199}

--

wpt-commits: 1b18480d9b8d67d7e9eefa225277443503b2199b
wpt-pr: 46182
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.

None yet

2 participants