Reuse Http2FrameStreamEvent instances to reduce GC pressure (#9392)
Motivation: We can easily reuse the Http2FrameStreamEvent instances and so reduce GC pressure as there may be multiple events per streams over the life-time. Modifications: Reuse instances Result: Less allocations
This commit is contained in:
parent
924150198e
commit
04afa3a07e
@ -423,7 +423,7 @@ public class Http2FrameCodec extends Http2ConnectionHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Http2FrameStream stream2 = newStream().setStreamAndProperty(streamKey, stream);
|
DefaultHttp2FrameStream stream2 = newStream().setStreamAndProperty(streamKey, stream);
|
||||||
onHttp2StreamStateChanged(ctx, stream2);
|
onHttp2StreamStateChanged(ctx, stream2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,7 +454,7 @@ public class Http2FrameCodec extends Http2ConnectionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onHttp2StreamStateChanged0(Http2Stream stream) {
|
private void onHttp2StreamStateChanged0(Http2Stream stream) {
|
||||||
Http2FrameStream stream2 = stream.getProperty(streamKey);
|
DefaultHttp2FrameStream stream2 = stream.getProperty(streamKey);
|
||||||
if (stream2 != null) {
|
if (stream2 != null) {
|
||||||
onHttp2StreamStateChanged(ctx, stream2);
|
onHttp2StreamStateChanged(ctx, stream2);
|
||||||
}
|
}
|
||||||
@ -611,13 +611,13 @@ public class Http2FrameCodec extends Http2ConnectionHandler {
|
|||||||
ctx.fireUserEventTriggered(evt);
|
ctx.fireUserEventTriggered(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onHttp2StreamWritabilityChanged(ChannelHandlerContext ctx, Http2FrameStream stream,
|
private void onHttp2StreamWritabilityChanged(ChannelHandlerContext ctx, DefaultHttp2FrameStream stream,
|
||||||
@SuppressWarnings("unused") boolean writable) {
|
@SuppressWarnings("unused") boolean writable) {
|
||||||
ctx.fireUserEventTriggered(Http2FrameStreamEvent.writabilityChanged(stream));
|
ctx.fireUserEventTriggered(stream.writabilityChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onHttp2StreamStateChanged(ChannelHandlerContext ctx, Http2FrameStream stream) {
|
void onHttp2StreamStateChanged(ChannelHandlerContext ctx, DefaultHttp2FrameStream stream) {
|
||||||
ctx.fireUserEventTriggered(Http2FrameStreamEvent.stateChanged(stream));
|
ctx.fireUserEventTriggered(stream.stateChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onHttp2Frame(ChannelHandlerContext ctx, Http2Frame frame) {
|
void onHttp2Frame(ChannelHandlerContext ctx, Http2Frame frame) {
|
||||||
@ -631,7 +631,7 @@ public class Http2FrameCodec extends Http2ConnectionHandler {
|
|||||||
private final class Http2RemoteFlowControllerListener implements Http2RemoteFlowController.Listener {
|
private final class Http2RemoteFlowControllerListener implements Http2RemoteFlowController.Listener {
|
||||||
@Override
|
@Override
|
||||||
public void writabilityChanged(Http2Stream stream) {
|
public void writabilityChanged(Http2Stream stream) {
|
||||||
Http2FrameStream frameStream = stream.getProperty(streamKey);
|
DefaultHttp2FrameStream frameStream = stream.getProperty(streamKey);
|
||||||
if (frameStream == null) {
|
if (frameStream == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -649,6 +649,9 @@ public class Http2FrameCodec extends Http2ConnectionHandler {
|
|||||||
private volatile int id = -1;
|
private volatile int id = -1;
|
||||||
volatile Http2Stream stream;
|
volatile Http2Stream stream;
|
||||||
|
|
||||||
|
final Http2FrameStreamEvent stateChanged = Http2FrameStreamEvent.stateChanged(this);
|
||||||
|
final Http2FrameStreamEvent writabilityChanged = Http2FrameStreamEvent.writabilityChanged(this);
|
||||||
|
|
||||||
Channel attachment;
|
Channel attachment;
|
||||||
|
|
||||||
DefaultHttp2FrameStream setStreamAndProperty(PropertyKey streamKey, Http2Stream stream) {
|
DefaultHttp2FrameStream setStreamAndProperty(PropertyKey streamKey, Http2Stream stream) {
|
||||||
|
@ -166,24 +166,23 @@ public class Http2MultiplexCodec extends Http2FrameCodec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
final void onHttp2StreamStateChanged(ChannelHandlerContext ctx, Http2FrameStream stream) {
|
final void onHttp2StreamStateChanged(ChannelHandlerContext ctx, DefaultHttp2FrameStream stream) {
|
||||||
DefaultHttp2FrameStream s = (DefaultHttp2FrameStream) stream;
|
|
||||||
|
|
||||||
switch (stream.state()) {
|
switch (stream.state()) {
|
||||||
case HALF_CLOSED_LOCAL:
|
case HALF_CLOSED_LOCAL:
|
||||||
if (stream.id() == HTTP_UPGRADE_STREAM_ID) {
|
if (stream.id() == HTTP_UPGRADE_STREAM_ID) {
|
||||||
onHttp2UpgradeStreamInitialized(ctx, s);
|
onHttp2UpgradeStreamInitialized(ctx, stream);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case HALF_CLOSED_REMOTE:
|
case HALF_CLOSED_REMOTE:
|
||||||
case OPEN:
|
case OPEN:
|
||||||
if (s.attachment != null) {
|
if (stream.attachment != null) {
|
||||||
// ignore if child channel was already created.
|
// ignore if child channel was already created.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// fall-trough
|
// fall-trough
|
||||||
ChannelFuture future = ctx.channel().eventLoop().register(
|
ChannelFuture future = ctx.channel().eventLoop().register(
|
||||||
new Http2MultiplexCodecStreamChannel(s, inboundStreamHandler));
|
new Http2MultiplexCodecStreamChannel(stream, inboundStreamHandler));
|
||||||
if (future.isDone()) {
|
if (future.isDone()) {
|
||||||
Http2MultiplexHandler.registerDone(future);
|
Http2MultiplexHandler.registerDone(future);
|
||||||
} else {
|
} else {
|
||||||
@ -191,7 +190,7 @@ public class Http2MultiplexCodec extends Http2FrameCodec {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CLOSED:
|
case CLOSED:
|
||||||
AbstractHttp2StreamChannel channel = (AbstractHttp2StreamChannel) s.attachment;
|
AbstractHttp2StreamChannel channel = (AbstractHttp2StreamChannel) stream.attachment;
|
||||||
if (channel != null) {
|
if (channel != null) {
|
||||||
channel.streamClosed();
|
channel.streamClosed();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user