Skip to content

Commit

Permalink
Reduce Memory used by Finished AsyncQueue Instances
Browse files Browse the repository at this point in the history
ArrayDeque instances have no way to shrink their backing array
which can grow large during query execution and is retained by way
of references in QueryTracker after completion. This resets the
AsyncQueue elements field after finishing to reduce heap usage.
  • Loading branch information
pettyjamesm authored and wenleix committed Dec 9, 2019
1 parent 0f7061f commit 951eb8d
Showing 1 changed file with 3 additions and 1 deletion.
Expand Up @@ -39,7 +39,7 @@ public class AsyncQueue<T>
private final int targetQueueSize;

@GuardedBy("this")
private final Queue<T> elements;
private Queue<T> elements;
// This future is completed when the queue transitions from full to not. But it will be replaced by a new instance of future immediately.
@GuardedBy("this")
private SettableFuture<?> notFullSignal = SettableFuture.create();
Expand Down Expand Up @@ -84,6 +84,8 @@ private synchronized void signalIfFinishing()
{
if (finishing && borrowerCount == 0) {
if (elements.size() == 0) {
// Reset elements queue after finishing to avoid holding on to the full sized empty array inside
elements = new ArrayDeque<>(0);
completeAsync(executor, notEmptySignal);
notEmptySignal = SettableFuture.create();
}
Expand Down

0 comments on commit 951eb8d

Please sign in to comment.