Skip to content

Commit c55d98b

Browse files
author
zhongheng.gy
committed
reuse shrink constants from RowHelper
1 parent 075a825 commit c55d98b

2 files changed

Lines changed: 5 additions & 17 deletions

File tree

paimon-common/src/main/java/org/apache/paimon/data/RowHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ public class RowHelper implements Serializable {
4040
* Maximum retained reuse buffer size in bytes. Buffers exceeding this cap are eligible for
4141
* release when the shrink ratio condition is also met.
4242
*/
43-
private static final int MAX_RETAINED_REUSE_BUFFER_SIZE = 4 * 1024 * 1024; // 4MB
43+
public static final int MAX_RETAINED_REUSE_BUFFER_SIZE = 4 * 1024 * 1024; // 4MB
4444

4545
/**
4646
* Shrink ratio for hysteresis. The buffer is released only when its capacity exceeds {@link
4747
* #MAX_RETAINED_REUSE_BUFFER_SIZE} AND is more than {@code SHRINK_RATIO} times the current
4848
* row's size. This avoids thrashing for sustained medium-to-large records while still releasing
4949
* after a spike (e.g. 100MB buffer with 5MB rows → 20x > 4x → release).
5050
*/
51-
private static final int SHRINK_RATIO = 4;
51+
public static final int SHRINK_RATIO = 4;
5252

5353
private final FieldGetter[] fieldGetters;
5454
private final ValueSetter[] valueSetters;

paimon-common/src/main/java/org/apache/paimon/data/serializer/BinaryRowSerializer.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.paimon.data.AbstractPagedInputView;
2222
import org.apache.paimon.data.AbstractPagedOutputView;
2323
import org.apache.paimon.data.BinaryRow;
24+
import org.apache.paimon.data.RowHelper;
2425
import org.apache.paimon.io.DataInputView;
2526
import org.apache.paimon.io.DataOutputView;
2627
import org.apache.paimon.memory.MemorySegment;
@@ -80,19 +81,6 @@ public BinaryRow deserialize(DataInputView source) throws IOException {
8081
return row;
8182
}
8283

83-
/**
84-
* Maximum retained reuse buffer size in bytes. Buffers exceeding this cap are eligible for
85-
* shrinking when the shrink ratio condition is also met.
86-
*/
87-
private static final int MAX_RETAINED_REUSE_BUFFER_SIZE = 4 * 1024 * 1024; // 4MB
88-
89-
/**
90-
* Shrink ratio. The buffer is reallocated only when its size exceeds {@link
91-
* #MAX_RETAINED_REUSE_BUFFER_SIZE} AND is more than {@code SHRINK_RATIO} times the current
92-
* record length.
93-
*/
94-
private static final int SHRINK_RATIO = 4;
95-
9684
public BinaryRow deserialize(BinaryRow reuse, DataInputView source) throws IOException {
9785
MemorySegment[] segments = reuse.getSegments();
9886
checkArgument(
@@ -103,8 +91,8 @@ public BinaryRow deserialize(BinaryRow reuse, DataInputView source) throws IOExc
10391
if (segments == null || segments[0].size() < length) {
10492
// Need a larger buffer
10593
segments = new MemorySegment[] {MemorySegment.wrap(new byte[length])};
106-
} else if (segments[0].size() > MAX_RETAINED_REUSE_BUFFER_SIZE
107-
&& segments[0].size() > (long) length * SHRINK_RATIO) {
94+
} else if (segments[0].size() > RowHelper.MAX_RETAINED_REUSE_BUFFER_SIZE
95+
&& segments[0].size() > (long) length * RowHelper.SHRINK_RATIO) {
10896
segments = new MemorySegment[] {MemorySegment.wrap(new byte[length])};
10997
}
11098
source.readFully(segments[0].getArray(), 0, length);

0 commit comments

Comments
 (0)