iteration order for Object

Lasse Reichstein reichsteinatwork at gmail.com
Mon Mar 14 03:09:06 PDT 2011


On Fri, 11 Mar 2011 16:48:04 +0100, Charles Kendrick  
<charles at isomorphic.com> wrote:

> Just connecting the dots - I addressed this in my first email on the  
> subject.  While it superficially sounds like a good compromise, I  
> actually think it's the worst possibility: it requires browser vendors  
> to implement limited order preservation, preventing deeper optimizations  
> like sorted keys.

Implementors already have to do that. In V8, some objects have their
properties backed by a hashmap. This just means that it needs an extra  
field
in that hashmap (a 50% increase in size) to store the insertion index, and  
then
extract and sort the keys by insertion index before iterating over them.

That also means that some ideas that might work well in one implementation,
like:
   function hasKey(object) { for(var _ in object) return true; return  
false; }
(which I believe works quickly in SpiderMonkey) will work much worse in  
other
implementations - by at least a factor of 10.

So yes, (some) objects are hashmaps ... plus some more.

/L 'firmly in the "they are not ordered and never were, damnit!" camp'
-- 
Lasse Reichstein - reichsteinatwork at gmail.com


More information about the es-discuss mailing list