mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-01 12:07:14 +02:00
LibJS: Skip iteration result allocation in AsyncFunctionDriverWrapper
- Create less GC pressure by making each `await` in async function skip
iteration result object allocation.
- Skip uncached `Object::get()` calls to extract `value` and `done` from
the iteration result object.
With this change, following function goes 30% faster on my computer:
```js
(async () => {
const resolved = Promise.resolve();
for (let i = 0; i < 5_000_000; i++) {
await resolved;
}
})();
```
This commit is contained in:
committed by
Andreas Kling
parent
286a9d8101
commit
4c789ac689
Notes:
github-actions[bot]
2025-05-09 10:31:18 +00:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/LadybirdBrowser/ladybird/commit/4c789ac6892 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4663
@@ -131,11 +131,8 @@ void AsyncFunctionDriverWrapper::continue_async_execution(VM& vm, Value value, b
|
||||
return generator_result.throw_completion();
|
||||
|
||||
auto result = generator_result.release_value();
|
||||
VERIFY(result.is_object());
|
||||
|
||||
auto promise_value = TRY(result.get(vm, vm.names.value));
|
||||
|
||||
if (TRY(result.get(vm, vm.names.done)).to_boolean()) {
|
||||
auto promise_value = result.value;
|
||||
if (result.done) {
|
||||
// When returning a promise, we need to unwrap it.
|
||||
if (promise_value.is_object() && is<Promise>(promise_value.as_object())) {
|
||||
auto& returned_promise = static_cast<Promise&>(promise_value.as_object());
|
||||
|
||||
Reference in New Issue
Block a user