iteration order for Object

Charles Kendrick charles at isomorphic.com
Thu Mar 10 21:20:27 PST 2011


On 3/10/2011 7:18 PM, Brendan Eich wrote:
> On Mar 10, 2011, at 6:50 PM, Charles Kendrick wrote:
>> Has a use case been identified where treating numeric properties differently from other properties is a desirable behavior?
>
> If I'm reading you right, you don't mind us specifying arrays enumerating indexed "own" properties first and in index order.

Yes, exactly.  I understand the performance advantage here and I think Arrays should either do 
exactly what's in the strawman or even not have a standardized iteration order (for maximum 
optimization leeway).

> But it gets worse: several notable JS libraries, including IIRC jQuery (the #1 library in popularity right now), use indexed properties on Object instances -- frequently. I'll try to dig up the references.
>
> Those VMs that optimize indexed properties on Object to be (a) fast; (b, and therefore) enumerated in index order, do better on such code. VMs that optimize only for certain "dense-enough arrays" lose.
>
> This creates pressure to follow the performance leader and treat indexed properties the same, in terms of enumeration, on all objects including arrays.

You're correct, JQuery returns most query results as an Object where each matching element is 
placed at a numeric index and it also does a lot of subsetting and traversal on such objects.

However, I doubt very much that the effect on JQuery of dense arrays could be shown outside of 
synthetic benchmarks and very very niche use cases.  References would be great if you can find 
them.

However large the effect on JQuery, I expect that a benchmark of a JavaScript LinkedHashMap 
implementation as compared to native speed would be, I would guess, something like a 25x advantage.

Further, note that JQuery's use of Object is an implementation detail that may change in the 
future.  Big chunks of JQuery are now shims for old browsers to duplicate HTML5/CSS3 native 
support, and libraries are emerging that are roughly JQuery-compatible but directly return an 
augmented native NodeList instead of an Object with indices:

	http://chocolatechipmobile.wordpress.com/

JQuery may well adopt this just as it adopted Sizzle, so it would be a shame to optimize the 
language for such a short-lived advantage.

> Harmony is *not* a clean break. I don't know why you wrote that.

Quite right Brendan, sorry about that, I understand that it's designed as a more minimal break. 
  Thanks for giving me the fingers ;)


More information about the es-discuss mailing list