franz1981 commented on a change in pull request #2522: ARTEMIS-2239 Zero-copy NIO/MAPPED TimedBuffer URL: https://github.com/apache/activemq-artemis/pull/2522#discussion_r251009673
########## File path: artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/buffer/TimedBuffer.java ########## @@ -358,13 +358,7 @@ public boolean flushBatch() { bytesFlushed.addAndGet(pos); } - final ByteBuffer bufferToFlush = bufferObserver.newBuffer(bufferSize, pos); - //bufferObserver::newBuffer doesn't necessary return a buffer with limit == pos or limit == bufferSize!! - bufferToFlush.limit(pos); - //perform memcpy under the hood due to the off heap buffer - buffer.getBytes(0, bufferToFlush); - - bufferObserver.flushBuffer(bufferToFlush, pendingSync, callbacks); + bufferObserver.flushBuffer(buffer.byteBuf(), pendingSync, callbacks); Review comment: It has been solved on the abstract seq file Local: ASYNCIO is doing is exactly like before (with the copy), while NIO/MAPPED avoid the copy by using a specialized class. For ASYNCIO: ```java @Override public void flushBuffer(final ByteBuffer buffer, final boolean requestedSync, final List<IOCallback> callbacks) { public void flushBuffer(final ByteBuf byteBuf, final boolean requestedSync, final List<IOCallback> callbacks) { buffer.flip(); final int bytes = byteBuf.readableBytes(); if (bytes > 0) { if (buffer.limit() == 0) { final ByteBuffer buffer = newBuffer(byteBuf.capacity(), bytes); factory.releaseBuffer(buffer); buffer.limit(bytes); } else { byteBuf.getBytes(byteBuf.readerIndex(), buffer); buffer.flip(); writeDirect(buffer, requestedSync, new DelegateCallback(callbacks)); writeDirect(buffer, requestedSync, new DelegateCallback(callbacks)); } else { DelegateCallback.done(callbacks); } } } } ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services