mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:37:35 +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:
parent
706710fa13
commit
f47a14b9d6
5 changed files with 28 additions and 3 deletions
|
@ -23,6 +23,10 @@ public:
|
|||
NonnullGCPtr<Shape> new_object_shape() { return *m_new_object_shape; }
|
||||
NonnullGCPtr<Shape> new_ordinary_function_prototype_object_shape() { return *m_new_ordinary_function_prototype_object_shape; }
|
||||
|
||||
[[nodiscard]] NonnullGCPtr<Shape> iterator_result_object_shape() { return *m_iterator_result_object_shape; }
|
||||
[[nodiscard]] u32 iterator_result_object_value_offset() { return m_iterator_result_object_value_offset; }
|
||||
[[nodiscard]] u32 iterator_result_object_done_offset() { return m_iterator_result_object_done_offset; }
|
||||
|
||||
// Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
|
||||
NonnullGCPtr<ProxyConstructor> proxy_constructor() { return *m_proxy_constructor; }
|
||||
|
||||
|
@ -123,6 +127,10 @@ private:
|
|||
GCPtr<Shape> m_new_object_shape;
|
||||
GCPtr<Shape> m_new_ordinary_function_prototype_object_shape;
|
||||
|
||||
GCPtr<Shape> m_iterator_result_object_shape;
|
||||
u32 m_iterator_result_object_value_offset { 0 };
|
||||
u32 m_iterator_result_object_done_offset { 0 };
|
||||
|
||||
// Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
|
||||
GCPtr<ProxyConstructor> m_proxy_constructor;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue