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

Report A and script loading to resource timing #7180

Merged
merged 15 commits into from
Jan 27, 2022

Conversation

noamr
Copy link
Contributor

@noamr noamr commented Oct 7, 2021

Starting with two elements that perform a full download, and have decent
HTML/fetch integration. Finalize and report resource timing once the response body is fully read or there is a network error,
and before any load/error events are fired.

Resolves part of #6542

A element: report resource timing for download & ping
Script: report resource timing for importing, classic and worker.

Reporting is always done before load/error events are fired, so that
those events could get access to the new entry.

[x] At least two implementers are interested (and none opposed):
This is already implemented in Chrome, Safari and Firefox, and was previously spec'ed as part of resource timing.
Some of the specific discrepancies will be handled as part of WPT.

[x] New tests for previously unspecified scenarios: web-platform-tests/wpt#32513

[X] Implementation bugs are filed:

Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=1290356
Firefox: No currently known bugs
Safari: No currently known bugs
(See WHATWG Working Mode: Changes for more details.)


/infrastructure.html ( diff )
/links.html ( diff )
/webappapis.html ( diff )


/infrastructure.html ( diff )
/links.html ( diff )
/webappapis.html ( diff )

Copy link
Collaborator

@yoavweiss yoavweiss left a comment

Choose a reason for hiding this comment

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

Non-authoritative LGTM % nit

source Show resolved Hide resolved
@noamr noamr force-pushed the report-some-resource-timing branch from 3ad0e7f to 84873cb Compare December 14, 2021 16:14
@noamr
Copy link
Contributor Author

noamr commented Jan 17, 2022

@domenic, review when possible please?

source Outdated
<i data-x="processResponseConsumeBody">processResponseConsumeBody</i> given
<span data-x="concept-response">response</span> <var>res</var> set to
<span>finalize and report timing</span> with <var>res</var>, the
<span>current global object</span>, and "a".</p></li>
Copy link
Member

Choose a reason for hiding this comment

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

"<code data-x="">a</code>"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

source Outdated
@@ -24226,7 +24227,11 @@ document.body.appendChild(wbr);</code></pre>
</dl>
</li>

<!--FETCH--><li><p><span data-x="concept-fetch">Fetch</span> <var>request</var>.</p></li>
<!--FETCH--><li><p><span data-x="concept-fetch">Fetch</span> <var>request</var>, with
<i data-x="processResponseConsumeBody">processResponseConsumeBody</i> given
Copy link
Member

Choose a reason for hiding this comment

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

This ties into whatwg/fetch#1382 ... if someone sends a long trickle body, do we really want to wait for it before finalizing and reporting timing? What do browsers do? That issue suggests maybe they terminate the body early?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Chrome does something equivalent to processResponseEndOfBody. I'll revise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

source Outdated

<ol>
<li><p><span>Finalize and report timing</span> with <var>response</var>, the
<span>current global object</span> and "script".</p></li>
Copy link
Member

Choose a reason for hiding this comment

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

"<code data-x="">script</code>"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

source Outdated
@@ -91620,7 +91637,9 @@ document.querySelector("button").addEventListener("click", bound);
<span>JavaScript MIME type</span>,</p>
</ul>

<p>then asynchronously complete this algorithm with null, and return.</p>
<p>then <span>finalize and report timing</span> with <var>response</var>, the
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 we should consolidate this into the previous step now. Something like:

If any of the following conditions are met:

  • x;
  • y; or
  • z and w

then:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

source Outdated
@@ -91635,6 +91654,9 @@ document.querySelector("button").addEventListener("click", bound);
data-x="concept-response-url">url</span>, and the <span>default classic script fetch
options</span>.</p></li>

<li><p><span>Finalize and report timing</span> with <var>response</var>, the
<span>current global object</span> and "script".</p></li>
Copy link
Member

Choose a reason for hiding this comment

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

Is it correct that this happens after parsing? I could imagine parsing taking a few milliseconds...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to make it happen prior to parsing

source Outdated

<p class="note"><var>response</var> is always <span>CORS-same-origin</span>.</p>
</li>

<li><p><span>Finalize and report timing</span> with <var>response</var>, the
<span>current global object</span> and "script".</p></li>
Copy link
Member

Choose a reason for hiding this comment

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

Here you report timing before parsing happens. That is cleaner since then you don't have duplicate "finalize and report timing with response, the current global object, and script".

source Outdated
<i data-x="processResponseConsumeBody">processResponseConsumeBody</i> given
<span data-x="concept-response">response</span> <var>res</var> set to
<span>finalize and report timing</span> with <var>res</var>, the
<span>current global object</span>, and "a".</p></li>
Copy link
Member

Choose a reason for hiding this comment

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

There is no "current global object" in most of these algorithms. You need to use the <span data-x="concept-settings-object-global">global object</span> of one of the various settings objects passed into each algorithm. (I'm not sure which one in each case...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@noamr noamr force-pushed the report-some-resource-timing branch from 0b529b6 to e51e434 Compare January 19, 2022 09:39
source Outdated
<i data-x="processResponseEndOfBody">processResponseEndOfBody</i> given
<span data-x="concept-response">response</span> <var>res</var> set to
<span>finalize and report timing</span> with <var>res</var>, <var>global</var>, and
"<code data-x="">ping</code>".</p></li>
Copy link
Member

Choose a reason for hiding this comment

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

OK, so to be clear, if the body is not fully downloaded (because the server trickles it, for example) by the time the page unloads due to the link navigation, no resource timing entry will be created. Is that correct? Are there tests for that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By the time the page unloads you can't test whether an RT entry is created.
But RT entry is created when for example you have a link with a target attribute. I'll make sure tests cover this.

Copy link
Member

Choose a reason for hiding this comment

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

Right. I was thinking that maybe browsers sent the resource timing when the response headers came in, not when the whole body did. It sounds like that is not the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, I double-checked this.

source Outdated
<li><p>Let <var>global</var> be the
<span data-x="concept-settings-object-global">global object</span> of the
<span>environment settings object</span> of the <code>Document</code> containing the
<span>hyperlink</span>.
Copy link
Member

@domenic domenic Jan 19, 2022

Choose a reason for hiding this comment

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

"the Document containing the hyperlink" is not defined (although I see that is used in preexisting text); nor is "the environment settings object of [a Document]".

It'd be best to factor this out as follows:

  • Let client be the element's node document's relevant settings object.
  • Later, passing client's global object to "finalize and report timing".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I called it settingsObject rather than client, seemed more explicit. Otherwise fixed.

source Outdated
@@ -91917,7 +91930,18 @@ document.querySelector("button").addEventListener("click", bound);
<span>ok status</span>,</p></li>
</ul>

<p>then asynchronously complete this algorithm with null, and return.</p>
<p>then:</p>
Copy link
Member

Choose a reason for hiding this comment

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

This did not get fixed: #7180 (comment)

Copy link
Contributor Author

@noamr noamr Jan 19, 2022

Choose a reason for hiding this comment

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

OK, maybe I misunderstood that original comment. Will reread

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I refactored that bit, hope it's satisfactory.

source Outdated Show resolved Hide resolved
source Outdated
algorithm, and run the remaining steps as part of the fetch's <span>process response</span> for
the <span data-x="concept-response">response</span> <var>response</var>.</p>
algorithm, and run the remaining steps as part of the fetch's
<i>processResponseConsumeBody</i> for <span data-x="concept-response">response</span>
Copy link
Member

Choose a reason for hiding this comment

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

Please make this cross-link to the definition in Fetch, with the appropriate data-x attribute on the <i>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

source Outdated

<p class="note"><var>response</var> is always <span>CORS-same-origin</span>.</p>
</li>

<li><p><span>Finalize and report timing</span> with <var>response</var>, the
<span>current global object</span> and "script".</p></li>
Copy link
Member

Choose a reason for hiding this comment

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

Missing code around script

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@noamr
Copy link
Contributor Author

noamr commented Jan 24, 2022

@domenic, re-review? :)

@domenic
Copy link
Member

domenic commented Jan 24, 2022

Sorry, on my near-term to-do list but I got to the end of another the day without having made the time. Tomorrow for sure!

source Outdated
<var>response</var>, <var>fetch client settings object</var>'s
<span data-x="concept-settings-object-global">global object</span>, and
"<code data-x="">other</code>", asynchronously complete this algorithm with
null, and return.</p>
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, this is still not great.

To be clear, the structure in your PR right now is:

  1. If either of the following conditions are met:
    • x; or
    • y
      then:
    1. Finalize and report...
    2. Asynchronously complete with null
    3. Return.
  2. If z and w, then: finalize and report..., asynchronously complete with null, and return.

Can you see how this is bad? I am proposing instead we do the following:

  1. If any of the following conditions are met:
    • x;
    • y; or
    • z and w
      then:
    1. Finalize and report...
    2. Asynchronously complete with null
    3. Return.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I see what you mean now. It was entirely unclear to me what you meant in the original comment.

source Outdated
<li><p>Let <var>source text</var> be the result of <span data-x="UTF-8 decode">UTF-8
<li><p><span>Finalize and report timing</span> with <var>response</var>,
<var>fetch client settings object</var>'s
<span data-x="concept-settings-object-global">global object</span> and
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<span data-x="concept-settings-object-global">global object</span> and
<span data-x="concept-settings-object-global">global object</span>, and

source Outdated
<span data-x="concept-settings-object-global">global object</span> and
"<code data-x="">other</code>".</p></li>

<li><p>Let <var>source text</var> be the result of <span data-x="UTF-8 decode">UTF-8
Copy link
Member

Choose a reason for hiding this comment

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

Indentation changed here, but it should not.

source Show resolved Hide resolved
Starting with two elements that perform a full download, and have decent
HTML/fetch integration.

A element: report resource timing for download & ping
Script: report resource timing for importing, classic and worker.

Reporting is *always* done before load/error events are fired, so that
those events could get access to the new entry.
- Use proper global object from env settings
- Report before parsing
- Change callback for ping
@noamr noamr force-pushed the report-some-resource-timing branch from 062c28b to 75f9b84 Compare January 26, 2022 13:07
@noamr
Copy link
Contributor Author

noamr commented Jan 26, 2022

@domenic: I did a major refactor to use processResponseAndConsumeBody which makes reporting a lot more straightforward.

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

This works pretty well. At some point we should clean the surrounding code in the script-fetching algorithms up to use the second parameter to processResponseConsumeBody, instead of what it currently does of UTF-8 decoding response's body. But that is a preexisting problem and I'm happy to tackle it separately, now that you've factored this PR to not touch that part of things.

Tests look pretty comprehensive so I think this is ready to merge. I'll do so tomorrow unless anyone has thoughts.

@domenic domenic merged commit e8e499e into whatwg:main Jan 27, 2022
@noamr noamr deleted the report-some-resource-timing branch January 28, 2022 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants