-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make prioritization stricter #71
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,28 +28,58 @@ a specific [=task queue=]. | |
With: For each [=event loop=], every [=task source=] that is not a | ||
[=scheduler task source=] must be associated with a specific [=task queue=]. | ||
|
||
An [=event loop=] object has a numeric <dfn for="event loop">next enqueue order</dfn>, which is | ||
is initialized to 1. | ||
|
||
Note: The [=event loop/next enqueue order=] is a strictly increasing number that is used to | ||
determine task execution order across [=scheduler task queues=] of the same {{TaskPriority}} across | ||
all {{Scheduler}}s associated with the same [=event loop=]. A timestamp would also suffice as long | ||
as it is guaranteed to be strictly increasing and unique. | ||
|
||
### <a href="https://html.spec.whatwg.org/multipage/webappapis.html#event-loop-processing-model">Event loop: processing model</a> ### {#sec-patches-html-event-loop-processing} | ||
|
||
Add the following steps to the event loop processing steps, before step 1: | ||
|
||
1. Let |queues| be the [=set=] of the [=event loop=]'s [=task queues=] that | ||
contain at least one <a for="task">runnable</a> <a for="/">task</a>. | ||
1. Let |schedulers| be the [=set=] of all {{Scheduler}} objects whose | ||
[=relevant agent's=] [=agent/event loop=] is this event loop and that | ||
[=have a runnable task=]. | ||
1. If |schedulers| and |queues| are both [=list/empty=], skip to the | ||
<code>microtasks</code> step below. | ||
|
||
Modify step 1 to read: | ||
|
||
1. Let |taskQueue| be one of the following, chosen in an | ||
[=implementation-defined=] manner: | ||
* If |queues| is not [=list/empty=], one of the [=task queues=] in |queues|, | ||
chosen in an [=implementation-defined=] manner. | ||
* If |schedulers| is not [=list/empty=], the result of | ||
[=selecting the task queue of the next scheduler task=] from one of the | ||
{{Scheduler}}s in |schedulers|, chosen in an [=implementation-defined=] | ||
manner. | ||
Replace: | ||
1. If the [=event loop=] has a [=task queue=] with at least one <a for="task">runnable</a> | ||
<a for="/">task</a>, then: | ||
1. Let |taskQueue| be one such [=task queue=], chosen in an [=implementation-defined=] manner. | ||
|
||
With: | ||
1. Let |queues| be the [=set=] of the [=event loop=]'s [=task queues=] that contain at least one | ||
<a for="task">runnable</a> <a for="/">task</a>. | ||
1. Let |scheduler queue| be the result of [=selecting the next scheduler queue from all schedulers=] | ||
given the [=event loop=]. | ||
1. If |scheduler queue| is not null and |queues| is not [=list/empty=], then: | ||
1. If |scheduler queue|'s [=scheduler task queue/priority=] is {{TaskPriority/user-blocking}}, | ||
then [=set/remove=] from |queues| any [=task queue=] whose [=task source=] is in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Task queues don't have associated task sources. Instead, "every task source must be associated with a specific task queue". So e.g. a given task queue could have some timer task source-tasks, some networking tasks, etc. I think what you want to check here is the task source of the next runnable task in the task queue. That's kind of weird, but I'm not sure there's a better option... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ACK, ugh I knew that :(. I'm OOO next week, I'll work on cleaning it up after. Thanks for the review - much appreciated! |
||
«[=timer task source=], [=posted message task source=]». | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will delay behind all posted messages, not just same-Window ones. The below note doesn't seem to align with that. If you wanted to restrict to same-window ones, you'd need to mark the queued tasks in some way, presumably at the time they're enqueued. I might try something like moneypatching https://html.spec.whatwg.org/multipage/web-messaging.html#posted-message-task-source to contain "If ..., the [task] queued in such a way is a same-window posted message task", and then checking that here. |
||
1. Otherwise if |scheduler queue|'s [=scheduler task queue/priority=] is | ||
{{TaskPriority/background}}, then set |scheduler queue| to null. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add a note here: something like
|
||
1. If |scheduler queue| is not null or |queues| is not [=list/empty=], then: | ||
1. Let |taskQueue| be one of the following, chosen in an [=implementation-defined=] manner: | ||
* One of the [=task queues=] in |queues|, if |queues| is not [=list/empty=]. | ||
* |scheduler queue|'s [=scheduler task queue/tasks=], if |scheduler queue| is not null. | ||
|
||
|
||
Note: This section defines the integration of {{Scheduler}} tasks and the [=event loop=]. | ||
<br/><br/> | ||
The intention of {{TaskPriority/user-blocking}} priority is to enable developers to schedule high | ||
priority work that still stays responsive to input and rendering, e.g. critical work spawned by an | ||
input response that shouldn't block the next frame or key press. {{TaskPriority/user-blocking}} | ||
tasks are specified to have higher event loop priority than other scheduling methods, specifically | ||
{{WindowOrWorkerGlobalScope/setTimeout()|setTimeout(0)}} and same-window | ||
{{Window/postMessage(message, options)|postMessage()}}. UAs have flexibility to prioritize between | ||
{{TaskPriority/user-blocking}} tasks other task sources, but are encouraged to give some increased | ||
priority to the former. One possible strategy is to give {{TaskPriority/user-blocking}} | ||
tasks priority over everything except user input and rendering (to ensure the UI remains | ||
responsive), as well as user-driven tasks like navigation. | ||
<br/><br/> | ||
{{TaskPriority/user-visible}} tasks are meant to be scheduled in a similar way to existing | ||
scheduling mechanisms like {{WindowOrWorkerGlobalScope/setTimeout()|setTimeout(0)}} and | ||
and same-window {{Window/postMessage(message, options)|postMessage()}}, but the relative priority | ||
of these is unspecified (as is the case for all event loop task queues). | ||
<br/><br/> | ||
{{TaskPriority/background}} tasks can only run if no other tasks are <a for="task">runnable</a>. | ||
This is similar to idle tasks, but they can run outside of idle periods. | ||
|
||
Issue: The |taskQueue| in this step will either be a [=set=] of [=tasks=] or a | ||
[=set=] of [=scheduler tasks=]. The steps that follow only [=set/remove=] an | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quotes around strings like
user-blocking
, here and elsewhere.