Recycle RecyclableArrayDeque as fast as possible in FlowControlHandler (#9263)

Motivation:

FlowControlHandler does use a recyclable ArrayDeque internally but only recycles it when the channel is closed. We should better recycle it once it is empty.

Modifications:

Recycle the deque as fast as possible

Result:

Less RecyclableArrayDeque instances.
This commit is contained in:
Norman Maurer 2019-06-22 07:27:04 +02:00 committed by GitHub
parent 430eeee2f6
commit 2c99fc0f12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -88,7 +88,7 @@ public class FlowControlHandler extends ChannelDuplexHandler {
* testing, debugging and inspection purposes and it is not Thread safe! * testing, debugging and inspection purposes and it is not Thread safe!
*/ */
boolean isQueueEmpty() { boolean isQueueEmpty() {
return queue.isEmpty(); return queue == null || queue.isEmpty();
} }
/** /**
@ -190,9 +190,14 @@ public class FlowControlHandler extends ChannelDuplexHandler {
// We're firing a completion event every time one (or more) // We're firing a completion event every time one (or more)
// messages were consumed and the queue ended up being drained // messages were consumed and the queue ended up being drained
// to an empty state. // to an empty state.
if (queue.isEmpty() && consumed > 0) { if (queue.isEmpty()) {
queue.recycle();
queue = null;
if (consumed > 0) {
ctx.fireChannelReadComplete(); ctx.fireChannelReadComplete();
} }
}
return consumed; return consumed;
} }