Try to reduce GC produced while writing headers (#9682)
Motivation:
bbc34d0eda
introduced correct handling of "in process" setup of streams but there is some room for improvements. Often the writeHeaders(...) is completed directly which means there is not need to create the extra listener object.
Modifications:
- Only create the listener if we really need too.
Result:
Less GC
This commit is contained in:
parent
19b4adf79c
commit
95230e01da
@ -159,12 +159,6 @@ public class Http2FrameCodec extends Http2ConnectionHandler {
|
||||
private int numBufferedStreams;
|
||||
private final IntObjectMap<DefaultHttp2FrameStream> frameStreamToInitializeMap =
|
||||
new IntObjectHashMap<DefaultHttp2FrameStream>(8);
|
||||
private final ChannelFutureListener bufferedStreamsListener = new ChannelFutureListener() {
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture future) {
|
||||
numBufferedStreams--;
|
||||
}
|
||||
};
|
||||
|
||||
Http2FrameCodec(Http2ConnectionEncoder encoder, Http2ConnectionDecoder decoder, Http2Settings initialSettings,
|
||||
boolean decoupleCloseAndGoAway) {
|
||||
@ -420,23 +414,30 @@ public class Http2FrameCodec extends Http2ConnectionHandler {
|
||||
// We should not re-use ids.
|
||||
assert old == null;
|
||||
|
||||
// Clean up the stream being initialized if writing the headers fails.
|
||||
promise.addListener(new ChannelFutureListener() {
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture channelFuture) {
|
||||
if (!channelFuture.isSuccess()) {
|
||||
frameStreamToInitializeMap.remove(streamId);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
encoder().writeHeaders(ctx, streamId, headersFrame.headers(), headersFrame.padding(),
|
||||
headersFrame.isEndStream(), promise);
|
||||
|
||||
if (!promise.isDone()) {
|
||||
numBufferedStreams++;
|
||||
promise.addListener(bufferedStreamsListener);
|
||||
// Clean up the stream being initialized if writing the headers fails and also
|
||||
// decrement the number of buffered streams.
|
||||
promise.addListener(new ChannelFutureListener() {
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture channelFuture) {
|
||||
numBufferedStreams--;
|
||||
|
||||
handleHeaderFuture(channelFuture, streamId);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
handleHeaderFuture(promise, streamId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleHeaderFuture(ChannelFuture channelFuture, int streamId) {
|
||||
if (!channelFuture.isSuccess()) {
|
||||
frameStreamToInitializeMap.remove(streamId);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user