WICG / frame-timing

Frame Timing API
https://wicg.github.io/frame-timing/
Other
170 stars 18 forks source link

update Duration and cpuTime descriptions per dicussion #22

Closed mpb closed 9 years ago

mpb commented 9 years ago

Updating description for 'duration' and 'cpuTime' parameters for issue #3.

This clarifies a few points: 1) duration is measured as per requestAnimationFrame's definition of "start time" until the next VSYNC boundary this frame can make. This means duration will be approximately 16, 32, etc for ~60 FPS, depending on if you made or missed a particular deadline. It is a binary signal showing that you are missing deadlines.

2) 'cpuTime' captures wall clock EXCLUDING idle time. It is meant to show how much headroom you have when you make a deadline, or how much you missed by, when you miss one (or more.)

3) cpuTime is not an OS-level CPU time, it continues counting if the thread is descheduled and is a MAX() not a SUM() of all concurrent threads processing (if there are more than one thread). This is intentional because as a web developer, you have some amount of resources to use and are trying to use them to achieve a desired effect (smoothly!) It is the kernel and the user agent's job to manage system resources, and distribute time fairly.

Please let me know if the wording is clear, and if this makes sense in a vendor-agnostic way. Thanks!

mithro commented 9 years ago

I'm confused here.

@igrigorik commented 13 days ago in #1

(based on a video chat w/ Michael)... cpuTime looks good. wallTime is better handled via duration attribute (see #3), which we can update to capture the total time to process the frame, instead of defining it as time between startTime's of subsequent frames. This allows developers to (a) detect if they're exceeding the frame budget, and if so (b) by how much.. instead of just getting a 'previous frame was painted 33ms ago'.

Which my understanding meant;

It seems that the discussion has moved onward somewhat and this is no longer the case?

Now some specific comments on this change.

Looking at the new definition of duration;

The <code>duration</code> attribute will return a <a href="http://www.w3.org/TR/hr-time/#domhighrestimestamp"><code>DOMHighResTimeStamp</code></a> with the duration of the frame, computed by subtracting the <code>startTime</code> of the current frame from the next possible v-sync boundary, or <code>startTime</code> of the next frame, if available. <code>duration</code> should capture the entire wall-clock duration of the current frame, INLCUDING any idle, blocking or descheduled time.</p>

Its starts by saying that "duration = nextFrame.startTime - currentFrame.startTime", which because startTime is wall time, must also be wall time. Then it goes on to add some extra clarification statements that only make sense if duration was defined in some other way, such as time to render.

It should also be noted, with this definition, the duration is thus always going to be a multiple of the vsync interval. It gives the person no idea how much of the frame budget is being used.

This attribute must return a <a href="#bib-HR-Time">[High Resolution Time]</a> duration giving the actual wall-clock time used to process this frame EXCLUDING any idle time. The user agent SHOULD include the time spent on JavaScript execution, accessing and modifying the DOM and CSSOM, and other relevant processing operations required to render the frame (e.g. layout, style recalculations, painting, and so on).

With this definition I think idle time definitely needs some clarification and the text you have added to the duration would actually make sense here. Reading this for the first time, I would have assume idle time means any time you are not rendering - which to me would include time that you are not running such as being descheduled.

igrigorik commented 9 years ago

(housekeeping to bring together parallel threads)

natduca commented 9 years ago

This seems sane to switch to wall time. However, I'd encourage us to not use the word cpu in any fields so that we can reserve that keyword for a follow-on spec on cpu timing.

igrigorik commented 9 years ago

For sake of clarity, let's revisit the underlying use cases:

  1. As a developer I want to know the frame rate, as it is experienced by real users on their actual devices, such that I can detect poorly performing devices, user-agents, and/or deployed code.
  2. As a developer I want to know how much room I have in the per-frame (16ms) budget (or, by how much I have exceeded it), such that I can:
    • distinguish between frames that are barely under budget vs. have lots of headroom
    • if applicable, determine by how much the budget was exceeded

To fulfill (1) we only need to provide duration, which can be defined as frame.startTime ~> next vsync. The resulting (DOMHighResTimeStamp) value will always be a multiple of 16, and that's exactly what we're looking for. As a developer I can monitor this value to detect jank (duration > 16). I think Michael's definition for duration (modulo some editorial nitpicks -- see above) satisfies this... lgtm.

To fulfill (2) we need to provide the wall-clock time that excludes idle time -- I think Michael's definition satisfies this. To address @natduca's suggestion of avoiding mentions of "cpu", which may be a more general concept (see https://github.com/w3c/frame-timing/issues/1#issuecomment-67047641), how about simplifying the attribute name to cost - i.e. frame cost was X ms.

WDYT?

vmpstr commented 9 years ago

cost sgtm! I think that would allow us to move past cpu vs wall clock time for now. As a quick way forward, can we create a separate issue/pull request that just renames it?

mpb commented 9 years ago

Of course. I should probably split this request into 2 anyway, one for duration and one for name/text change. Should I wait for consensus here, or do that and they can be commented on individually?

igrigorik commented 9 years ago

@mpb split 'em, we can continue the discussion on newer drafts.

igrigorik commented 9 years ago

@mpb thanks, merged! All, please take a quick pass over:

In the meantime, closing this to unblock @plehegar from going forward with FPWD.

igrigorik commented 9 years ago

To clarify, if anyone has objections to above, please let us know.. we can continue to iterate.

mithro commented 9 years ago

See an issue I raised at https://github.com/w3c/frame-timing/issues/29 regarding the new duration definition.