LibJS: Skip iterator result object allocation in for..of and for..in

Introduce special instruction for `for..of` and `for..in` loop that
skips `{ value, done }` result object allocation if iterator is builtin
(array, map, set, string). This reduces GC pressure significantly and
avoids extracting the `value` and `done` properties.

This change makes this micro benchmark 48% faster on my computer:
```js
const arr = new Array(10_000_000);
let counter = 0;
for (let _ of arr) {
    counter++;
}
```
This commit is contained in:
Aliaksandr Kalenik 2025-04-30 16:31:26 +03:00 committed by Andreas Kling
parent ab52d86a69
commit 81b6a1100e
Notes: github-actions[bot] 2025-04-30 18:52:38 +00:00
4 changed files with 94 additions and 23 deletions

View file

@ -51,6 +51,7 @@
O(EnterObjectEnvironment) \
O(EnterUnwindContext) \
O(Exp) \
O(ForOfNext) \
O(GetById) \
O(GetByIdWithThis) \
O(GetByValue) \