Skip to content

Commit

Permalink
Optimize retained memory size calculation for getRegion method of Bin…
Browse files Browse the repository at this point in the history
…aryColumn
  • Loading branch information
JackieTien97 committed Jan 21, 2025
1 parent a608201 commit beace6c
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -78,6 +78,34 @@ public BinaryColumn(int positionCount, Optional<boolean[]> valueIsNull, Binary[]
retainedSizeInBytes = INSTANCE_SIZE + sizeOfBooleanArray(positionCount) + sizeOf(values);
}

// called by getRegion which already knows the underlying retainedSizeInBytes
private BinaryColumn(
int arrayOffset,
int positionCount,
boolean[] valueIsNull,
Binary[] values,
long retainedSizeInBytes) {
if (arrayOffset < 0) {
throw new IllegalArgumentException("arrayOffset is negative");
}
this.arrayOffset = arrayOffset;
if (positionCount < 0) {
throw new IllegalArgumentException("positionCount is negative");
}
this.positionCount = positionCount;

if (values.length - arrayOffset < positionCount) {
throw new IllegalArgumentException("values length is less than positionCount");
}
this.values = values;

if (valueIsNull != null && valueIsNull.length - arrayOffset < positionCount) {
throw new IllegalArgumentException("isNull length is less than positionCount");
}
this.valueIsNull = valueIsNull;
this.retainedSizeInBytes = retainedSizeInBytes;
}

@Override
public TSDataType getDataType() {
return TSDataType.TEXT;
@@ -141,7 +169,8 @@ public long getRetainedSizeInBytes() {
@Override
public Column getRegion(int positionOffset, int length) {
checkValidRegion(getPositionCount(), positionOffset, length);
return new BinaryColumn(positionOffset + arrayOffset, length, valueIsNull, values);
return new BinaryColumn(
positionOffset + arrayOffset, length, valueIsNull, values, getRetainedSizeInBytes());
}

@Override

0 comments on commit beace6c

Please sign in to comment.