Skip to content

Commit

Permalink
[Java] Avoid temporary copy when patching frame headers for a block.
Browse files Browse the repository at this point in the history
  • Loading branch information
vyazelenko committed Feb 7, 2024
1 parent 6e97490 commit 29053fe
Showing 1 changed file with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import io.aeron.driver.MediaDriver;
import io.aeron.logbuffer.BlockHandler;
import io.aeron.protocol.HeaderFlyweight;
import org.agrona.BufferUtil;
import org.agrona.concurrent.IdleStrategy;
import org.agrona.concurrent.SystemNanoClock;
import org.agrona.concurrent.UnsafeBuffer;
Expand All @@ -37,7 +36,6 @@
import static io.aeron.logbuffer.FrameDescriptor.*;
import static io.aeron.protocol.DataHeaderFlyweight.*;
import static java.nio.ByteOrder.LITTLE_ENDIAN;
import static org.agrona.BitUtil.CACHE_LINE_LENGTH;
import static org.agrona.BitUtil.align;
import static org.agrona.CloseHelper.closeAll;
import static org.agrona.PropertyAction.PRESERVE;
Expand Down Expand Up @@ -95,12 +93,10 @@ public final class EchoNode implements AutoCloseable, Runnable
image.termBufferLength() + " (expected=" + publication.termBufferLength() + ")");
}

blockBuffer.wrap(BufferUtil.allocateDirectAligned(publication.termBufferLength() >> 1, CACHE_LINE_LENGTH));

blockHandler = (buffer, offset, length, subSessionId, subTermId) ->
{
// TODO: Can we avoid a copy here?
blockBuffer.putBytes(0, buffer, offset, length);
// wrap Subscription buffer to patch frame headers in place (i.e. without temporary copy)
blockBuffer.wrap(buffer, offset, length);

final int streamId = publication.streamId();
final int sessionId = publication.sessionId();
Expand Down

0 comments on commit 29053fe

Please sign in to comment.