Skip to content

Commit

Permalink
Integrate with the Paint Timing spec
Browse files Browse the repository at this point in the history
This eliminates Paint Timing's monkey patching, and fixes some minor
issues with when we mark paint timing. It does so by introducing the new
concept of "rendering opportunity", which roughly maps to frame rate,
but in a model-agnostic way.

This also lays the groundwork necessary to correctly report event
duration for the Event Timing spec, per the issue at
w3c/event-timing#6.
  • Loading branch information
tdresser authored and domenic committed Aug 16, 2018
1 parent 34cc15a commit 92b90bd
Showing 1 changed file with 64 additions and 36 deletions.
100 changes: 64 additions & 36 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -2880,6 +2880,12 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li><dfn data-x-href="https://w3c.github.io/webappsec-mixed-content/#a-priori-authenticated-url"><i>a priori</i> authenticated URL</dfn></li>
</ul>

<p>The following terms are defined in <cite>Paint Timing</cite>: <ref spec=PAINTTIMING></p>

<ul class="brief">
<li><dfn data-x-href="https://w3c.github.io/paint-timing/#mark-paint-timing">mark paint timing</dfn></li>
</ul>

</dd>


Expand Down Expand Up @@ -89134,45 +89140,63 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {
</li>

<li>
<p>If there are <span data-x="top-level browsing context">top-level browsing contexts</span>
<var>B</var> that the user agent believes would not benefit from having their rendering
updated at this time, then remove from <var>docs</var> all <code>Document</code> objects whose
<span data-x="concept-document-bc">browsing context</span>'s <span>top-level browsing
context</span> is in <var>B</var>.</p>

<div class="note">
<p>Whether a <span>top-level browsing context</span> would benefit from having its rendering
updated depends on various factors, such as the update frequency. For example, if the browser
is attempting to achieve a 60Hz refresh rate, then these steps are only necessary every 60th
of a second (about 16.7ms). If the browser finds that a <span>top-level browsing
context</span> is not able to sustain this rate, it might drop to a more sustainable 30Hz for
that set of <code>Document</code>s, rather than occasionally dropping frames. (This
specification does not mandate any particular model for when to update the rendering.)
Similarly, if a <span>top-level browsing context</span> is in the background, the user agent
might decide to drop that page to a much slower 4Hz, or even less.</p>

<p>Another example of why a browser might skip updating the rendering is to ensure certain
<span data-x="concept-task">tasks</span> are executed immediately after each other, with only
<span data-x="perform a microtask checkpoint">microtask checkpoints</span> interleaved (and
without, e.g., <span data-x="run the animation frame callbacks">animation frame
callbacks</span> interleaved). For example, a user agent might wish to coalesce timer
callbacks together, with no intermediate rendering updates.</p>
</div>
<p><i>Rendering opportunites</i>: If there are <span data-x="browsing context">browsing
contexts</span> <var>browsingContexts</var> that do not have a <span>rendering
opportunity</span>, then remove from <var>docs</var> all <code>Document</code> objects whose
<span data-x="concept-document-bc">browsing context</span> is in
<var>browsingContexts</var>.</p>

<p>A <span>browsing context</span> has a <dfn>rendering opportunity</dfn> if the user agent is
currently able to present the contents of the <span>browsing context</span> to the user,
accounting for hardware refresh rate constraints and user agent throttling for performance
reasons, but considering content presentable even if it's outside the viewport.</p>

<p><span>Browsing context</span> <span data-x="rendering opportunity">rendering
opportunities</span> are determined based on hardware constraints such as display refresh
rates and other factors such as page performance or whether the page is in the background.
Rendering opportunities typically occur at regular intervals.</p>

<p class="note">This specification does not mandate any particular model for selecting
rendering opportunities. But for example, if the browser is attempting to achieve a 60Hz
refresh rate, then rendering opportunities occur at a maximum of every 60th of a second (about
16.7ms). If the browser finds that a <span>browsing context</span> is not able to sustain this
rate, it might drop to a more sustainable 30 rendering opportunities per second for that
<span>browsing context</span>, rather than occasionally dropping frames. Similarly, if a
<span>browsing context</span> is not visible, the user agent might decide to drop that page to
a much slower 4 rendering opportunities per second, or even less.</p>
</li>

<li><p><i>Unnecessary rendering</i>: If there are <span data-x="browsing context">browsing
contexts</span> <var>browsingContexts</var> for which the user agent believes updating the
rendering would have no visible effect and which possess no <code>Document</code> objects with
a non-empty <span>list of animation frame callbacks</span>, then remove from <var>docs</var>
all <code>Document</code> objects whose <span data-x="concept-document-bc">browsing
context</span> is in <var>browsingContexts</var>. Invoke the <span>mark paint timing</span>
algorithm for each <code>Document</code> object removed.</p></li>

<li>
<p>If there are a <span data-x="nested browsing context">nested browsing contexts</span>
<var>B</var> that the user agent believes would not benefit from having their rendering
updated at this time, then remove from <var>docs</var> all <code>Document</code> objects whose
<span data-x="concept-document-bc">browsing context</span> is in <var>B</var>.</p>

<p class="note">As with <span data-x="top-level browsing context">top-level browsing
contexts</span>, a variety of factors can influence whether it is profitable for a browser to
update the rendering of <span data-x="nested browsing context">nested browsing
contexts</span>. For example, a user agent might wish to spend less resources rendering
third-party content, especially if it is not currently visible to the user or if resources are
constrained. In such cases, the browser could decide to update the rendering for such content
infrequently or never.</p>
<p>If there are <span data-x="browsing context">browsing contexts</span>
<var>browsingContexts</var> for which the user agent believes it's preferrable to skip
updating the rendering for other reasons, then remove from <var>docs</var> all
<code>Document</code> objects whose <span data-x="concept-document-bc">browsing context</span>
is in <var>browsingContexts</var>.</p>

<div class="note">
<p>The step labeled <i>Rendering opportunities</i> prevents the user agent from updating the
rendering when it is unable to present new content to the user (there's no <span>rendering
opportunity</span>).</p>

<p>The step labeled <i>Unnecessary rendering</i> prevents the user agent from updating the
rendering when there's no new content to draw.</p>

<p>This step enables the user agent to prevent the steps below from running for other
reasons, for example, to ensure certain <span data-x="concept-task">tasks</span> are executed
immediately after each other, with only <span data-x="perform a microtask
checkpoint">microtask checkpoints</span> interleaved (and without, e.g., <span data-x="run
the animation frame callbacks">animation frame callbacks</span> interleaved). Concretely, a
user agent might wish to coalesce timer callbacks together, with no intermediate rendering
updates.</p>
</div>
</li>

<li><p>For each <span>fully active</span> <code>Document</code> in <var>docs</var>, <span>run
Expand Down Expand Up @@ -89203,6 +89227,9 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {
the update intersection observations steps</span> for that <code>Document</code>, passing in
<var>now</var> as the timestamp. <ref spec="INTERSECTIONOBSERVER"></p></li>

<li><p>Invoke the <span>mark paint timing</span> algorithm for each <code>Document</code>
object in <var>docs</var>.</p></li>

<li><p>For each <span>fully active</span> <code>Document</code> in <var>docs</var>, update the
rendering or user interface of that <code>Document</code> and its <span
data-x="concept-document-bc">browsing context</span> to reflect the current state.</p></li>
Expand Down Expand Up @@ -121911,6 +121938,7 @@ INSERT INTERFACES HERE
Thomas Koetter,
Thomas O'Connor,
Tim Altman,
Tim Dresser,
Tim Johansson,
Tim Perry,
Tim van der Lippe,
Expand Down

0 comments on commit 92b90bd

Please sign in to comment.