Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When/why does VM heap decrease? #51126

Closed
jensjoha opened this issue Jan 25, 2023 · 11 comments
Closed

When/why does VM heap decrease? #51126

jensjoha opened this issue Jan 25, 2023 · 11 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. vm-gc Related to the VM's garbage collector

Comments

@jensjoha
Copy link
Contributor

I'm playing around with the analyzers memory usage.

Via #41793 (comment) I found and checked out https://github.com/kodecocodes/rwf-materials.git and opened the entire directory (after running flutter pub get 500+ times --- I don't know if there's a helper command but that's what I did anyway).

With an empty cache the memory usage goes to (on my machine) ~14GB.

Now comes a hack: I've found that creating a file and deleting it again makes the analyzer clear some (unneeded) cache stuff (and do all kinds of stuff again, but still) --- once it's done the memory usage is now ~11GB, but the used heap is in the ~3.5GB range. Doing the same thing again makes the memory usage go to ~9GB and the heap usage is still in the ~3.5GB range (e.g. it's displayed as heap 3.49GB of 9.13GB in Observatory).

So: Why doesn't the VM reduce the heap size further? Is there something else that has to be satisfied for it to reduce the heap or something?

/cc @mkustermann @mraleph

@mkustermann
Copy link
Member

Generally old space is organized in pages, so if there's at least one object on a page, the whole heap page is retained. So a partial reason may be fragmentation. Though if the analyzer is ever idle, it may trigger compacting GC, which can get rid of this fragmentation.

/cc @rmacnak-google

@vsmenon vsmenon added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label Jan 25, 2023
@rmacnak-google rmacnak-google added the vm-gc Related to the VM's garbage collector label Jan 25, 2023
@rmacnak-google
Copy link
Contributor

@jensjoha What command are you using to run the analyzer?

@jensjoha
Copy link
Contributor Author

I'm opening the directory with Android Studio (and enabling dart support for the dir).

@rmacnak-google
Copy link
Contributor

How are you getting to Observatory? I can see some analyzer-specific diagnostic page, but it claims the VM service is not running, and sending the usual sigquit to the pid doesn't enable the VM service. I also don't see anywhere to set flags passed to the analyzer invocation.

@rmacnak-google
Copy link
Contributor

I suspect what is happening is that the heap size is so large that the VM estimates it will taking longer than --idle_duration_micros to complete a compaction, and so chooses mark-sweep instead of mark-compact to avoid blocking for too long.

@jensjoha
Copy link
Contributor Author

I'm cheating...
I'm applying this patch:

diff --git a/pkg/analysis_server/lib/src/status/diagnostics.dart b/pkg/analysis_server/lib/src/status/diagnostics.dart
index 82aa23c37cd..6558597e9e4 100644
--- a/pkg/analysis_server/lib/src/status/diagnostics.dart
+++ b/pkg/analysis_server/lib/src/status/diagnostics.dart
@@ -460,10 +460,10 @@ class CollectReportPage extends DiagnosticPage {
       }
     }
 
-    if (startedServiceProtocol) {
-      await developer.Service.controlWebServer(
-          enable: false, silenceOutput: true);
-    }
 
     const JsonEncoder encoder = JsonEncoder.withIndent('  ');
     return encoder.convert(collectedData);

opening the "Analysis Server Diagnostics" via Android Studio -> "Dart Analysis" bottom page thing -> wheel on the left -> "View Analyzer Diagnostics" -> Clicking "Collect Report" and "Download report". Then from "Diagnostics" -> "Memory and CPU Usage" I can see the URL for Observatory.

@mraleph
Copy link
Member

mraleph commented Jan 27, 2023

I suspect what is happening is that the heap size is so large that the VM estimates it will taking longer than --idle_duration_micros to complete a compaction, and so chooses mark-sweep instead of mark-compact to avoid blocking for too long.

I guess this might be one of those huge-heap use cases where compacting gradually via selective/partial evacuation of pages is better than our current full sliding compaction which is tiered towards smaller heaps.

@mraleph
Copy link
Member

mraleph commented Feb 9, 2023

@rmacnak-google did you have any chance to look at this? it would be nice to find out why VM does not shrink the heap more aggressively.

@rmacnak-google
Copy link
Contributor

It was the estimated time exceeding the deadline. See 2b8ca6f (I linked the wrong issue).

@mraleph
Copy link
Member

mraleph commented Feb 9, 2023

@rmacnak-google thanks! I suspected it was related.

@jensjoha when you have some free time could you check how things look on master now wrt to analyzer heap? Maybe we can close this issue then.

@jensjoha
Copy link
Contributor Author

It's now at ~3GB so seems fixed to me :).
Closing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. vm-gc Related to the VM's garbage collector
Projects
None yet
Development

No branches or pull requests

5 participants