1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 16:18:12 +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:
Andreas Kling 2023-12-07 22:30:53 +01:00
parent 706710fa13
commit f47a14b9d6
5 changed files with 28 additions and 3 deletions

View file

@ -58,6 +58,7 @@ class Object : public Cell {
public:
static NonnullGCPtr<Object> create(Realm&, Object* prototype);
static NonnullGCPtr<Object> create_with_premade_shape(Shape&);
virtual void initialize(Realm&) override;
virtual ~Object();