Array.prototype.sort is now stable in @v8js v7.0 / Chrome 70! 🎉 Previously, V8 used an unstable QuickSort for arrays with more than 10 elements. Now, we use the stable TimSort algorithm. Demo: mathiasbynens.be/demo/sort-stab…
Although not technically a spec violation, stable sort was one of the oldest and most popular developer requests in our @v8js bug tracker (issue #90!): bugs.chromium.org/p/v8/issues/de… Kudos to @nimODota for making it happen!
Fingers crossed @ChakraCore eventually switches to a stable sorting algorithm, too. Then we could update the Array.prototype.sort spec to require stability and call it a day. One can dream… (@ChakraCore’s sort is currently only stable for arrays with 512 or fewer elements.)
Update: @ChakraCore just landed a stable MergeSort, making its Array.prototype.sort stable — even for arrays with more than 512 elements! github.com/Microsoft/Chak… When this ships in Edge, Array.prototype.sort is finally 100% stable in all browsers! 🎉
@mathias @ChakraCore Curious how you see the benefits of stable sort stack up against the obscure site breaks in non-chrome, older browsers, xs, etc. as these subtle non-standard semantics become web-reality?
@mathias @ChakraCore There is an issue there now btw github.com/Microsoft/Chak…
@mathias @ChakraCore Wow! I didn't really think that was still going to happen.
@mathias @ChakraCore Can we have a sort that doesn't sort in place