Hi all,

I’m happy to share this proof of concept about refactoring the sorting and ordering API in Julia:

**SortingSortingOut.jl**

The basic ideas are:

- To make
`Ordering`

objects more composable and reusable - To figure out a better way to dispatch on efficient sorting algorithms.

The following is one of the motivating examples where `sort!`

does not dispatch on an efficient floating point sorting algorithm, because the signature is `sort!(::Vector{Product}, ...)`

rather than `sort!(::Vector{Float64})`

. In my package I try to dispatch on the inferred type that is being compared / sorted, which allows me to use the efficient floating point sorting algorithm .

## Results

n | `sort!` |
`sortsort!` |
x faster |
---|---|---|---|

10_000 | 1.113 ms | 560.6 μs | 2.0x |

1_000 | 66.00 μs | 11.66 μs | 5.7x |

100 | 2.021 μs | 615.6 ns | 3.3x |

## Benchmark

```
using SortingSortingOut, BenchmarkTools
struct Product
price::Int
weight::Float64
end
weight(p::Product) = p.weight
function sort_products(n = 100)
products = [Product(rand(1:100), 100rand()) for i = 1 : n]
fst = @benchmark sort!(ps, by = $weight) setup = (ps = copy($products))
snd = @benchmark sortsort!(ps, $(By(weight))) setup = (ps = copy($products))
fst, snd
end
```

I’m hoping people could give feedback on this idea