Speed up 1D BKD merging. (#12079)

On the NYC taxis dataset on my local machine, switching from
`Arrays#compareUnsigned` to `ArrayUtil#getUnsignedComparator` yielded a 15%
speedup of BKD merging.
This commit is contained in:
Adrien Grand 2023-01-12 18:14:15 +01:00 committed by GitHub
parent 59b17452aa
commit 729fedcbac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -278,6 +278,8 @@ Optimizations
* GITHUB#12017: Aggressive count in BooleanWeight. (Lu Xugang) * GITHUB#12017: Aggressive count in BooleanWeight. (Lu Xugang)
* GITHUB#12079: Faster merging of 1D points. (Adrien Grand)
Other Other
--------------------- ---------------------

View File

@ -366,19 +366,19 @@ public class BKDWriter implements Closeable {
} }
private static class BKDMergeQueue extends PriorityQueue<MergeReader> { private static class BKDMergeQueue extends PriorityQueue<MergeReader> {
private final int bytesPerDim; private final ArrayUtil.ByteArrayComparator comparator;
public BKDMergeQueue(int bytesPerDim, int maxSize) { public BKDMergeQueue(int bytesPerDim, int maxSize) {
super(maxSize); super(maxSize);
this.bytesPerDim = bytesPerDim; this.comparator = ArrayUtil.getUnsignedComparator(bytesPerDim);
} }
@Override @Override
public boolean lessThan(MergeReader a, MergeReader b) { public boolean lessThan(MergeReader a, MergeReader b) {
assert a != b; assert a != b;
int cmp = int cmp = comparator.compare(a.packedValue, 0, b.packedValue, 0);
Arrays.compareUnsigned(a.packedValue, 0, bytesPerDim, b.packedValue, 0, bytesPerDim);
if (cmp < 0) { if (cmp < 0) {
return true; return true;
} else if (cmp > 0) { } else if (cmp > 0) {