Johan Nystrom-Persson
unread,Jun 21, 2021, 12:49:03 AM6/21/21Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to fastutil
Hi,
Thank you for your work on fastutil, which is clearly a great library.
I wanted to report a possible performance bug in LongArrays.radixSort(long[][] a).
This method falls back on selectionSort when the data to be sorted is below a certain size, which is hardcoded as LongArrays.RADIXSORT_NO_REC = 1024, originally in Arrays.drv.
When profiling my application, I found that radixSort(long[][]) spent more than 90% of its time in selectionSort. This didn't seem right, and overall the speed was no faster than java.util.Arrays.sort with a custom comparator.
I experimentally tried lowering the RADIXSORT_NO_REC cutoff, and got performance improvements with smaller values. I have tried various powers of 2, currently using RADIXSORT_NO_REC=16, and the smaller the value, the better the performance, as far as I can tell. Currently 16 is the best value I have found (I have yet to try 8 or smaller). With this change, radixSort(long[][]) is overall dramatically faster than before, and much faster than java.util.Arrays.sort.
I would submit a pull request, except that I have no idea how the original value of 1024 was determined, and I have only tested this for long[][], not for other primitives such as int[][], so I am not confident that my change is universally valid. (I also see that this constant is used for slightly different purposes in other methods in Arrays.drv, which I haven't tested either.) About my test application: I am sorting genetic sequence fragments, where each item is stored as a short long[] (of length 1-3 typically). The data is mostly random-looking and I sort 10,000-100,000 items at a time. I am using OpenJDK 8 on Linux 5.10; my CPU is a 4-core Core i5 3570. I get the same result when I run this code on AWS Graviton-based VMs.
Many thanks,
Johan Nystrom-Persson