pivotal-jbarrett commented on code in PR #7621:
URL: https://github.com/apache/geode/pull/7621#discussion_r859096798
##########
geode-core/src/main/java/org/apache/geode/internal/net/BufferPool.java:
##########
@@ -90,46 +87,46 @@ static boolean computeUseDirectBuffers() {
*
* @return a byte buffer to be used for sending on this connection.
*/
- public ByteBuffer acquireDirectSenderBuffer(int size) {
+ public PooledByteBuffer acquireDirectSenderBuffer(int size) {
return acquireDirectBuffer(size, true);
}
- public ByteBuffer acquireDirectReceiveBuffer(int size) {
+ public PooledByteBuffer acquireDirectReceiveBuffer(int size) {
return acquireDirectBuffer(size, false);
}
/**
* try to acquire direct buffer, if enabled by configuration
*/
- private ByteBuffer acquireDirectBuffer(int size, boolean send) {
- ByteBuffer result;
+ private PooledByteBuffer acquireDirectBuffer(int size, boolean send) {
+ ByteBuffer byteBuffer;
if (useDirectBuffers) {
if (size <= MEDIUM_BUFFER_SIZE) {
- result = acquirePredefinedFixedBuffer(send, size);
+ byteBuffer = acquirePredefinedFixedBuffer(send, size);
} else {
- result = acquireLargeBuffer(send, size);
+ byteBuffer = acquireLargeBuffer(send, size);
}
- if (result.capacity() > size) {
- result.position(0).limit(size);
- result = result.slice();
+ if (byteBuffer.capacity() > size) {
+ byteBuffer.position(0).limit(size);
+ return new PooledByteBuffer(byteBuffer, byteBuffer.slice());
Review Comment:
The other half that don't invoke this method rapidly to get send buffers.
While the size is small the effect of number of objects can be detrimental and
if everyone along the path says it's small in the larger scope we eventually
end up with noticeable latency. Great care has go into removing allocations
like this in hot paths like this because they had measurable impact. While I
agree p2p has many worse places for transient allocations I don't see it as
proof to support a new one. I think we can avoid this completely by just
returning the original `ByteBuffer`. To do so we need to stop slicing, which is
not necessary.
--
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]