From 4c93f891e1c0236fef51f68fa07a64c4e67a4b18 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Fri, 17 Jun 2022 14:06:53 +0300 Subject: [PATCH] Inline "finalize and report timing" As long as fetch callers pass in the necessary data through the request concept, they will not have to make additional calls to get timing reported accurately. Note that this does not work if callers want to use useParallelQueue. Downstream PRs: * https://github.com/whatwg/html/pull/7722 * https://github.com/whatwg/xhr/pull/347 * https://github.com/w3c/csswg-drafts/pull/7355 * https://github.com/w3c/beacon/pull/75 * https://github.com/w3c/resource-timing/pull/321 * https://github.com/w3c/navigation-timing/pull/1760 Closes #1208 and closes https://github.com/w3c/navigation-timing/pull/131. --- fetch.bs | 263 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 146 insertions(+), 117 deletions(-) diff --git a/fetch.bs b/fetch.bs index ae1bef392..2b71b3a5d 100644 --- a/fetch.bs +++ b/fetch.bs @@ -225,8 +225,34 @@ lt="authentication entry">authentication entries (for HTTP authentication).
state (default "ongoing")
"ongoing", "terminated", or "aborted" + +
full timing info (default null) +
Null or a fetch timing info. + +
report timing steps (default null) +
Null or an algorithm accepting a global object.
+

To report timing for a +fetch controller controller given a global object global: + +

    +
  1. Assert: this's report timing steps is not + null. + +

  2. Call this's report timing steps with global. +

+ +

To extract full timing info +given a fetch controller controller: + +

    +
  1. Assert: this's full timing info is not + null. + +

  2. Return this's full timing info. +

+

To abort a fetch controller controller, set controller's state to "aborted". @@ -258,10 +284,6 @@ following items: [[RESOURCE-TIMING]] [[NAVIGATION-TIMING]]

end time (default 0)
A {{DOMHighResTimeStamp}}. -
encoded body size (default 0) -
decoded body size (default 0) -
A number. -
final connection timing info (default null)
Null or a connection timing info. @@ -269,6 +291,18 @@ following items: [[RESOURCE-TIMING]] [[NAVIGATION-TIMING]]
A list of strings. +

A response body info is a struct used to maintain +information needed by Resource Timing and Navigation Timing. It has the +following items: [[RESOURCE-TIMING]] [[NAVIGATION-TIMING]] + +

+
encoded + size (default 0) +
decoded + size (default 0) +
A number. +
+

To create an opaque timing info, given a fetch timing info timingInfo, return a new @@ -276,22 +310,6 @@ given a fetch timing info timingInfo, return a new post-redirect start time are timingInfo's start time. -

To update timing info from stored response, given a -connection timing info timingInfo and a response -response, perform the following steps: - -

    -
  1. Let storedTimingInfo be response's timing info. - -

  2. If storedTimingInfo is null, then return. - -

  3. Set timingInfo's encoded body size to - storedTimingInfo's encoded body size. - -

  4. Set timingInfo's decoded body size to - storedTimingInfo's decoded body size. -

-

To queue a fetch task, given an algorithm algorithm, a global object or a parallel queue taskDestination, run these steps: @@ -1404,6 +1422,32 @@ this flag set are subject to additional processing requirements.

A request has an associated service-workers mode, that is "all" or "none". Unless stated otherwise it is "all". +

A request has an associated +initiator type, which is null, +"audio", +"beacon", +"body", +"css", +"early-hint", +"embed", +"fetch", +"font", +"frame", +"iframe", +"image", +"img", +"input", +"link", +"object", +"ping", +"script", +"track", +"video", +"xmlhttprequest", or +"other". Unless stated otherwise it is null. [[RESOURCE-TIMING]] + +

This determines which service workers will receive a {{fetch!!event}} event for this fetch. @@ -2084,7 +2128,7 @@ message as HTTP/2 does not support them.

A response has an associated cache state (the empty string, -"local", or "validated"). Unlesss stated otherwise, it is the empty +"local", or "validated"). Unless stated otherwise, it is the empty string.

This is intended for usage by Service Workers and @@ -2123,8 +2167,9 @@ the response of a redirect has to be set if it was set for previous responses in this is also tracked internally using the request's timing allow failed flag.

A response has an associated -timing info (null or a -fetch timing info), which is initially null. +body info +(a response body info). Unless stated otherwise, it is a new +response body info.

A response has an associated service worker timing info (null or a @@ -3838,6 +3883,7 @@ the request.

  • Let fetchParams be a new fetch params whose request is request, timing info is timingInfo, + controller is controller, process request body chunk length is processRequestBodyChunkLength, process request end-of-body is processRequestEndOfBody, @@ -4283,28 +4329,13 @@ steps: fetchParams and a response response, run these steps:

      -
    1. -

      If response is a network error, then: - -

        -
      1. -

        Set response's URL list to « fetchParams's - request's URL list[0] ». - -

        This is needed as after cloning fetchParams's - request's URL list earlier, response - might have been set to a network error.

        -
      2. - -
      3. Set response's timing info to the result of - creating an opaque timing info for fetchParams's - timing info.

      4. -
      +
    2. Let timingInfo be fetchParams's + timing info.

    3. -

      Otherwise, if fetchParams's request's - client is a secure context, set response's - timing info's server-timing headers to the +

      If response is not a network error and fetchParams's + request's client is a secure context, then set + timingInfo's server-timing headers to the result of getting, decoding, and splitting `Server-Timing` from response's header list. @@ -4315,12 +4346,68 @@ steps:

      Let processResponseEndOfBody be the following steps:

        -
      1. Set fetchParams's request's - done flag. +

      2. Let unsafeEndTime be the unsafe shared current time. + +

      3. If fetchParams's request's + destination is "document", then set fetchParams's + controller's full timing info to + fetchParams's timing info. + +

      4. +

        Set fetchParams's controller's + report timing steps to the following steps given a + global object global: -

      5. If fetchParams's process response end-of-body is not - null, then queue a fetch task to run fetchParams's - process response end-of-body given response with +

          +
        1. If fetchParams's request's URL's + scheme is not an HTTP(S) scheme, then return. + +

        2. Set timingInfo's end time to the + relative high resolution time given unsafeEndTime and + global. + +

        3. Let cacheState be response's cache state. + +

        4. Let bodyInfo be response's body info. + +

        5. +

          If response's timing allow passed flag is not set, + then set timingInfo to a the result of creating an opaque timing info for + timingInfo, set bodyInfo to a new response body info, and + set cacheState to the empty string. + +

          This covers the case of response being a network error. + +

        6. If fetchParams's request's + initiator type is not null, then + mark resource timing given timingInfo, request's + URL, request's + initiator type, global, cacheState, and + bodyInfo. +

        + +
      6. +

        Let processResponseEndOfBodyTask be the following steps: + +

          +
        1. Set fetchParams's request's + done flag. + +

        2. If fetchParams's process response end-of-body is + non-null, then run fetchParams's + process response end-of-body given response. + +

        3. If fetchParams's request's + initiator type is non-null and fetchParams's + request's client's + global object is fetchParams's + task destination, then run fetchParams's + controller's report timing steps given + fetchParams's request's client's + global object. +

        + +
      7. Queue a fetch task to run processResponseEndOfBodyTask with fetchParams's task destination.

    4. @@ -4378,49 +4465,6 @@ steps:
    -

    To finalize and report timing given a response -response, a global object global, and a string -initiatorType (default "other"), run these steps: - -

      -
    1. If response is an aborted network error, then return. - -

    2. If response's URL list is null or - empty, then return. - -

    3. Let originalURL be response's URL list[0]. - -

    4. Let timingInfo be response's timing info. - -

    5. Let cacheState be response's cache state. - -

    6. If originalURL's scheme is not an HTTP(S) scheme, then - return. - -

    7. If timingInfo is null, then return. - -

    8. -

      If response's timing allow passed flag is not set, then: - -

        -
      1. Set timingInfo to a the result of creating an opaque timing info for - timingInfo. - -

      2. Set cacheState to the empty string. -

      - -
    9. Set timingInfo's end time to the - coarsened shared current time given global's - relevant settings object's - cross-origin isolated capability. - -

    10. Set response's timing info to timingInfo. - -

    11. Mark resource timing for timingInfo, originalURL, - initiatorType, global, and cacheState. -

    - -

    Scheme fetch

    To scheme fetch, given a @@ -4590,9 +4634,6 @@ these steps: final service worker start time to serviceWorkerStartTime. -

  • Update timing info from stored response given fetchParams's - timing info and response. -

  • If request's body is non-null, then cancel request's body with undefined. @@ -4725,15 +4766,6 @@ these steps: -
  • -

    Set response's timing info to timingInfo. - -

    Attaching the timing info to a response is what makes it exposed to the web as a - Resource Timing entry later. This step is done here, as resource-timing entries are available only - for HTTP fetches, including ones that are handled by service-workers or HTTP cache, and not for, - e.g., data:, blob: URL fetches, and are only available after all the - relevant security checks have succeeded. -

  • Return response. Typically actualResponse's body's stream is still being enqueued to after returning. @@ -5259,9 +5291,6 @@ steps. They return a response.

  • Set response to storedResponse.

  • Set response's cache state to "validated". - -

  • Update timing info from stored response given fetchParams's - timing info and response.

  • @@ -5278,7 +5307,7 @@ steps. They return a response.

    If forwardResponse is a network error, this effectively caches the network error, which is sometimes known as "negative caching". -

    The associated timing info is stored in the cache +

    The associated body info is stored in the cache alongside the response. @@ -5686,8 +5715,9 @@ optional boolean forceNewConnection (default false), run these steps:

  • Let codings be the result of extracting header list values given `Content-Encoding` and response's header list. -

  • Increase timingInfo's encoded body size - by bytes's length. +

  • Increase response's body info's + encoded size by bytes's + length.

  • Set bytes to the result of handling content @@ -5696,7 +5726,8 @@ optional boolean forceNewConnection (default false), run these steps:

    This makes the `Content-Length` header unreliable to the extent that it was reliable to begin with. -

  • Increase timingInfo's decoded body size by +

  • Increase response's body info's + decoded size by bytes's length.

  • If bytes is failure, then terminate @@ -7066,6 +7097,9 @@ constructor steps are:

    URL list
    A clone of request's URL list. + +
    initiator type +
    "fetch".
  • @@ -7715,15 +7749,10 @@ method steps are: controller. -
  • Let handleFetchDone given response response be to - finalize and report timing with response, globalObject, and - "fetch". -

  • Set controller to the result of calling fetch given - request, with processResponseEndOfBody set to - handleFetchDone, and processResponse given response - being these substeps: + request and processResponse given response being + these substeps:

    1. If locallyAborted is true, terminate these substeps.