Skip to content

Commit

Permalink
Reclaim PagesSerde memory in Query
Browse files Browse the repository at this point in the history
When we finish reading data for a query we can
safely null reference to PagesSerde used for deserializing
query results. This allow GCing buffer references stored
in PagesSerde.
  • Loading branch information
losipiuk committed Dec 1, 2022
1 parent 9f4b153 commit 18a622d
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ class Query
private final Executor resultsProcessorExecutor;
private final ScheduledExecutorService timeoutExecutor;

private final PagesSerde serde;
@GuardedBy("this")
private PagesSerde serde;

private final boolean supportsParametricDateTime;

@GuardedBy("this")
Expand Down Expand Up @@ -232,7 +234,7 @@ private Query(
this.resultsProcessorExecutor = resultsProcessorExecutor;
this.timeoutExecutor = timeoutExecutor;
this.supportsParametricDateTime = session.getClientCapabilities().contains(ClientCapabilities.PARAMETRIC_DATETIME.toString());
serde = new PagesSerdeFactory(blockEncodingSerde, isExchangeCompressionEnabled(session))
this.serde = new PagesSerdeFactory(blockEncodingSerde, isExchangeCompressionEnabled(session))
.createPagesSerde(session.getExchangeEncryptionKey().map(Ciphers::deserializeAesEncryptionKey));
}

Expand Down Expand Up @@ -575,6 +577,7 @@ private synchronized QueryResultRows removePagesFromExchange(QueryInfo queryInfo
}
if (exchangeDataSource.isFinished()) {
exchangeDataSource.close();
serde = null; // null to reclaim memory of PagesSerde which does not expose explicit lifecycle
}
}
catch (Throwable cause) {
Expand Down

0 comments on commit 18a622d

Please sign in to comment.