You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello @coderb, can you provide some benchmarks that exhibit that pdqsort is faster than the existing sorting algorithm in .NET? It would help to move the suggestion forward.
@teo-tsirpanis please see the link to the golang commit. the go team (google) has devoted a large amount of engineering resources to this and has done a far better job benchmarking than i would be able to. the thing to remember is that quicksort (and introsort) have very poor performance for certain types of inputs which pdqsort overcomes. see golang/go@72e77a7
For log2 there is System.Numerics.BitOperations.Log2(uint). PdqSort_Random looks worse than ArraySort_Random, possibly because PdqSort_Random calls Compare by interface while ArraySort_Random calls Comparethrough a delegate.
It would be very important to ensure that this is tested with multiple sizes of data to show the differences between "small scale" vs "large scale".
Sorting 1 million elements faster is nice, but if that's not the "common" case and the common is more like 10-1000, then we'll end up regressing real world users.
Testing random, already sorted, mostly sorted, etc is also important, but it looks like you've got that bit covered already.
Also worth noting that the benchmarks are including the overhead of allocating and copying the data to a large array. Ideally that would be moved out to some "per iteration setup" so that the measurement is only over the actual Sort function.
The use of UnguardedAccess in UnguardedInsertionSort(and possibly elsewhere) could cause buffer overflow if the comparer is bugged.
UnguardedAccess could use Unsafe.Add(ref MemoryMarshal.GetReference(span), index), as Unsafe.Add(ref span[0], index) has an extra range check that span.Length must be positive.
UnguardedSlice should use MemoryMarshal.CreateSpan(ref UnguardedAccess(span, begin), end - begin). Unsafe.AsPointer could stop GC tracking.
ghost added
in-prThere is an active PR which will close this issue when it is merged
Activity
kasperk81 commentedon Apr 21, 2022
has
std::sort()switched from introsort to pdqsort? in which version of STL?coderb commentedon Apr 21, 2022
@kasperk81 sorry... maybe i misread the golang commit message. there is an implementation for rust/c++, i guess it's not standard. my bad.
teo-tsirpanis commentedon Apr 21, 2022
Hello @coderb, can you provide some benchmarks that exhibit that pdqsort is faster than the existing sorting algorithm in .NET? It would help to move the suggestion forward.
coderb commentedon Apr 21, 2022
@teo-tsirpanis please see the link to the golang commit. the go team (google) has devoted a large amount of engineering resources to this and has done a far better job benchmarking than i would be able to. the thing to remember is that quicksort (and introsort) have very poor performance for certain types of inputs which pdqsort overcomes. see golang/go@72e77a7
hez2010 commentedon Apr 22, 2022
I would also like to recommend .NET to change its sort implementation to pdqsort. Generally pdqsort performs way better than introsort (std::sort):
hez2010 commentedon Apr 22, 2022
I ported pdqsort(https://github.com/orlp/pdqsort) to C# and this is the benchmark result:
code: https://gist.github.com/hez2010/6b52929ee1755788c34818972c46aefb
/cc:@stephentoub
tfenise commentedon Apr 22, 2022
For log2 there is
System.Numerics.BitOperations.Log2(uint).PdqSort_Randomlooks worse thanArraySort_Random, possibly becausePdqSort_RandomcallsCompareby interface whileArraySort_RandomcallsComparethrough a delegate.tannergooding commentedon Apr 22, 2022
It would be very important to ensure that this is tested with multiple sizes of data to show the differences between "small scale" vs "large scale".
Sorting 1 million elements faster is nice, but if that's not the "common" case and the common is more like 10-1000, then we'll end up regressing real world users.
Testing random, already sorted, mostly sorted, etc is also important, but it looks like you've got that bit covered already.
tannergooding commentedon Apr 22, 2022
Also worth noting that the benchmarks are including the overhead of allocating and copying the data to a large array. Ideally that would be moved out to some "per iteration setup" so that the measurement is only over the actual
Sortfunction.coderb commentedon Apr 22, 2022
@hez2010 you may want to test on objects in addition to primitives.
hez2010 commentedon Apr 23, 2022
@tannergooding I modified my code and rerun it with .NET 7 (PGO+QJFL+OSR enabled), PdqSort out performs in every case:
See code here: https://gist.github.com/hez2010/6b52929ee1755788c34818972c46aefb
tfenise commentedon Apr 23, 2022
The use of
UnguardedAccessinUnguardedInsertionSort(and possibly elsewhere) could cause buffer overflow if the comparer is bugged.UnguardedAccesscould useUnsafe.Add(ref MemoryMarshal.GetReference(span), index), asUnsafe.Add(ref span[0], index)has an extra range check thatspan.Lengthmust be positive.UnguardedSliceshould useMemoryMarshal.CreateSpan(ref UnguardedAccess(span, begin), end - begin).Unsafe.AsPointercould stop GC tracking.jeffhandley commentedon Jun 24, 2022
The discussion in #68436 revealed that we need to define acceptance criteria for a change to our default sort algorithm.
blackholeearth commentedon Nov 4, 2023
https://github.com/scandum/fluxsort
İmage is from the repo.
Just to let u know,
Maybe, in couple of years another sort algos might popup , which might outperform it.