In V8, the data structures behind the object are very different:
- Named in-object properties stored directly "on the C-structure"
- Identification properties outside the object, stored in an array external to the object, additional indirectness
- Indexed properties (properties whose property names can be converted to integers) are stored in an array external to the object but the array index acts like a key
- Ordered Hash Table
Named properties are in insertion order, as this is most natural with hidden class evolution / transitions.
Indexed properties are in their actual ordinal value because it would be a waste of memory to store the insertion order.
If you maintain a hash table, the hash table intentionally fakes the same order as the result of natural optimizations.
The same is true in other browsers, since storing indexed properties when numbers are small in a real "C" array is a huge optimization. What can change is whether the indexed properties of the properties of the first or the name are listed.
The spectrum made this optimization possible without defining the iteration order , and V8 was the first (at least according to this stream of errors) to use it.
Indexed keys listed before naming, and vice versa, are of course arbitrary and do not affect optimization.
source share