Long Tasks API - Web APIs 编辑

Motivation

The experimental Long Tasks API gives us visibility into tasks that take 50 milliseconds or more. The 50 ms threshold comes from the RAIL Model, in particular the "Response: process events in under 50 ms" section.

Tasks that block the main thread for 50 ms or more cause, among other issues:

  • Delayed "Time to interactive".
  • High/variable input latency.
  • High/variable event handling latency.
  • Janky animations and scrolling.

Concepts

Some key terms or ideas that are utilized by the Long Tasks API.

Long task

Any uninterrupted period where the main UI thread is busy for 50 ms or longer. Common examples include:

  • Long running event handlers.
  • Expensive reflows and other re-renders.
  • Work the browser does between different turns of the event loop that exceeds 50 ms.

Culprit browsing context container

The "culprit browsing context container", or "the container" for short, is the top level page, iframe, embed or object that the task occurred within.

Attributions

A list of containers that the task occurred within. For tasks that don't occur within the top level page, the containerId, containerName and containerSrc fields may provide information as to the source of the task.

Usage

var observer = new PerformanceObserver(function(list) {
    var perfEntries = list.getEntries();
    for (var i = 0; i < perfEntries.length; i++) {
        // Process long task notifications:
        // report back for analytics and monitoring
        // ...
    }
});
// register observer for long task notifications
observer.observe({entryTypes: ["longtask"]});
// Long script execution after this will result in queueing
// and receiving "longtask" entries in the observer.

Interfaces

PerformanceLongTaskTiming
Reports instances of long tasks.
TaskAttributionTiming
Returns information about the work involved in a long task and its associate frame context.

Specifications

SpecificationStatusComment
Long Tasks API 1Working DraftInitial definition.

Browser compatibility

PerformanceLongTaskTiming

BCD tables only load in the browser

TaskAttributionTiming

BCD tables only load in the browser

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:110 次

字数:4859

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文