LibJS: Add fast path in async function await for non-thenable values

Per spec, every `await` goes through PromiseResolve (which wraps the
value in a new Promise via NewPromiseCapability) and then
PerformPromiseThen (which creates PromiseReaction and JobCallback
objects). This results in 13-16 GC cell allocations per await.

Add a fast path that detects two common cases:

1. Primitive values: These can never have a "then" property, so we
   can skip all promise wrapping and directly schedule the async
   function's continuation as a microtask.

2. Already-settled native Promises: If the promise has no own
   properties and its prototype is the intrinsic %Promise.prototype%,
   we can extract the result directly and schedule continuation.

For these cases, we bypass promise_resolve(), new_promise_capability(),
create_resolving_functions(), perform_then(), PromiseReaction creation,
and JobCallback creation -- replacing ~13 GC allocations with 1
(the GC::Function for the microtask job).
This commit is contained in:
Andreas Kling
2026-03-15 11:21:35 -05:00
committed by Andreas Kling
parent b34274a2a0
commit 3a2f2f3926
Notes: github-actions[bot] 2026-03-16 17:02:59 +00:00
3 changed files with 419 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ public:
void visit_edges(Cell::Visitor&) override;
void continue_async_execution(VM&, Value, bool is_successful);
void schedule_resume(Value, bool is_fulfilled);
private:
AsyncFunctionDriverWrapper(Realm&, GC::Ref<GeneratorObject>, GC::Ref<Promise> top_level_promise);