@Override
        public int compare(RecordPointerAndKeyPrefix r1, RecordPointerAndKeyPrefix r2) {
            final int prefixComparisonResult = prefixComparator.compare(r1.keyPrefix, r2.keyPrefix);
            if (prefixComparisonResult == 0) {
                final Object baseObject1 = memoryManager.getPage(r1.recordPointer);
                final long baseOffset1 = memoryManager.getOffsetInPage(r1.recordPointer) + 4; // skip length
                final Object baseObject2 = memoryManager.getPage(r2.recordPointer);
                final long baseOffset2 = memoryManager.getOffsetInPage(r2.recordPointer) + 4; // skip length
                return recordComparator.compare(baseObject1, baseOffset1, baseObject2, baseOffset2);
            } else {
                return prefixComparisonResult;
            }
        }
Sorts records using an AlphaSort-style key-prefix sort. This sort stores pointers to records
alongside a user-defined prefix of the record's sorting key. When the underlying sort algorithm
compares records, it will first compare the stored key prefixes; if the prefixes are not equal,
then we do not need to traverse the record pointers to compare the actual records. Avoiding these
random memory accesses improves cache hit rates.
indexr-query-opt/src/main/java/org/apache/spark/util/collection/unsafe/sort/UnsafeInMemorySorter.java