Skip to content

Commit

Permalink
Reduce initial size of listeners queue in WriteStreamSubscriber (#1465
Browse files Browse the repository at this point in the history
)

Motivation:

Most of the write HTTP messages have 3 listeners, because it consist of
headers, one payload body chunk (can be empty), and trailers. `ArrayDeque`
defines `MIN_INITIAL_CAPACITY = 8` internally. It's sufficient for most
use-cases. Messages with large streaming payload body may have more
listeners, but those messages have higher overhead anyway (flush-on-each,
etc.). Therefore, it's ok for them to resize the queue, if necessary.

Modifications:

- Define the default size of 8 for `listenersOnWriteBoundaries` in
`WriteStreamSubscriber.AllWritePromise`;

Result:

Less allocation per each message write.
  • Loading branch information
idelpivnitskiy authored Mar 31, 2021
1 parent d7ecc59 commit 5ee8446
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,10 @@ private final class AllWritesPromise extends DefaultChannelPromise {
* {@link #WRITE_BOUNDARY}, listener1, listener2, {@link #WRITE_BOUNDARY}, listener3 ...
* </pre>
* We assume that no listener for a write is added after that write is completed (a.k.a late listeners).
* Most of the messages have 3 listeners (headers, one payload body chunk, trailers). Messages with large
* streaming payload body may have more listeners. However, the MIN_INITIAL_CAPACITY of ArrayDeque is 8.
*/
private final Deque<GenericFutureListener<?>> listenersOnWriteBoundaries = new ArrayDeque<>();
private final Deque<GenericFutureListener<?>> listenersOnWriteBoundaries = new ArrayDeque<>(8);
private final WriteObserver observer;
private final UnaryOperator<Throwable> enrichProtocolError;

Expand Down

0 comments on commit 5ee8446

Please sign in to comment.