fast.js icon indicating copy to clipboard operation
fast.js copied to clipboard

faster sort?

Open pakastin opened this issue 11 years ago • 11 comments

Is Array.prototype.sort already max fast?

pakastin avatar Dec 03 '14 22:12 pakastin

Not sure, but either way it might be nice to have a fast NOT in-place sort, since it would be faster than slicing then sorting.

bttmly avatar Dec 03 '14 23:12 bttmly

yeah it's definitely worth investigating this. I really hate that sort operates in-place, suspect we can beat it with an immutable implementation.

phpnode avatar Dec 03 '14 23:12 phpnode

Yes, I really hate in-place sorting as well.. Hope you fix something out :)

pakastin avatar Dec 03 '14 23:12 pakastin

I guess question no. 1 is whether or not we want a stable sort (I'd say yes)

bttmly avatar Dec 04 '14 00:12 bttmly

+1

Some sorting algorithms are fast for small arrays whilst others performs way better for large arrays in JavaScript (see the suggestion of @zhak55 in https://github.com/josdejong/mathjs/issues/268). It may be interesting to use a different algorithm when dealing with either a small or a large array.

josdejong avatar Jan 24 '15 19:01 josdejong

node-timsort seems to be worth looking in, perf-wise http://mziccard.me/2015/08/10/node-timsort-fast-sorting-nodejs/

sairion avatar Aug 16 '15 15:08 sairion

Yeah, that one seems promising!

pakastin avatar Aug 16 '15 21:08 pakastin

..although that's almost 1000 lines of code :/

pakastin avatar Sep 05 '15 22:09 pakastin

https://gist.github.com/Yaffle/62addec7c78052ab72cc - merge sort - "slow", but stable

Yaffle avatar Jan 27 '16 04:01 Yaffle

You could ship with a tiny build system in the repository which bundles different optimizations (like the somewhat expensive 1k dynamic sorting library mentioned above) so you only get what you need, minimizing size.

wbrickner avatar Jun 24 '18 05:06 wbrickner

Or, alternatively, you could ship sort in a different module, something like @fast/sort, maybe taking it further to slicing even more the fast project with @fast/array, @fast/object, @fast/string and @fast/function

munizart avatar Dec 06 '18 16:12 munizart