[[OwnPropertyKeys]] key ordering
Boris Zbarsky
bzbarsky at MIT.EDU
Mon Apr 21 23:01:48 PDT 2014
On 4/19/14, 4:38 PM, Charles Kendrick wrote:
> However, for the record, I continue to think that special treatment of
> numeric keys is a really bad design for property order for Objects (for
> Arrays, it's fine).
In practice people use plain objects as arrays (i.e. setting indexed
properties on them, then getting them, and expecting performance to
match that of arrays) that JS engines have explicitly moved toward
having more or less the same internal representation for Object and
Array, since you need the indexed access optimizations for both.
So in practice engines actually have different internal representations
for indexed (in at least some cases up to some number that's much
smaller than 2^32) properties and other properties, and the enumeration
behavior browsers have right now falls out of those internal
representations.
Now you might argue that using plain objects as arrays (in benchmarks,
no less) is bad form, and I'd agree, but the code out there is what it is.
> 3. treating array indices as special does not match any known use case
>
> No one has identified any application in which it would be desirable for
> *Object* (again *not* Array) to have this particular quirk of property
> ordering. It's purely an optimization detail leaking through.
Indeed. The problem is that the optimization in this case involves
discarding the information that you'd need to produce a different
enumeration order...
-Boris
More information about the es-discuss
mailing list