mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-03 04:52:06 +02:00
LibJS: Avoid IteratorRecord GC-allocation in GetIterator instruction
With this change, `GetIterator` no longer GC-allocates an
`IteratorRecord`. Instead, it stores the iterator record fields in
bytecode registers. This avoids per-iteration allocations in patterns
like: `for (let [x] of array) {}`.
`IteratorRecord` now inherits from `IteratorRecordImpl`, which holds the
iteration state. This allows the existing iteration helpers
(`iterator_next()`, `iterator_step()`, etc.) operate on both the
GC-allocated and the register-backed forms.
Microbenchmarks:
1.1x array-destructuring-assignment-rest.js
1.226x array-destructuring-assignment.js
This commit is contained in:
committed by
Alexander Kalenik
parent
a4e3890c05
commit
646457099c
Notes:
github-actions[bot]
2025-11-02 19:06:58 +00:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/LadybirdBrowser/ladybird/commit/646457099c4 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6639
@@ -341,7 +341,8 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from_async)
|
||||
else if (using_sync_iterator) {
|
||||
// i. Set iteratorRecord to ? CreateAsyncFromSyncIterator(GetIterator(asyncItems, sync, usingSyncIterator)).
|
||||
// FIXME: The Array.from proposal is out of date - it should be using GetIteratorFromMethod.
|
||||
iterator_record = create_async_from_sync_iterator(vm, TRY(get_iterator_from_method(vm, async_items, *using_sync_iterator)));
|
||||
auto iterator_record_impl = create_async_from_sync_iterator(vm, TRY(get_iterator_from_method(vm, async_items, *using_sync_iterator)));
|
||||
iterator_record = vm.heap().allocate<IteratorRecord>(iterator_record_impl.iterator, iterator_record_impl.next_method, iterator_record_impl.done);
|
||||
}
|
||||
|
||||
// h. If iteratorRecord is not undefined, then
|
||||
|
||||
Reference in New Issue
Block a user