Bug 110718 - Array.prototype.sort is not quite stable
Summary: Array.prototype.sort is not quite stable
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
Depends on:
Blocks: 110007
  Show dependency treegraph
Reported: 2013-02-24 17:16 PST by Richard Gibson
Modified: 2013-02-24 18:49 PST (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Richard Gibson 2013-02-24 17:16:53 PST
The results of sorting length-N arrays for sufficiently large N appear to differ from a stable sort only at indices 0, 1, and N/2. It would be very convenient for Sizzle and jQuery if the sort were made fully stable, *especially* if such change lands in 537.32 so there's no release in which #108274 is fixed but this is not.

Example with strings: http://jsfiddle.net/zTprj/1/
Example with DOM nodes: http://jsfiddle.net/vU2uB/
jQuery tickets: http://bugs.jquery.com/ticket/13505 http://bugs.jquery.com/ticket/13331
Comment 1 Kyle Simpson 2013-02-24 17:42:47 PST
For reference, discussion thread for Chrome about this: http://code.google.com/p/v8/issues/detail?id=90

In particular, some people on the thread balk at stabilizing the sort because the spec for JS doesn't mandate stable sort (apparently wanting to give implementers more flexibility for performance sake).
Comment 2 Richard Gibson 2013-02-24 18:49:38 PST
Argh, forgive me for the misplaced report. WebKit handles this just fine; V8 is the inconsistent engine here. Moving discussion to their tracker.