Skip to content
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

Improve spec compliance of the event-loop #24759

Open
gterzian opened this issue Nov 17, 2019 · 1 comment
Open

Improve spec compliance of the event-loop #24759

gterzian opened this issue Nov 17, 2019 · 1 comment
Labels
A-content/script Related to the script thread B-meta This issue tracks the status of multiple, related pieces of work

Comments

@gterzian
Copy link
Member

Spec: https://html.spec.whatwg.org/multipage/#event-loop-processing-model

which is also called into by step 29 of https://html.spec.whatwg.org/multipage/#run-a-worker

We have two implementations of the event-loop:

  1. In ScriptThread, representing a "similar-origin-window-agent", running an window-event-loop at
    while self.handle_msgs() {
  2. In AbstractWorkerGlobalScope, representing a dedicated-worker-agent or a service-worker-agent running a worker-event-loop, at
    pub fn run_worker_event_loop<T, TimerMsg, WorkerMsg, Event>(
  3. We also have paint worklet-agents running a worklet event-loop

This issue will focus on 1 and 2.

Couple of issues can be noted in both:

  1. We run a microtask-checkpoint after handling any message/event, however we should only run those when mandated by the spec, such as:
  2. In the window event-loop, we have a bunch of custom logic where we first run resize events, and then prioritize some events coming from the constellation(see here), while the spec clearly says to start by running a task, if any is available, then running a microtask checkpoint, and then finally run the various optionsal steps in update the rendering, which includes for example run-the-resize-stepsat 10.6. So it appears that most of the resize and other constellation events we handle first, should be handled after the handling of a task, and in a specific order. This includes running the window animation frame callbacks(Step 10.11).
  3. We don't run any animation frame callbacks for dedicated workers(which I assume only makes sense once we have transferable offscreen-canvas?).
  4. I'm not sure if the generic worker event-loop was really such a good idea, because different workers might require different hooks(for example animation frames in dedicated workers), however it might also be that we can just add methods to WorkerEventLoopMethods to reflect this diversity.
@gterzian gterzian added A-content/dom Interacting with the DOM from web content B-meta This issue tracks the status of multiple, related pieces of work A-content/script Related to the script thread and removed A-content/dom Interacting with the DOM from web content labels Nov 17, 2019
@gterzian
Copy link
Member Author

gterzian commented Dec 2, 2019

Re microtask, we should also run them even if there is no task to run, so instead of blocking on the select, which potentially blocks until a task is enqueued, we should do something were we immediatelly do a microtask checkpoint if not task is runnable, and then only block if there is no microtask and no task to run.

For example, if a promise resolves, and then queues another promise via a microtask, we would want it to run, even if there is no runnable task in the queue and we don't receive any other message. Currently we would block and only run the microtask when a message comes in.

See step 1: "If there is no such task queue, then jump to the microtasks step below."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-content/script Related to the script thread B-meta This issue tracks the status of multiple, related pieces of work
Projects
None yet
Development

No branches or pull requests

1 participant