mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 16:45:03 +00:00
LibJS: Remove dedicated iterator result instructions in favor of GetById
When iterating over an iterable, we get back a JS object with the fields
"value" and "done".
Before this change, we've had two dedicated instructions for retrieving
the two fields: IteratorResultValue and IteratorResultDone. These had no
fast path whatsoever and just did a generic [[Get]] access to fetch the
corresponding property values.
By replacing the instructions with GetById("value") and GetById("done"),
they instantly get caching and JIT fast paths for free, making iterating
over iterables much faster. :^)
26% speed-up on this microbenchmark:
function go(a) {
for (const p of a) {
}
}
const a = [];
a.length = 1_000_000;
go(a);
This commit is contained in:
@@ -584,4 +584,14 @@ void Generator::emit_get_by_id_with_this(IdentifierTableIndex id, Register this_
|
||||
emit<Op::GetByIdWithThis>(id, this_reg, m_next_property_lookup_cache++);
|
||||
}
|
||||
|
||||
void Generator::emit_iterator_value()
|
||||
{
|
||||
emit_get_by_id(intern_identifier("value"sv));
|
||||
}
|
||||
|
||||
void Generator::emit_iterator_complete()
|
||||
{
|
||||
emit_get_by_id(intern_identifier("done"sv));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user