mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:27:45 +00:00
LibJS: Introduce "dictionary" mode for object shapes
This is similar to "unique" shapes, which were removed in commit
3d92c26445
.
The key difference is that dictionary shapes don't have a serial number,
but instead have a "cacheable" flag.
Shapes become dictionaries after 64 transitions have occurred, at which
point no further transitions occur.
As long as properties are only added to a dictionary shape, it remains
cacheable. (Since if we've cached the shape pointer in an IC somewhere,
we know the IC is still valid.)
Deleting a property from a dictionary shape causes it to become an
uncacheable dictionary.
Note that deleting a property from a non-dictionary shape still performs
a delete transition.
This fixes an issue on Discord where Object.freeze() would eventually
OOM us, since they add more than 16000 properties to a single object
before freezing it.
It also yields a 15% speedup on Octane/pdfjs.js :^)
This commit is contained in:
parent
8255a1a5ee
commit
1e90379008
4 changed files with 94 additions and 4 deletions
|
@ -49,16 +49,28 @@ public:
|
|||
Configure,
|
||||
Prototype,
|
||||
Delete,
|
||||
CacheableDictionary,
|
||||
UncacheableDictionary,
|
||||
};
|
||||
|
||||
Shape* create_put_transition(StringOrSymbol const&, PropertyAttributes attributes);
|
||||
Shape* create_configure_transition(StringOrSymbol const&, PropertyAttributes attributes);
|
||||
Shape* create_prototype_transition(Object* new_prototype);
|
||||
[[nodiscard]] NonnullGCPtr<Shape> create_delete_transition(StringOrSymbol const&);
|
||||
[[nodiscard]] NonnullGCPtr<Shape> create_cacheable_dictionary_transition();
|
||||
[[nodiscard]] NonnullGCPtr<Shape> create_uncacheable_dictionary_transition();
|
||||
|
||||
void add_property_without_transition(StringOrSymbol const&, PropertyAttributes);
|
||||
void add_property_without_transition(PropertyKey const&, PropertyAttributes);
|
||||
|
||||
void remove_property_without_transition(StringOrSymbol const&, u32 offset);
|
||||
void set_property_attributes_without_transition(StringOrSymbol const&, PropertyAttributes);
|
||||
|
||||
[[nodiscard]] bool is_cacheable() const { return m_cacheable; }
|
||||
[[nodiscard]] bool is_dictionary() const { return m_dictionary; }
|
||||
[[nodiscard]] bool is_cacheable_dictionary() const { return m_dictionary && m_cacheable; }
|
||||
[[nodiscard]] bool is_uncacheable_dictionary() const { return m_dictionary && !m_cacheable; }
|
||||
|
||||
Realm& realm() const { return m_realm; }
|
||||
|
||||
Object* prototype() { return m_prototype; }
|
||||
|
@ -103,6 +115,9 @@ private:
|
|||
|
||||
PropertyAttributes m_attributes { 0 };
|
||||
TransitionType m_transition_type { TransitionType::Invalid };
|
||||
|
||||
bool m_dictionary { false };
|
||||
bool m_cacheable { true };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue