mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-30 11:37:16 +02:00
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:
committed by
Andreas Kling
parent
b34274a2a0
commit
3a2f2f3926
Notes:
github-actions[bot]
2026-03-16 17:02:59 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/3a2f2f39263 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8449 Reviewed-by: https://github.com/shannonbooth
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user