-
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
Consider reusing AsyncContext specification infrastructure for "current scheduling state" #94
Comments
Would there be a way to limit the propagation of an |
Do you have any information about the motivation for not propagating across the entire task graph (e.g., why not also to setTimeout and event handlers)? Also, I'm curious what the priority is set as, for things which do not inherit this way. For AsyncContext, we'll probably have one main location in WebIDL where we propagate the AsyncContext.Snapshot to most (all?) callbacks. We could, if needed, add logic in here to set the scheduling state to a particular thing at that point, when calling the callback, if they are all supposed to be considered as a "fresh" task with a different priority. |
Sure. Our goal was for the scheduling state to be propagated through the body of an async function, such that breaking it up with const task = async () => {
while (hasWork()) {
doSomeWork();
// The continuation inherits the task's priority.
await scheduler.yield();
}
};
const controller = new TaskController({priority: "background"});
scheduler.postTask(task, {signal: controller.signal}); Conceptually, when breaking up a long synchronous task with
and turning it into
and propagating the state to all the pieces. Things of course get more complicated if you mix in other promise-based async APIs, which is discussed a bit here. In my mental model, if For example, suppose a const task = () => {
doSomeWork();
// This might schedule yieldy tasks via setTimeout(). Is that a continuation of this?
informThirdPartyLibrary();
// This might trigger framework updates and eventually lead to custom hooks.
// Are all of those related?
triggerFrameWorkUpdate();
}; A risk with inheriting broadly across the task graph is "runaway prioritization": elevated priority can be effective, but prioritizing everything in the task graph can lead to over-priortization. Reducing the scope such that On the other hand, there might be cases where propagating an
The scheduling state is only set (and propagated) for |
I wonder if this concern about how "scheduler-like" APIs should reset priority implies to other things which may be tracked by AsyncContext variables, in case they're run out of an unsuspecting third-party library. I suppose they definitely want task attribution propagation, but (for example) if we implicitly propagated an AbortSignal for cancellation, we would probably want that to not propagate, if the third-party scheduled tasks are somehow logically detached (which I assume is the motivation for not propagating the priority). Are your thoughts on this topic influenced by any particular JS code that you've examined? It'd be helpful to open that back up to understand the implications on AsyncContext more broadly. |
I had a thought: If the AsyncContext model of propagation would retain the scheduling options more than desired via certain scheduling mechanisms, could we just explicitly reset these in those places? E.g., If I were implementing a userland scheduler, that might be how I would do it. Conceptually, I think it could be a way to merge the two concepts (AsyncContext specifies all the ways in which context is propagated, and task scheduling chooses to constrain down / drop the context sometimes). In practice I'm not sure if that is how it would be implemented most efficiently. |
I've now opened tc39/proposal-async-context#100, with a document outlining the web integration of AsyncContext in detail.
Yes, that would be possible, but the handling of callbacks in WebIDL would need to take the |
The Stage 2 JavaScript AsyncContext proposal adds state which is saved and restored across
await
, like the current scheduling state. Can we model the current scheduling state as anAsyncContext.Variable
instance which is not exposed to JavaScript, just held internally by HTML? If so, then it would allow implementations to share the same code paths, reducing overall complexity.Note that there is a currently open design discussion about how AsyncContext is saved and restored across various web APIs (issue, html issue). I'm curious whether the propagation of the current scheduling state should be propagated in the same way.
The text was updated successfully, but these errors were encountered: