I need to solve a combinatorics problem, that requires, among others, finding and sortperm (a.k.a. argsort) for thousands of millions of vectors of fixed size.
It so happens that the size of the vector is known at the compile time in my setup.
Since the size of the vectors is expected to be small (single digit), I expect a significant speedup when compiler is given the size of the vectors, because it theoretically can unroll the sort into a hierarchy of βifβ statements.
Is this kind of optimization achievable in Julia? If so, how?
Itβs pretty fast, but the speedup is less than what you will see from other operations, probably.
SVectors are statically sized as well as immutable, if you absolutely have to mutate the vectors, there are also MVector, but in most cases immutability is not a problem.
(Edit: The below benchmarks are not quite reliable, since it probably measures sorting vectors that are already sorted during the benchmark. Iβm not sure how to benchmark in-place sorting of short vectors, since using evals=1 does not work quite well either. Benchmarking of sort (not sort!) is probably more reliable.)
Sorting in-place with sort! is actually faster than sorting SVectors, which surprises me a bit. Keep in mind, though, that SVectors have many other performance benefits that you should consider.