From 678983f2a72fea1ec0efb89ea6d40fbe3136b2ad Mon Sep 17 00:00:00 2001 From: Tim Brooks Date: Sat, 12 Oct 2019 12:12:13 -0600 Subject: [PATCH] Do not mandate direct bytes in SslHandler queue (#9656) Motivation: Currently when the SslHandler coalesces outbound bytes it always allocates a direct byte buffer. This does not make sense if the JDK engine is being used as the bytes will have to be copied back to heap bytes for the engine to operate on them. Modifications: Inspect engine type when coalescing outbound bytes and allocate heap buffer if heap bytes are preferred by the engine. Result: Improved performance for JDK engine. Better performance in environments without direct buffer pooling. --- handler/src/main/java/io/netty/handler/ssl/SslHandler.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java index b7ebbabb7d..2e9616e187 100644 --- a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java +++ b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java @@ -2137,7 +2137,11 @@ public class SslHandler extends ByteToMessageDecoder { protected ByteBuf composeFirst(ByteBufAllocator allocator, ByteBuf first) { if (first instanceof CompositeByteBuf) { CompositeByteBuf composite = (CompositeByteBuf) first; - first = allocator.directBuffer(composite.readableBytes()); + if (engineType.wantsDirectBuffer) { + first = allocator.directBuffer(composite.readableBytes()); + } else { + first = allocator.heapBuffer(composite.readableBytes()); + } try { first.writeBytes(composite); } catch (Throwable cause) {