• Stars
    star
    896
  • Rank 49,138 (Top 1.0 %)
  • Language
    HTML
  • License
    Other
  • Created over 5 years ago
  • Updated 16 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

APIs for scheduling and controlling prioritized tasks.

Scheduling APIs

This document outlines the motivation for working on various scheduling APIs1, discusses some of the problems that apps and userspace schedulers face when writing scheduling code, and links to various proposals we are working on in this space.

(1The scope of this work was previously restricted to main-thread scheduling, and while main-thread scheduling remains the primary focus, the repository and some accompanying text has been renamed to "scheduling-apis" to reflect the inclusion of APIs like scheduler.postTask() on workers.)

Motivation: Main-thread Contention

Applications may experience main-thread contention at various points in their execution, e.g. during page load or as a result of user interaction. This contention can negatively affect user experience in terms of responsiveness and latency. For example, a busy main thread can prevent the UA from servicing input, leading to poor responsiveness. Similarly, tasks (e.g. fetch completions, rendering, etc.) can experience large queuing durations during times of contention, which increases task latency and can result in degraded quality of experience.

Consider a "search-as-you-type" application. This app needs to be responsive to user input, i.e. users typing in the search-box. At the same time, any animations on the page must be rendered smoothly, and the work for fetching and preparing search results and updating the page must also progress quickly. There are a lot of different deadlines to meet for the app developer. It is easy for any long running script work to hold up the main thread and cause responsiveness issues for typing, rendering animations, or updating search results.

Another example pinch-zooming in a map application. The app needs to continuously respond to the input, update the rendering, and potentially fetch new content to be displayed. Similar to the search-as-you-type example, long running script work could block other tasks, making the application feel laggy.

Current Solutions, Their Limitations, and APIs to Fill the Gaps

Dealing with contention is largely a scheduling problem: to the degree that work can be reordered in an more optimal way, scheduling can have a positive impact. What makes this problem more pronounced on the web is that tasks run to completion—the UA cannot preempt a task to run high priority work like processing user input. This problem is generally tackled in userspace by systematically chunking and scheduling main-thread work. Since long tasks and responsiveness are at odds, breaking up long tasks can help keep an app responsive when also yielding to the browser's event loop.

Userspace schedulers have evolved to manage these chunks of work—prioritizing and executing work async at an appropriate time relative to current situation of user and browser. And while userspace schedulers have been effective in improving responsiveness, there are several problems they still face:

  1. Coordination between (cooperating) actors: Most userspace schedulers have a notion of priority that allows tasks to be ordered in a way that improves user experience. But this is limited since userspace schedulers do not control all tasks on the page.

    Apps can consist of 1P, 1P library, 3P, and (one or more) framework script each of which competes for the main thread. At the same time, the browser also has tasks to run on the main thread, such as fetch() and IDB tasks and garbage collection.

    Having a shared notion of priority can help the browser make better scheduling decisions, which in turn can help improve user experience. We propose adding a prioritized task scheduling API to address this problem.

  2. A disparate set of scheduling APIs: Despite the need to schedule chunks of script, the Platform lacks a unified API to do so. Developers can choose setTimeout, postMessage, requestAnimationFrame, or requestIdleCallback, when choosing to schedule tasks.

    This disparate set of scheduling APIs makes it even more difficult for developers to write scheduling code and requires expert knowledge of the browser's event loop to do so. Creating a unified native scheduling API —scheduler.postTask() —will alleviate this.

  3. Determining when to yield to the browser: yielding has overhead—the overhead of posting a task and context switching, the cost of regaining control, etc. This can lead to increased task latency.

    Making intelligent decisions about when to yield is difficult with limited knowledge. Scheduling primitives can help userspace schedulers make better decisions, e.g. isInputPending() and isFramePending().

  4. Regaining control after yielding: chunking work and yielding is necessary for improving responsiveness, but it comes at a cost: when yielding to the event loop, a task that yields has no way to continue without arbitrary work of the same priority running first, e.g. other script. This disincentivizes yielding from a script that requires low task latency. Providing a primitive like scheduler.yield() that is designed to take into account this async userspace task model can help, as the scheduler can prioritize these continuations more fairly.

Additional Scheduling Problems

The problem as described above only covers part of the scheduling problem space. Additionally, there are developer needs for things like detecting when a frame is pending, throttling the frame rate, and avoiding layout thrashing. Some of the other APIs we are considering in this space are noted here.

APIs and Status

API Abstract Status Links
scheduler.postTask() An API for scheduling and controlling prioritizing tasks. This feature shipped in Chromium M94 Explainer
Spec
Polyfill
scheduler.yield() An API for breaking up long tasks by yielding to the browser, continuing after being rescheduled by the scheduler. This feature is available behind a flag in Chromium M113. Explainer
scheduler.wait() This enables tasks to yield and resume after some amount of time, or perhaps after an event has occurred. This feature is currently being co-designed with scheduler.yield(). Related Discussion
scheduler.currentTaskSignal This API provides a way to get the currently running task's TaskSignal, which can be used to schedule dependent tasks. This API is currently being re-evaluating in the context of scheduler.yield(). Explainer
Prioritized Fetch Scheduling Using a TaskSignal or postTask priorities for resource fetching would enable developers to prioritize critical resources, or deprioritize less critical ones. This feature is actively being designed. Early Proposal
isInputPending() An API for determining if the current task is blocking input events. This API shipped in Chrome M87. Explainer
Spec
web.dev

Further Reading / Viewing

More Repositories

1

webcomponents

Web Components specifications
HTML
4,306
star
2

import-maps

How to control the behavior of JavaScript imports
JavaScript
2,636
star
3

virtual-scroller

1,997
star
4

focus-visible

Polyfill for `:focus-visible`
JavaScript
1,606
star
5

webusb

Connecting hardware to the web.
Bikeshed
1,287
star
6

webpackage

Web packaging format
Go
1,216
star
7

EventListenerOptions

An extension to the DOM event pattern to allow authors to disable support for preventDefault
JavaScript
1,166
star
8

portals

A proposal for enabling seamless navigations between sites or pages
HTML
945
star
9

floc

This proposal has been replaced by the Topics API.
Makefile
933
star
10

inert

Polyfill for the inert attribute and property.
JavaScript
914
star
11

view-transitions

789
star
12

file-system-access

Expose the file system on the user’s device, so Web apps can interoperate with the user’s native applications.
Bikeshed
641
star
13

background-sync

A design and spec for ServiceWorker-based background synchronization
HTML
638
star
14

scroll-to-text-fragment

Proposal to allow specifying a text snippet in a URL fragment
HTML
577
star
15

ua-client-hints

Wouldn't it be nice if `User-Agent` was a (set of) client hints?
Bikeshed
575
star
16

aom

Accessibility Object Model
HTML
553
star
17

kv-storage

[On hold] A proposal for an async key/value storage API for the web
550
star
18

observable

Observable API proposal
Bikeshed
515
star
19

turtledove

TURTLEDOVE
Bikeshed
505
star
20

navigation-api

The new navigation API provides a new interface for navigations and session history, with a focus on single-page application navigations.
Makefile
474
star
21

webmonetization

Proposed Web Monetization standard
HTML
439
star
22

trust-token-api

Trust Token API
Bikeshed
412
star
23

attribution-reporting-api

Attribution Reporting API
Bikeshed
338
star
24

direct-sockets

Direct Sockets API for the web platform
HTML
304
star
25

shape-detection-api

Detection of shapes (faces, QR codes) in images
Bikeshed
299
star
26

display-locking

A repository for the Display Locking spec
HTML
294
star
27

background-fetch

API proposal for background downloading/uploading
Shell
279
star
28

resize-observer

This repository is no longer active. ResizeObserver has moved out of WICG into
HTML
256
star
29

first-party-sets

Bikeshed
255
star
30

serial

Serial ports API for the platform.
HTML
254
star
31

priority-hints

A browser API to enable developers signal the priorities of the resources they need to download.
Bikeshed
228
star
32

dbsc

HTML
227
star
33

is-input-pending

HTML
222
star
34

sanitizer-api

Bikeshed
213
star
35

proposals

A home for well-formed proposed incubations for the web platform. All proposals welcome.
209
star
36

spatial-navigation

Directional focus navigation with arrow keys
JavaScript
199
star
37

js-self-profiling

Proposal for a programmable JS profiling API for collecting JS profiles from real end-user environments
HTML
196
star
38

cq-usecases

Use cases and requirements for standardizing element queries.
HTML
185
star
39

interventions

A place for browsers and web developers to collaborate on user agent interventions.
178
star
40

visual-viewport

A proposal to add explicit APIs to the Web for querying and setting the visual viewport
HTML
174
star
41

frame-timing

Frame Timing API
HTML
170
star
42

layout-instability

A proposal for a Layout Instability specification
Makefile
157
star
43

page-lifecycle

Lifecycle API to support system initiated discarding and freezing
HTML
153
star
44

isolated-web-apps

Repository for explainers and other documents related to the Isolated Web Apps proposal.
Bikeshed
146
star
45

speech-api

Web Speech API
Bikeshed
144
star
46

cookie-store

Asynchronous access to cookies from JavaScript
Bikeshed
141
star
47

nav-speculation

Proposal to enable privacy-enhanced preloading
HTML
141
star
48

construct-stylesheets

API for constructing CSS stylesheet objects
Bikeshed
137
star
49

webhid

Web API for accessing Human Interface Devices (HID)
HTML
135
star
50

color-api

A proposal and draft spec for a Color object for the Web Platform, loosely influenced by the Color.js work. Heavily WIP, if you landed here randomly, please move along.
HTML
124
star
51

devtools-protocol

DevTools Protocol
JavaScript
120
star
52

fenced-frame

Proposal for a strong boundary between a page and its embedded content
Bikeshed
118
star
53

sms-one-time-codes

A way to format SMS messages for use with browser autofill features such as HTML’s autocomplete=one-time-code.
Makefile
109
star
54

bundle-preloading

Bundles of multiple resources, to improve loading JS and the Web.
HTML
103
star
55

netinfo

HTML
95
star
56

intrinsicsize-attribute

Proposal to add an intrinsicsize attribute to media elements
94
star
57

window-controls-overlay

HTML
94
star
58

container-queries

HTML
92
star
59

animation-worklet

🚫 Old repository for AnimationWorklet specification ➡️ New repository: https://github.com/w3c/css-houdini-drafts
Makefile
92
star
60

manifest-incubations

Before install prompt API for installing web applications
HTML
90
star
61

async-append

A way to create DOM and add it to the document without blocking the main thread.
HTML
87
star
62

privacy-preserving-ads

Privacy-Preserving Ads
86
star
63

indexed-db-observers

Prototyping and discussion around indexeddb observers.
WebIDL
83
star
64

shared-storage

Explainer for proposed web platform Shared Storage API
Bikeshed
82
star
65

compression

Standard text for CompressionStream and DecompressionStream API
HTML
81
star
66

file-handling

API for web applications to handle files
81
star
67

compression-dictionary-transport

80
star
68

canvas-color-space

Proposed web platform feature to add color management, wide gamut and high bit-depth support to the <canvas> element.
78
star
69

canvas-formatted-text

HTML
77
star
70

local-font-access

Web API for enumerating fonts on the local system
Bikeshed
75
star
71

performance-measure-memory

performance.measureMemory API
HTML
73
star
72

starter-kit

A simple starter kit for incubations
JavaScript
72
star
73

handwriting-recognition

Handwriting Recognition Web API Proposal
Makefile
72
star
74

css-parser-api

This is the repo where the CSS Houdini parser API will be worked on
HTML
72
star
75

ContentPerformancePolicy

A set of policies that a site guarantees to adhere to, browsers enforce, and embedders can count on.
HTML
72
star
76

web-app-launch

Web App Launch Handler
HTML
72
star
77

pwa-url-handler

71
star
78

eyedropper-api

HTML
70
star
79

idle-detection

A proposal for an idle detection and notification API for the web
Bikeshed
67
star
80

close-watcher

A web API proposal for watching for close requests (e.g. Esc, Android back button, ...)
Makefile
67
star
81

storage-foundation-api-explainer

Explainer showcasing a new web storage API, NativeIO
65
star
82

video-editing

64
star
83

uuid

UUID V4
63
star
84

client-hints-infrastructure

Specification for the Client Hints infrastructure - privacy preserving proactive content negotiation
Bikeshed
61
star
85

sparrow

59
star
86

element-timing

A proposal for an Element Timing specification.
Bikeshed
59
star
87

local-peer-to-peer

↔️ Proposal for local communication between browsers without the aid of a server.
Bikeshed
53
star
88

digital-credentials

Digital Credentials, like driver's licenses
HTML
53
star
89

video-rvfc

video.requestVideoFrameCallback() incubation
HTML
53
star
90

time-to-interactive

Repository for hosting TTI specification and discussions around it.
52
star
91

digital-goods

Makefile
49
star
92

private-network-access

HTML
49
star
93

raw-clipboard-access

An explainer for the Raw Clipboard Access feature
45
star
94

document-picture-in-picture

Bikeshed
45
star
95

admin

👋 Ask your questions here! 👋
HTML
42
star
96

soft-navigations

Heuristics to detect Single Page Apps soft navigations
Bikeshed
42
star
97

pending-beacon

A better beaconing API
Bikeshed
40
star
98

webcrypto-secure-curves

Proposal for the addition of Curve25519 and Curve448 to the Web Cryptography API
HTML
40
star
99

entries-api

Spec defining browser support for file/directory upload by drag-and-drop
Bikeshed
40
star
100

transfer-size

38
star