Skip to content

Commit 054fcc5

Browse files
authored
Clarify event loop integration and prioritization (WICG#92)
1 parent 0a23970 commit 054fcc5

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

spec/patches.md

+20
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,26 @@ Modify step 2.1 to read:
5555
[=implementation-defined=] manner.
5656
* |schedulerQueue|'s [=scheduler task queue/tasks=], if |schedulerQueue| is not null.
5757

58+
Note: the HTML specification enables per-[=task source=] prioritization by making the selection of
59+
the next [=task=]'s [=task queue=] in the event loop processing steps [=implementation-defined=].
60+
Similarly, this specification makes selecting between the next {{Scheduler}} task and the next task
61+
from an [=event loop=]'s [=task queues=] [=implementation-defined=], which provides UAs with the
62+
most scheduling flexibility.
63+
<br/><br/>
64+
But the intent of this specification is that the {{TaskPriority}} of {{Scheduler}} tasks would
65+
influence the event loop priority. Specifically, "{{TaskPriority/background}}" tasks and
66+
continuations are typically considered less important than most other event loop tasks, while
67+
"{{TaskPriority/user-blocking}}" tasks and continuations, as well as "{{TaskPriority/user-visible}}"
68+
continuations (but not tasks), are typically considered to be more important.
69+
<br/><br/>
70+
One strategy is to run {{Scheduler}} tasks with an [=scheduler task queue/effective priority=] of 3
71+
or higher with an elevated priority, e.g. lower than input, rendering, and other <em>urgent</em>
72+
work, but higher than most other [=task sources=]. {{Scheduler}} tasks with an [=scheduler task
73+
queue/effective priority=] of 0 or 1 could be run only when no other tasks in an [=event loop=]'s
74+
[=task queues=] are [=task/runnable=], and {{Scheduler}} tasks with an [=scheduler task
75+
queue/effective priority=] of 2 could be scheduled like other scheduling-related [=task sources=],
76+
e.g. the [=timer task source=].
77+
5878
Issue: The |taskQueue| in this step will either be a [=set=] of [=tasks=] or a [=set=] of
5979
[=scheduler tasks=]. The steps that follow only [=set/remove=] an [=set/item=], so they are
6080
*roughly* compatible. Ideally, there would be a common task queue interface that supports a `pop()`

spec/scheduling-tasks.md

+21-11
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,27 @@ This spec formalizes three priorities to support scheduling tasks:
1212
};
1313
</pre>
1414

15-
<dfn enum-value for=TaskPriority>user-blocking</dfn> is the highest priority, and is meant to be
16-
used for tasks that are blocking the user's ability to interact with the page, such as rendering the
17-
core experience or responding to user input.
18-
19-
<dfn enum-value for=TaskPriority>user-visible</dfn> is the second highest priority, and is meant to
20-
be used for tasks that are observable to the user but not necessarily blocking user actions, such as
21-
updating secondary parts of the page. This is the default priority.
22-
23-
<dfn enum-value for=TaskPriority>background</dfn> is the lowest priority, and is meant to be used
24-
for tasks that are not time-critical, such as background log processing or initializing certain
25-
third party libraries.
15+
<dfn enum-value for=TaskPriority>user-blocking</dfn> is the highest priority, and it is meant for
16+
tasks that should run as soon as possible, such that running them at a lower priority would degrade
17+
user experience. This could be (chunked) work that is directly in response to user input, or
18+
updating the in-viewport UI state, for example.
19+
<br/><br/>
20+
Note that tasks scheduled with this priority will typically have a higher event loop priority
21+
compared to other tasks, but they are not necessarily render-blocking. Work that needs to happen
22+
immediately without interruption should typically be done synchronously &mdash; but this can lead to
23+
poor responsiveness if the work takes too long. "{{TaskPriority/user-blocking}}" tasks, on the other
24+
hand, can be used to break up work and remain remain responsive to input and rendering, while
25+
increasing the liklihood that the work finishes as soon as possible.
26+
27+
<dfn enum-value for=TaskPriority>user-visible</dfn> is the second highest priority, and it is meant
28+
for tasks that will have useful side effects that are observable to the user, but either which are
29+
not immediately observable or which are not essential to user experience. Tasks with this prioriy
30+
are less important or less urgent than "{{TaskPriority/user-blocking}}" tasks. This is the default
31+
priority.
32+
33+
<dfn enum-value for=TaskPriority>background</dfn> is the lowest priority, and it is meant to be used
34+
for tasks that are not time-critical, such as background log or metrics processing or initializing
35+
certain third party libraries.
2636

2737
Continuation priorities mirror task priorities, with an additional option to inherit the current
2838
priority:

0 commit comments

Comments
 (0)