-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented CombSort as an additional sorting algorithm in base #32696
Conversation
Cool. Does LLVM manage to vectorize this? Any example performance numbers? |
Yes, it gets nicely vectorized. The method implemented here is the same as the blue curve on the experiments graph from my article. It is roughly 85% faster than the default quicksort, at least for Int32 and up to 1M elements. Check out my presentation, more specifically slides 8 and 9 https://nlw0.github.io/chipsort-juliacon2019/index.html#/8 https://nlw0.github.io/chipsort-juliacon2019/index.html#/9 |
A simple test with this patch:
|
I noticed later this implementation is failing with floats. It seems to have something to do with the approach for handling |
Would it be possible to post this code somewhere in case someone wants to pick it up? |
Should be here: 91fc5a3 |
One last comment: it turns out RadixSort from SortingAlgorithms.jl can outperform this. I haven't figured out yet whether it also exploits SIMD somehow. Thus radix might be a better possible candidate for the default library, the saving grace from Combsort being its tiny code footprint. This was closed by accident, by the way, I never had two PRs open before, sorry! |
The biggest downside of radix sort are that it didn't work for all types. |
This was closed by accident, but I never reopened it. Updated with latest master branch. |
Or should it be closed? The issue was just something weird happening with floats. It still might be of interest, it's a simple algorithm that performs well in some cases. |
I'm in favor of merging if we can demonstrate performance improvements (preferably for types where radix sort doesn't work) and turn it on by default. |
The biggest claim to fame here is greater speed than the standard library on What's compelling about this CombSort approach is that it is a comparison sort and has a simple implementation, while leading itself to automatic parallelization better than QuickSort, according to my experiments. This seems to make CombSort Pareto-optimal in a way, beating the standard QuickSort for Int32, while also beating RadixSort for generality. I wasn't thinking in replacing the default, just offering an interesting alternative. Anyways, I'd gladly make more tests with other datatypes. Can I have some suggestions? I can think of random strings, and structures with increasing sizes and Int32 keys, or perhaps tuple keys. Anything else? |
Triage thinks this should go in SortingAlgorithms.jl, and we will consider moving radix sort to Base for performance. |
Comb sort is a classic and much overlooked algorithm that is very suitable for vectorization. This PR implements it as an alternative to the other algorithms in Base (Insertion, Quick, Merge). It can achieve speed-ups of ~90% over Quicksort on an AVX2 machine.
One important detail of this implementation is that we switch to Insertion sort when the interval becomes 1.
This algorithm implementation was investigated before on ChipSort.jl, presented at JuliaCon2019. More information can be found on its references.