Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upEvent-loop should not block when microtask queue is not empty #26700
Labels
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Step 1 of the event-loop processing model reads(emphasis mine):
We have two places where this is implemented:
In both places, we actually run a different algorithm where we:
select!So the problem there is that while we block at 1. we won't perform the "If there is no such task queue, then jump to the microtasks step below." part of the processing model, instead we'll just block until a message comes in, even if we do have microtasks ready to execute.
I think we're not noticing this a lot because there are usually lots of messages coming in, but it might also be a hidden performance problem, since in cases were we could immediately skip to the microtask checkpoint, now we will instead wait until an unrelated messages wakes-up the event-loop.
The actual use case were this can happen is where a microtask queues other microtasks, while the microtask checkpoint is not re-entrant so those subsequent tasks will only execute at the next checkpoint.
So I think in both cases, we could add a "microtask-ready" channel to the select, and ensure it has a message when the microtask queue is not empty(send a message on it when the first microtask in an iteration of the event-loop is queued).