jonhoo / proximity-sort

Simple command-line utility for sorting inputs by proximity to a path argument
Apache License 2.0
117 stars 8 forks source link

Consider using rayon to parallelize this #8

Open svenstaro opened 4 years ago

svenstaro commented 4 years ago

Hey, super nice tool. I'm now using this with fzf.vim for great effect. However, after some benchmarking, I can't help but wonder whether perhaps we'd get an even faster result by parallelizing the sorting. In a benchmark via hyperfine, it takes my laptop about 3s to order a list of 2.2m files (all files on my computer). That's not bad at all but still perceivable. Perhaps we can get it down to 0.8s which would be great. Perhaps something like par_sort_by could be used with a custom criterion?

jonhoo commented 4 years ago

Thanks! I'm amazed that you're even using this across your whole file system! That's at least never a way that I've used fzf in the past — I only ever use it for a particular project at a time.

You are right that rayon parallel sorting might give us a decent speedup for lists as large as that one, and it's worth investigating. I'd mainly be worried about whether it slows down small searches measurably, which are arguably the most common use-case. As long as that's not the case, it seems like a good idea!

svenstaro commented 4 years ago

It will definitely slow down small searches but not in any way that matters. Rayon will only spawn threads if it thinks that it'll actually result in a speedup (i.e. if the chunk size is large enough to even warrant multithreading) so it should not matter. I think the benefits are very likely to outweigh the drawbacks.