reswqa commented on code in PR #20216:
URL: https://github.com/apache/flink/pull/20216#discussion_r933483230
##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/buffer/BufferCompressor.java:
##########
@@ -107,15 +107,28 @@ private int compress(Buffer buffer) {
"Illegal reference count, buffer need to be released.");
try {
+ int compressedLen;
int length = buffer.getSize();
- // compress the given buffer into the internal heap buffer
- int compressedLen =
- blockCompressor.compress(
- buffer.getNioBuffer(0, length),
- 0,
- length,
- internalBuffer.getNioBuffer(0,
internalBuffer.capacity()),
- 0);
+ // if buffer is in-heap, manipulate the underlying array directly.
+ if (!buffer.getMemorySegment().isOffHeap()) {
Review Comment:
Good suggestion. In addition, for internalBuffer, can we promote the heap
array to class field named `internalBufferArray`, and directly use it instead
of `internalBuffer.array()` for the `!buffer.getMemorySegment().isOffHeap()`
branch to avoid `ensureAccessible` every time as we will take care of the ref
count of internal buffer.
##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/buffer/BufferCompressor.java:
##########
@@ -107,15 +107,28 @@ private int compress(Buffer buffer) {
"Illegal reference count, buffer need to be released.");
try {
+ int compressedLen;
int length = buffer.getSize();
- // compress the given buffer into the internal heap buffer
- int compressedLen =
- blockCompressor.compress(
- buffer.getNioBuffer(0, length),
- 0,
- length,
- internalBuffer.getNioBuffer(0,
internalBuffer.capacity()),
- 0);
+ // if buffer is in-heap, manipulate the underlying array directly.
+ if (!buffer.getMemorySegment().isOffHeap()) {
Review Comment:
Good suggestion. In addition, for internalBuffer, can we promote the heap
array to class field named `internalBufferArray`, and directly use it instead
of `internalBuffer.array()` for the `!buffer.getMemorySegment().isOffHeap()`
branch to avoid `ensureAccessible` every time as we will take care of the ref
count of internal buffer?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]