From 56e8e43b799bb6821f6beb6fd35932ee9ff0f84c Mon Sep 17 00:00:00 2001 From: "He-Pin(kerr)" Date: Sat, 4 Jan 2025 00:27:42 +0800 Subject: [PATCH] perf: optmize NettyChannelHandlerAdapter with explict extends. (#1667) (cherry picked from commit 03712a927e67723e9ffeadaa0b774dae45cbea88) --- .../remote/transport/netty/NettyHelpers.scala | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/remote/src/main/scala/org/apache/pekko/remote/transport/netty/NettyHelpers.scala b/remote/src/main/scala/org/apache/pekko/remote/transport/netty/NettyHelpers.scala index 3b17a577303..f1bcbe66974 100644 --- a/remote/src/main/scala/org/apache/pekko/remote/transport/netty/NettyHelpers.scala +++ b/remote/src/main/scala/org/apache/pekko/remote/transport/netty/NettyHelpers.scala @@ -23,7 +23,7 @@ import pekko.PekkoException import pekko.util.unused import io.netty.buffer.ByteBuf -import io.netty.channel.{ ChannelHandlerContext, SimpleChannelInboundHandler } +import io.netty.channel.{ ChannelHandlerContext, ChannelInboundHandlerAdapter } /** * INTERNAL API @@ -53,10 +53,19 @@ private[netty] trait NettyHelpers { /** * INTERNAL API */ -private[netty] abstract class NettyChannelHandlerAdapter extends SimpleChannelInboundHandler[ByteBuf] +private[netty] abstract class NettyChannelHandlerAdapter extends ChannelInboundHandlerAdapter with NettyHelpers { - final override def channelRead0(ctx: ChannelHandlerContext, msg: ByteBuf): Unit = { - onMessage(ctx, msg) + + final override def channelRead(ctx: ChannelHandlerContext, msg: AnyRef): Unit = { + msg match { + case buf: ByteBuf => + try { + onMessage(ctx, buf) + } catch { + case ex: Throwable => transformException(ctx, ex) + } finally buf.release() // ByteBuf must be released explicitly + case _ => ctx.fireChannelRead(msg) + } } @nowarn("msg=deprecated")