3 ms·
The short answer is that v8 has several different ways of storing objects and resolving property lookups, and deleting a property causes that object to be handl
by fenomas 11y ago
The short answer is that v8 has several different ways of storing objects and resolving property lookups, and deleting a property causes that object to be handled in the slowest mode (i.e. "dictionary mode", with property data stored in a hash table).
If you want gory details I recommend Vyacheslav Egorov's blog (mrale.ph). Here's an old slide of his that lists all the ways you can force an object into dictionary mode (at least ca. 2011):
http://s3.mrale.ph/nodecamp.eu/#54 http://s3.mrale.ph/nodecamp.eu/#54
- mraleph 11y agoSome of this slide is a bit outdated by now. Using Object.seal, Object.freeze and Object.defineProperty with writable, enumerable, configurable not set to true does not cause object named properties convertion to dictionary mode. However they still convert elements storage (one containing properties with names "0", "1", etc) to dictionary mode. Similary accessors don't cause object properties storage conversion to dictionary mode unless there is a transition clash. var obj = {}; obj.__defineGetter__("foo", function () { return 0; }) print(%HasFastProperties(obj)); // => true var obj = {}; obj.__defineGetter__("foo", function () { return 0; }) // Transition clash print(%HasFastProperties(obj)); // => false Nothing changed with respect to `delete obj.foo`: this always converts named properties storage conversion to dictionary mode. However `delete arr[index]` doesn't (at least for arrays that were not in slow mode already), rules for objects depend on the amount of holes in the elements part of the object.