mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-26 19:29:16 +00:00
LibJS: Use a premade shape when creating iterator result objects
Instead of going through the steps of creating an empty new object,
and adding two properties ("value" and "done") to it, we can pre-bake
a shape object and cache the property offsets.
This makes creating iterator result objects in the runtime much faster.
47% speedup 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:
@@ -37,6 +37,11 @@ NonnullGCPtr<Object> Object::create(Realm& realm, Object* prototype)
|
||||
return realm.heap().allocate<Object>(realm, ConstructWithPrototypeTag::Tag, *prototype);
|
||||
}
|
||||
|
||||
NonnullGCPtr<Object> Object::create_with_premade_shape(Shape& shape)
|
||||
{
|
||||
return shape.heap().allocate<Object>(shape.realm(), shape);
|
||||
}
|
||||
|
||||
Object::Object(GlobalObjectTag, Realm& realm, MayInterfereWithIndexedPropertyAccess may_interfere_with_indexed_property_access)
|
||||
: m_may_interfere_with_indexed_property_access(may_interfere_with_indexed_property_access == MayInterfereWithIndexedPropertyAccess::Yes)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user