On Mon, Mar 14, 2016 at 2:16 PM, Tab Atkins Jr. <jackalm...@gmail.com>
wrote:

> On Fri, Mar 11, 2016 at 8:17 PM, Isiah Meadows <isiahmead...@gmail.com>
> wrote:
> > In my honest opinion, there's not much reason to just require the sort
> to be
> > stable. Some engines have done this in the past, and the spec technically
> > allows it. At this point, stable sorts are about as fast as unstable
> ones,
> > both in theory and practice (wasn't the case 10 years ago IIRC).
>
> I think you meant "to not just require", yes?  As in, you think the
> spec *should* require .sort() to be stable?
>
> On Sun, Mar 13, 2016 at 12:23 PM, Vic99999 <vic99...@yandex.ru> wrote:
> > Stable sort is useful sometimes, but it is possible to implement it in
> js.
>
> Most things in the JS standard library are possible in userland code,
> so that's not a useful rebuttal to anything by itself.  The question
> is whether it's worth requiring that the standard sort be stable.
> Stable sort is never *bad* - there are no use-cases where a stable
> sort gives the wrong answer while an unstable sort is correct, but the
> opposite is definitely true.  The only question is how much
> slower/more expensiver stable sorting is than unstable sorting, and
> whether that cost is sufficient to outweigh the usefulness of a stable
> sort.
>

ISTM a symbol could be defined to grab a handle on the implementation's
fastest possible sort logic. If the implementation has a substantially
faster unstable sort algo they'd surface it here -- otherwise this would
just delegate to the implementation's stable sort. This could be
`Array.prototype.sort`, or it could also be a spec'd symbol which
`Array.prototype.sort` delegates to. (Or this could all be done w/ modules,
although modules might complicate what's otherwise pretty simple to
polyfill).

But fastest-possible (likely unstable) sort logic should be opt-in, not
opt-out. If the perf difference is that relevant to your use case you
probably don't want off-the-shelf `Array.prototype.sort` anyway.
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to