Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@

import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import org.junit.Assume;
import org.junit.Test;
import org.slf4j.Logger;
Expand All @@ -41,30 +42,31 @@ public void unpackValuesUsingVector() {
}

private void unpackValuesUsingVectorBitWidth(int bitWidth) {
List<int[]> intInputs = getRangeData(bitWidth);

for (int[] intInput : intInputs) {
int pack8Count = intInput.length / 8;
int byteOutputSize = pack8Count * bitWidth;
byte[] byteOutput = new byte[byteOutputSize];
int[] output1 = new int[intInput.length];
int[] output2 = new int[intInput.length];
int[] output3 = new int[intInput.length];

BytePacker bytePacker = Packer.LITTLE_ENDIAN.newBytePacker(bitWidth);
for (int i = 0; i < pack8Count; i++) {
bytePacker.pack8Values(intInput, 8 * i, byteOutput, bitWidth * i);
}
try (Stream<int[]> intInputs = getRangeData(bitWidth)) {
intInputs.forEach(intInput -> {
int pack8Count = intInput.length / 8;
int byteOutputSize = pack8Count * bitWidth;
byte[] byteOutput = new byte[byteOutputSize];
int[] output = new int[intInput.length];

BytePacker bytePacker = Packer.LITTLE_ENDIAN.newBytePacker(bitWidth);
for (int i = 0; i < pack8Count; i++) {
bytePacker.pack8Values(intInput, 8 * i, byteOutput, bitWidth * i);
}

unpack8Values(bitWidth, byteOutput, output1);
unpackValuesUsingVectorArray(bitWidth, byteOutput, output2);
unpack8Values(bitWidth, byteOutput, output);
assertArrayEquals(intInput, output);
Arrays.fill(output, 0);

ByteBuffer byteBuffer = ByteBuffer.wrap(byteOutput);
unpackValuesUsingVectorByteBuffer(bitWidth, byteBuffer, output3);
unpackValuesUsingVectorArray(bitWidth, byteOutput, output);
assertArrayEquals(intInput, output);
Arrays.fill(output, 0);

Comment on lines +57 to 64
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arrays.fill(output, 0) after each assert is an O(n) operation over the entire output array and adds significant runtime (especially for large chunks). Since each unpack method writes all positions it is responsible for, clearing should be unnecessary if output is sized to intInput.length; if you still need clearing, limit it to the written range (e.g., 0..intInput.length).

Copilot uses AI. Check for mistakes.
assertArrayEquals(intInput, output1);
assertArrayEquals(intInput, output2);
assertArrayEquals(intInput, output3);
ByteBuffer byteBuffer = ByteBuffer.wrap(byteOutput);
unpackValuesUsingVectorByteBuffer(bitWidth, byteBuffer, output);
assertArrayEquals(intInput, output);
Arrays.fill(output, 0);
});
}
}

Expand Down Expand Up @@ -119,8 +121,7 @@ public void unpackValuesUsingVectorByteBuffer(int bitWidth, ByteBuffer input, in
}
}

private List<int[]> getRangeData(int bitWidth) {
List<int[]> result = new ArrayList<>();
private Stream<int[]> getRangeData(int bitWidth) {
int itemMax = 268435456;

long maxValue = getMaxValue(bitWidth);
Expand All @@ -131,9 +132,11 @@ private List<int[]> getRangeData(int bitWidth) {
++itemCount;
}

for (int i = 0; i < itemCount; i++) {
final int finalItemCount = itemCount;

return IntStream.range(0, finalItemCount).mapToObj(i -> {
int len;
if ((i == itemCount - 1) && mode != 0) {
if ((i == finalItemCount - 1) && mode != 0) {
len = mode;
} else {
len = itemMax;
Expand Down Expand Up @@ -162,9 +165,8 @@ private List<int[]> getRangeData(int bitWidth) {
array[j] = value;
j++;
}
result.add(array);
}
return result;
return array;
});
}

private long getMaxValue(int bitWidth) {
Expand Down