Skip to content

Commit 5e08794

Browse files
jensjohaCommit Queue
authored and
Commit Queue
committed
[analyzer] Plug "temporary leak" when starting new rebuilds before afterContextsCreated is called
If again and again editing, say, a `pubspec.yaml` with proper timing there is a "temporary leak" that repairs itself once the analyzer finishes (some time after the editing stops). What happens is that old contexts are saved in the `declarationsTracker` but eventually cleared in the `afterContextsCreated` call. In a test on Windows (on Linux I'd currently run into https://dartbug.com/52703) I opened the entire "pkg" folder and edited a `pubspec.yaml` file every 5 seconds. The analyzer went from using something along the lines of 700MB of heap to using around 2.5 GB of heap after 25 edits and 17GB (!) of heap shortly before stopping at 250 `pubspec.yaml` edits. After the editing stopped (and clicking the GC button in observatory) the heap usage went down to ~650MB heap used. This fixes the problem by clearing the `declarationsTracker` on the `afterContextsDestroyed` call too. In the same test it stays at around 300-700MB of heap. Possibly related to: #48788 #52447 Change-Id: Ia38cc946a1f36fa8c5b6804f79cbc8dd96c21030 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309722 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent a2c10f4 commit 5e08794

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pkg/analysis_server/lib/src/analysis_server.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ abstract class AnalysisServer {
325325
addContextsToDeclarationsTracker();
326326
}
327327

328+
void afterContextsDestroyed() {
329+
declarationsTracker?.discardContexts();
330+
}
331+
328332
/// Broadcast a request built from the given [params] to all of the plugins
329333
/// that are currently associated with the context root from the given
330334
/// [driver]. Return a list containing futures that will complete when each of
@@ -762,6 +766,7 @@ abstract class CommonServerContextManagerCallbacks
762766
void afterContextsDestroyed() {
763767
flushResults(filesToFlush.toList());
764768
filesToFlush.clear();
769+
analysisServer.afterContextsDestroyed();
765770
}
766771

767772
@override

0 commit comments

Comments
 (0)