Abstract

This specification defines an interface to help web developers measure the performance of their applications by giving them access to frame performance data to facilitate smoothness (i.e. Frames per Second and Time to Frame) measurements.

Status of This Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.

This is a work in progress and may change without any notices.

This document was published by the Web Performance Working Group as a Working Draft. This document is intended to become a W3C Recommendation. If you wish to make comments regarding this document, please send them to public-web-perf@w3.org (subscribe, archives) with [Frame Timing] at the start of your email's subject. All comments are welcome.

Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

This document is governed by the 1 September 2015 W3C Process Document.

Table of Contents

1. Introduction

This section is non-normative.

Web developers need the ability to assess and understand the performance characteristics of their applications. While JavaScript [ECMA-262] provides a mechanism to approximate application Frames per Second (FPS) and Time to Frame (TTF) (by calling a nearly empty requestAnimationFrame [Animation-Timing] in a loop), the precision of this method has a high variance. Some example situations where this returns misleading results are:

This document defines the PerformanceRenderTiming and PerformanceCompositeTiming interfaces, and extensions to the Performance interface, which expose frame performance data to be used for smoothness measurements.

2. Conformance

As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.

The key words MAY, MUST, and SHOULD are to be interpreted as described in [RFC2119].

Requirements phrased in the imperative as part of algorithms (such as "strip any leading space characters" or "return false and abort these steps") are to be interpreted with the meaning of the key word ("MUST", "SHOULD", "MAY", etc) used in introducing the algorithm.

Some conformance requirements are phrased as requirements on attributes, methods or objects. Such requirements are to be interpreted as requirements on user agents.

Conformance requirements phrased as algorithms or specific steps may be implemented in any manner, so long as the end result is equivalent. (In particular, the algorithms defined in this specification are intended to be easy to follow, and not intended to be performant.)

The IDL fragments in this specification MUST be interpreted as required for conforming IDL fragments, as described in the Web IDL specification. [WebIDL]

3. Terminology

The construction "a Foo object", where Foo is actually an interface, is sometimes used instead of the more accurate "an object implementing the interface Foo".

The term "JavaScript" is used to refer to ECMAScript [ECMA-262], rather than the official term ECMAScript, since the term JavaScript is more widely known.

4. Frame Timing

4.1 Introduction

This section is non-normative.

The PerformanceRenderTiming and PerformanceCompositeTiming interfaces, and extensions to the Performance interface, enable web developers to measure the performance of their applications by giving them access to frame performance data to facilitate smoothness (i.e. FPS and TTF) measurements:

The relationship between PerformanceRenderTiming and PerformanceCompositeTiming events will vary based on the workload, and architecture and configuration of the user agent. For example, the user agent may report many PerformanceCompositeTiming events corresponding to a single PerformanceRenderTiming event due to a CSS animation, composite thread scrolling, or similar activities. Other workloads may result in 1:1 mapping of PerformanceRenderTiming and PerformanceCompositeTiming events, and the exact relationship is also subject to user agent architecture and configuration.

4.2 Extensions to the Performance Interface

partial interface Performance {
    void clearFrameTimings ();
    void setFrameTimingBufferSize (unsigned long maxSize);
                attribute EventHandler onframetimingbufferfull;
};

4.2.1 Attributes

onframetimingbufferfull of type EventHandler,
The event handler for the frametimingbufferfull event. Immediately after the buffer used to store the list of PerformanceRenderTiming and PerformanceCompositeTiming resources becomes full, the User Agent MUST fire a simple event named frametimingbufferfull that bubbles, isn't cancelable, has no default action, at the Performance object [Navigation-Timing-2].

4.2.2 Methods

clearFrameTimings
The method clearFrameTimings clears the buffer used to store the current list of PerformanceRenderTiming resources.
No parameters.
Return type: void
setFrameTimingBufferSize
The setFrameTimingBufferSize method, when invoked, MUST set the maximum number of PerformanceRenderTiming resources that may be stored in the buffer to the value of the maxSize parameter.
ParameterTypeNullableOptionalDescription
maxSizeunsigned long The maxSize parameter sets the maximum number of PerformanceRenderTiming resources that will be stored in the buffer.
Return type: void

4.3 The PerformanceRenderTiming Interface

The PerformanceRenderTiming interface participates in the Performance Timeline and extends the following attributes of the PerformanceEntry interface [Performance-Timeline]:

name
This attribute MUST return the current document's address.
entryType
This attribute MUST return the DOMString "render".
startTime
This attribute MUST return a DOMHighResTimeStamp with current frame's beginning time value, which is the time that the requestAnimationFrame callback (see [Animation-Timing]) would have fired for the frame. [HR-Time].
duration
This attribute MUST return a DOMHighResTimeStamp with the difference between the end of the frame and the startTime of the frame. The end of the frame is defined as what the beginning time of the next frame's requestAnimationFrame callback (see [Animation-Timing]) would have been, had one been scheduled in the current frame. If a requestAnimationFrame is already requested, its beginning time SHOULD be used.
interface PerformanceRenderTiming : PerformanceEntry {
    readonly    attribute unsigned long sourceFrameNumber;
    serializer = {inherit, attribute};
};

4.3.1 Attributes

sourceFrameNumber of type unsigned long, readonly
This attribute MUST return the source frame number for the event. This is used to correlate PerformanceRenderTiming and PerformanceCompositeTiming events to measure time-to-frame delays.

4.3.2 Serializer

Instances of this interface are serialized as a map with entries from the closest inherited interface and with entries for each of the serializable attributes.

4.4 The PerformanceCompositeTiming Interface

The PerformanceCompositeTiming interface participates in the Performance Timeline and extends the following attributes of the PerformanceEntry interface [Performance-Timeline]:

name
This attribute MUST return the name of the requesting document.
entryType
This attribute MUST return the DOMString "composite".
startTime
This attribute MUST return a DOMHighResTimeStamp with the event's time value [HR-Time].
duration
The duration attribute MUST return a DOMHighResTimeStamp of value 0.
interface PerformanceCompositeTiming : PerformanceEntry {
    readonly    attribute unsigned long sourceFrameNumber;
    serializer = {inherit, attribute};
};

4.4.1 Attributes

sourceFrameNumber of type unsigned long, readonly
This attribute MUST return the last known source frame number for the event. This is used to correlate PerformanceRenderTiming and PerformanceCompositeTiming events to measure time-to-frame delays.

4.4.2 Serializer

Instances of this interface are serialized as a map with entries from the closest inherited interface and with entries for each of the serializable attributes.

5. Monotonic Clock

The time values stored within the interface MUST monotonically increase to ensure they are not affected by adjustments to the system clock. The difference between any two chronologically recorded time values MUST never be negative. The user agent MUST record the system clock at the beginning of the navigation and define subsequent time values in terms of a monotonic clock measuring time elapsed from the beginning of the navigation.

6. Privacy and Security

This section is non-normative.

The interfaces defined in this specification expose potentially sensitive timing information on specific JavaScript activity of a page. However, unlike other interfaces defined in the Performance Timeline, the interfaces defined in this specification do not have any restrictions on sharing timing information through script. This is because the web platform has been designed with the invariant that any script included on a page has the same access as any other script included on that page regardless of the origin of the script.

A. Acknowledgments

Thanks to Enne Walker, Rick Byers, Chris Harrelson, Timothy Robert Ansell, Vladimir Levin, and Nat Duca for their helpful comments and contributions to this work.

B. References

B.1 Normative references

[Animation-Timing]
James Robinson; Cameron McCormack. Timing control for script-based animations. 31 October 2013. W3C Candidate Recommendation. URL: http://www.w3.org/TR/animation-timing/
[HR-Time]
Jatinder Mann. High Resolution Time. 17 December 2012. W3C Recommendation. URL: http://www.w3.org/TR/hr-time/
[Navigation-Timing-2]
Tobin Titus; Jatinder Mann; Arvind Jain. Navigation Timing Level 2. 18 September 2015. W3C Working Draft. URL: http://www.w3.org/TR/navigation-timing-2/
[Performance-Timeline]
Jatinder Mann; Zhiheng Wang. Performance Timeline. 12 December 2013. W3C Recommendation. URL: http://www.w3.org/TR/performance-timeline/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://tools.ietf.org/html/rfc2119
[WebIDL]
Cameron McCormack; Boris Zbarsky. WebIDL Level 1. 4 August 2015. W3C Working Draft. URL: http://www.w3.org/TR/WebIDL-1/

B.2 Informative references

[ECMA-262]
Allen Wirfs-Brock. ECMA-262 6th Edition, The ECMAScript 2015 Language Specification. June 2015. Standard. URL: http://www.ecma-international.org/ecma-262/6.0/