From: Phrogz Date: 2006-08-22T22:55:07+09:00 Subject: Re: Why Does Hash Apparently Reorder Its Internal Representation And Other Associated Ponderings Hal Fulton wrote: > Phrogz wrote: > > And, for what it's worth, JavaScript's Object primitive is also an > > associative array that retains insertion order for iterating keys, > > while exhibiting performance characteristics of a hash. > > I find that interesting, since so many appear convinced that > a so-called ordered hash would be "too slow." > > Do you know anything about the internal implementation? I don't. I wouldn't call most JavaScript engines 'fast', but I suspect that has to do with aspects other than the native Object type. Without having tried it, I would think that preserving insertion order would be a (small) memory size addition to each hash (as you've mentioned before), a *tiny* slowdown in the speed to store a new entry, and no performance change in accessing an entry. Anyhow, because I'm too lazy to do so, you (or someone else) can get source code for the SpiderMonkey[1] and Rhino[2] and check out how insertion order is preserved on Object. [1] http://www.mozilla.org/js/spidermonkey/ - the C-based JS engine [2] http://www.mozilla.org/rhino/ - the Java-based JS engine