Main thread Scheduling APIs: Prioritized scheduler.postTask

Userspace tasks often have varying degrees of importance (related to user experience), but the Platform lacks a unified API to schedule prioritized work. The postTask API allows developers to schedule tasks (javascript callbacks) with a native browser scheduler at 3 levels of priority: user-blocking, user-visible, and background. It also exposes a TaskController, which can be used to dynamically cancel tasks and change their priority.

It is too difficult to build web apps that are responsive to user interaction, and that remain responsive over time. Script is a primary culprit that hurts responsiveness (https://tdresser.github.io/input-latency-deep-reports/). Consider a "search-as-you-type" application: this app needs to be responsive to user input i.e. user typing in the search-box. At the same time any animations on the page must be rendered smoothly, as well as the work for fetching, preparing and displaying search results must progress quickly. This problem can be tackled by systematically chunking and scheduling main thread work, i.e. prioritizing and executing work async at an appropriate time relative to current situation of user and browser. Userspace schedulers exist for this purpose, and use priority to order execution of their tasks. But this priority has limited meaning since they do not control all tasks on the page. Apps can consist of 1P, 1P library, 3P, and (one or more) framework scripts, all of which compete for the main thread. At the same time, the browser has tasks to run on the main thread, such as async work (e.g. fetch() and IDB tasks) and garbage collection. The problem is that most of these tasks run at the same priority, as the Platform only exposes a few priorities, either explicitly or implicitly through a disparate set of APIs. And without sufficient priorities, the browser is limited in how it can schedule tasks.

Comments

Previous umbrella I2I: https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/eLq8t56CbaQ/Ik7vP__GBgAJ

Documentation

Status in Chromium

Blink>Scheduling


Origin trial (tracking bug) in:

  • Chrome for desktop release 83
  • Chrome for Android release 83
  • Android WebView release 83

Consensus & Standardization

After a feature ships in Chrome, the values listed here are not guaranteed to be up to date.

  • No signal
  • No signal
  • No signal
  • Strongly positive

Owners

Last updated on 2020-09-11