The purpose of this document is to describe use cases which may be relevant to the Frame Timing API.
Authors:
Many complex web apps suffer from poor responsiveness and animation rate (also known as "jank"). This causes a poor user experience and users may complain about the UI being "slow", "stuck" or "not smooth". The common symptom for these poor experiences is the occurrence of long frames. In many cases the UI response to the user takes longer than 100ms or an animation’s frame rate drops below 60 FPS - which indicates frames longer than 16.5ms have occurred. See RAIL guidelines for more details.
Detecting, tracking and diagnosing these degraded experiences is not a trivial task for engineers building and running the apps. Engineers need ways to detect and track long frame occurrences during a user interaction.
Browsers currently do not provide Web APIs to detect and track long frames. In order to detect and track long frames in web apps developers came up with different solutions which all have significant downsides as will be outlined below.
The requestAnimationFrame Web API (rAF) is often used to measure frame length. A common pattern is to instrument a callback that records a timestamp once every frame using rAF. The gap between any two consecutive timestamps is considered “frame length”.
This approach has several downsides:
Similar to long task measuring methods, idle callbacks are essentially JavaScript code running when the callback queue is empty. Therefore, it can be tracked using techniques similar to the aforementioned methods. Understanding the duration of tasks scheduled during idle callbacks is important to understand the user response time when interacting with the UI using input devices.
Browser do not provide any Web API to directly understand rendering related bottlenecks. Long rendering operations could be caused by a complex page layout or frequent repetitive layout calculations (known as layout thrashing). In addition, there are cases where the compositor render phase can take extensive time to complete (although running on a separate thread in modern browsers). Since no relevant Web API exist to observe these operations, engineers are left with relatively narrow options.
The use cases here directly derive from the described challenges.
When web application users complain about certain actions in the UI being “slow”, “stuck”, “not smooth” it is not trivial to troubleshoot and diagnose these cases, particularly when there is no local repro for the engineer investigating this. A common challenge is to understand what caused long frames in terms of specific code paths or rendering inefficiencies. The Frame Timing API could provide data about long frames that occurred during a certain time frame. With the addition of other context around user actions and application state, developers can use correlation and analysis to identify sources of problems.
When building web applications, it is a common practice to build KPIs based on Real User Monitoring data to measure and track the overall user experience. Developers can create KPIs to quantify user experience using metrics derived from long frame data. One of the main challenges besides detecting that a long frame occurred is to understand the root cause of those long frames.
When an engineer builds a feature or fixes a bug in a web app, they want to know if they introduced UX regressions by increasing JavaScript execution time or rendering overhead, such as layout thrashing. It is possible to measure long tasks (long JS execution time) using Long Tasks API but not the length of entire frames and the rendering time within those frames. This is a blind spot in the ability to detect performance regressions.
In modern browsers, part of the rendering pipeline is executed in parallel with JS execution, for example, threaded scrolling, or slow composited effects like blurs. It should be possible to use this API to identify when asynchronous animations are slow.
As outlined in this document, it is very challenging for engineers of complex web apps to track and detect long frames and identify their root causes. A new Web API is required to provide the ability to natively track long frames and provide a breakdown into phases for more effective root cause analysis. Such an API would give engineers the ability to develop and build more responsive and interactive web applications with smooth and rich animations which will benefit the web apps ecosystem.