-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Unstable sorting in standard library should be faster #15388
Comments
Also, if you have time @orlp, it would be great to pick your brain here! My current understanding is that https://github.com/orlp/glidesort is the current state of the art, if you have some extra memory to spare. But for cases where you don't want/can't allocate, pdq is still the champion, right? |
Well, https://github.com/scandum/crumsort could be interesting, but I can not understand quadsort code, so I gave up my porting efforts. |
Keeping this open since std lib hash map sorting still uses insertion sort: Lines 587 to 591 in 3db3cf7
|
there is #11117 |
Ah. But, isn't rust's stable sort faster than zig's, as mentioned in the issue description? |
yes. rust implements timsort as their main stable sort |
Rust’s stable sort allocates, so it’s not immediately obvious that zig stable sort can be as fast, given that it doesn’t. |
Ah I see. With that in mind, nice work, @alichraghi! |
Zig Version
0.11.0-dev.2685+fac120bc3
Steps to Reproduce and Observed Behavior
Reproducible benchmark here:
https://github.com/matklad/benchmarks/tree/2b07628b8bbf5c9258c807aa8a221a0797f247b9/sort
The interesting bits:
By itself, the number is not surprising. Zig's sort is both stable and in place, while Rust's stable sort allocates.
However, while stable sort is a good default choice, Zig strives for optimality, so the user should be able to choose better performance if stability is not a requirement.
Expected Behavior
std.sort.sortUnstable
exists and it is as fast as state of the art. I noticed thathttps://github.com/alichraghi/zort/blob/67493f9412c65526fd0a5db447b52d53e282a934/src/pdqsort.zig
actually is a tiny bit faster than even Rust on my benchmark, so perhaps we can add that to stdlib? cc @alichraghi
The text was updated successfully, but these errors were encountered: