Comment #41 on issue 90 by [email protected]: V8 doesn't stable sort
https://code.google.com/p/v8/issues/detail?id=90

If "saying it best" is to use the old "you are just as bad as IE" then I'm not impressed.

Take a look at http://jsperf.com/stable-sort/3 The stable sorts are almost as fast as the unstable ones, and they are only a few lines.

V8 has always put a lot of weight on speed. This is why the stable sorts are so fast. Consider the fastest, the stableSortPair. It is only 23% slower than the unstable sort. It's that fast because:

* Stable objects have their properties inlined
* The generational GC cleans up the Pair objects very quickly
* Property accesses like .obj are fast
* push() is very optimized.
* Array.prototype.sort is very fast (see what I did there?)

By prioritizing speed, we give you a tool where you can build your own stuff, and it goes fast. You don't have to beg us for an accelerated library function, you have the freedom to build your own stuff and it will go fast. In fact sometimes you can go faster than the library functions, because they have all sorts of code to take care of sick edge cases that you don't have in your web pages. You don't do Array.prototype[2] = "fish" and then expect [,,,,,][2] to be "fish", right? You don't sort sparse arrays, right? Of course you don't.

And if everyone uses it, you can ask TC39 to put in the standard library. Just like C++, which has sort and stable_sort. This will save a tiny bit of download. Seriously tiny, check out the jsperf link.

By the way there are a lot of JS implementations of merge sort on the net, and they mostly use array shift. Please don't use them. array shift is fundamentally slow because it has to shift down all the elements. We optimized the hell out of a common case using a technique that causes cancer in small rodents, but if you try to do it on a large array, performance will collapse.

--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to