Skip to content

Commit

Permalink
[analyzer] Plug "temporary leak" when starting new rebuilds before `a…
Browse files Browse the repository at this point in the history
…fterContextsCreated` 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]>
  • Loading branch information
jensjoha authored and Commit Queue committed Jun 16, 2023
1 parent a2c10f4 commit 5e08794
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/analysis_server/lib/src/analysis_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ abstract class AnalysisServer {
addContextsToDeclarationsTracker();
}

void afterContextsDestroyed() {
declarationsTracker?.discardContexts();
}

/// Broadcast a request built from the given [params] to all of the plugins
/// that are currently associated with the context root from the given
/// [driver]. Return a list containing futures that will complete when each of
Expand Down Expand Up @@ -762,6 +766,7 @@ abstract class CommonServerContextManagerCallbacks
void afterContextsDestroyed() {
flushResults(filesToFlush.toList());
filesToFlush.clear();
analysisServer.afterContextsDestroyed();
}

@override
Expand Down

0 comments on commit 5e08794

Please sign in to comment.