LibJS: Synchronous await fast path when microtask queue is empty

When an async function is resumed from a microtask and hits another
await with a non-thenable value (primitive or already-settled native
promise), and the microtask queue is empty, we can resolve the await
synchronously without suspending. No other microtask can observe the
difference in execution order, making this optimization safe.

This avoids the overhead of creating a GC::Function for the microtask
job, enqueuing/dequeuing from the microtask queue, and the execution
context push/pop that comes with it.

A new VM host hook, host_promise_job_queue_is_empty, is added so both
the standalone js binary and LibWeb can provide the appropriate check
for their respective job queue implementations.
This commit is contained in:
Andreas Kling
2026-03-16 04:43:45 +01:00
committed by Andreas Kling
parent 94d3aa8d89
commit 3e1145ef07
Notes: github-actions[bot] 2026-03-17 00:16:01 +00:00
6 changed files with 135 additions and 1 deletions

View File

@@ -37,6 +37,7 @@ private:
OwnPtr<ExecutionContext> m_suspended_execution_context;
GC::Ptr<NativeFunction> m_on_settled;
bool m_is_initial_execution { true };
};
}