Skip to content

Commit 57a4ea0

Browse files
committed
Make initialSize configurable in UnsafeSorter
1 parent abf7bfe commit 57a4ea0

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

core/src/main/java/org/apache/spark/unsafe/sort/UnsafeSorter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static abstract class PrefixComparator {
6767
* Within this buffer, position {@code 2 * i} holds a pointer pointer to the record at
6868
* index {@code i}, while position {@code 2 * i + 1} in the array holds an 8-byte key prefix.
6969
*/
70-
private long[] sortBuffer = new long[1024];
70+
private long[] sortBuffer;
7171

7272
private int sortBufferInsertPosition = 0;
7373

@@ -82,7 +82,10 @@ public UnsafeSorter(
8282
final TaskMemoryManager memoryManager,
8383
final RecordComparator recordComparator,
8484
PrefixComputer prefixComputer,
85-
final PrefixComparator prefixComparator) {
85+
final PrefixComparator prefixComparator,
86+
int initialSize) {
87+
assert (initialSize > 0);
88+
this.sortBuffer = new long[initialSize * 2];
8689
this.memoryManager = memoryManager;
8790
this.prefixComputer = prefixComputer;
8891
this.sorter =

core/src/test/java/org/apache/spark/unsafe/sort/UnsafeSorterSuite.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ public int compare(long prefix1, long prefix2) {
106106
return (int) prefix1 - (int) prefix2;
107107
}
108108
};
109-
final UnsafeSorter sorter =
110-
new UnsafeSorter(memoryManager, recordComparator, prefixComputer, prefixComparator);
109+
final UnsafeSorter sorter = new UnsafeSorter(memoryManager, recordComparator, prefixComputer,
110+
prefixComparator, dataToSort.length);
111111
// Given a page of records, insert those records into the sorter one-by-one:
112112
position = dataPage.getBaseOffset();
113113
for (int i = 0; i < dataToSort.length; i++) {

0 commit comments

Comments
 (0)