Skip to content

Commit

Permalink
StreamTracker should better extend ArrayDeque to reduce memory copies
Browse files Browse the repository at this point in the history
Motivation:

StreamTracker did extend ArrayList which is not optimal as we always remove from index 0 and so cause memory copies.

Modifications:

Let StreamTracker extend ArrayDeque so removals dont cause memory copies all the time

Result:

Less memory copies
  • Loading branch information
normanmaurer committed Nov 30, 2023
1 parent 86a88c4 commit e3337c3
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.netty.util.ReferenceCountUtil;
import io.netty.util.collection.LongObjectHashMap;

import java.util.ArrayList;
import java.util.ArrayDeque;
import java.util.Map;

import static io.netty.incubator.codec.http3.Http3CodecUtils.closeOnFailure;
Expand Down Expand Up @@ -495,13 +495,13 @@ private boolean mayNotBlockStream() {
return blockedStreams >= maxBlockedStreams - 1;
}

private static final class StreamTracker extends ArrayList<Integer> {
private static final class StreamTracker extends ArrayDeque<Integer> {
StreamTracker() {
super(1); // we will mostly have a single header block in a stream.
}

int takeNextInsertCount() {
return isEmpty() ? -1 : remove(0);
return isEmpty() ? -1 : poll();
}
}
}

0 comments on commit e3337c3

Please sign in to comment.