mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-06 09:01:53 +00:00
LibJS: Optimize array destructuring assignment for builtin iterators
...by avoiding `{ value, done }` iterator result value allocation. This
change applies the same otimization 81b6a11
added for `for..in` and
`for..of`.
Makes following micro benchmark go 22% faster on my computer:
```js
function f() {
const arr = [];
for (let i = 0; i < 10_000_000; i++) {
arr.push([i]);
}
let sum = 0;
for (let [i] of arr) {
sum += i;
}
}
f();
```
This commit is contained in:
parent
295b78f7d3
commit
60bd5012fe
Notes:
github-actions[bot]
2025-05-01 13:58:54 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: 60bd5012fe
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4544
4 changed files with 11 additions and 15 deletions
|
@ -1504,8 +1504,8 @@ static Bytecode::CodeGenerationErrorOr<void> generate_array_binding_pattern_byte
|
|||
generator.switch_to_basic_block(iterator_is_not_exhausted_block);
|
||||
}
|
||||
|
||||
generator.emit<Bytecode::Op::IteratorNext>(temp_iterator_result, iterator);
|
||||
generator.emit_iterator_complete(is_iterator_exhausted, temp_iterator_result);
|
||||
auto value = generator.allocate_register();
|
||||
generator.emit<Bytecode::Op::IteratorNextUnpack>(value, is_iterator_exhausted, iterator);
|
||||
|
||||
// We still have to check for exhaustion here. If the iterator is exhausted,
|
||||
// we need to bail before trying to get the value
|
||||
|
@ -1517,10 +1517,6 @@ static Bytecode::CodeGenerationErrorOr<void> generate_array_binding_pattern_byte
|
|||
|
||||
generator.switch_to_basic_block(no_bail_block);
|
||||
|
||||
// Get the next value in the iterator
|
||||
auto value = generator.allocate_register();
|
||||
generator.emit_iterator_value(value, temp_iterator_result);
|
||||
|
||||
auto& create_binding_block = generator.make_block();
|
||||
generator.emit<Bytecode::Op::Jump>(Bytecode::Label { create_binding_block });
|
||||
|
||||
|
@ -3187,7 +3183,7 @@ static Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> for_in_of_body_e
|
|||
auto done = generator.allocate_register();
|
||||
|
||||
if (iterator_kind == IteratorHint::Sync) {
|
||||
generator.emit<Bytecode::Op::ForOfNext>(next_value, done, *head_result.iterator);
|
||||
generator.emit<Bytecode::Op::IteratorNextUnpack>(next_value, done, *head_result.iterator);
|
||||
|
||||
auto& loop_continue = generator.make_block();
|
||||
generator.emit_jump_if(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue