mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-09 08:33:28 +02:00
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).
9.3 KiB
9.3 KiB