dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.09k stars 1.56k forks source link

`dart:analysis_server` takes 19GB memory #52447

Closed fzyzcjy closed 10 months ago

fzyzcjy commented 1 year ago

Well, I have reported here https://github.com/dart-lang/sdk/issues/41793#issuecomment-1554378872, but I am not sure whether it is more reasonable to create a new issue, since the memory size is really really a lot IMHO. The original issue complains when it takes <2GB, while here it is nearly 20GB!

image

srawlins commented 10 months ago

@fzyzcjy I'm going to close this issue as a few folks on the Dart team have landed many memory improvements in the Analyzer code bases over the last year, and even over the last six months (see below). I won't promise that your memory problems are solved, but I think at this point, it would be most effective to sort of rebase the discussion.

Anyone else experiencing similar "giant memory usage" issues with the Dart Analyzer, and you'd like to document a bit your situation, also please follow these instructions:

First, be sure to bump to the latest Dart, 3.2.0, as it has some performance improvements over 3.1.0. Then, if you experience what you feel is an inordinate amount of memory being used (we don't have any SLOs yet in this space, but anything north of 5GB is probably noteworthy):

  1. We have a public document with instructions how to setup auto-snapshotting for analyzer in case of huge memory usage: https://docs.google.com/document/d/1mxCKhvyHUtGVhIH5Apx9y7V7itqCxAQPse6ghbjaDMM
  2. You can file an issue in this repo and send us some other basic info:
    • How many .dart files are under the analysis root for the IDE?
    • In the Diagnostics pages, you may want to look at Memory, Plugins, how many Analysis Contexts exist, etc.
    • How long has the process been running? If you restart your IDE or and/or DAS, does it use less memory? What about hours later? What about days later?

Recent memory-reducing changes:

Dart ~ 2.19.0, Jan 2023

Dart ~3.0.0, May 2023

Dart ~3.1.0, August 2023

Dart ~3.2.0, November 2023

(There were also speed-up improvements made in this time frame, and improvements to our analytics, logging, benchmarking, and platform coverage, but I'm not documenting those here on this memory-focused issue.)

fzyzcjy commented 10 months ago

Thank you and the Dart team for improving this! I will try Dart 3.2 later and report if anything goes wrong.

RichardGreat commented 5 months ago

I faced the same problem in flutter 3.7.12 but upgrading flutter version was not a option because I have a huge code base with 3-4 big modules which I have to migrate all my modules to dart null safety, I found the solution which worked on me the problem was in example project of an each module, which created I cyclic dependency source analyzing : module -> example -> dependency -> module -> example ... etc. and I reviewed my module examples and remove module dependency from pubspec.yaml file and now it helped and now it takes at most 1GB in ram

polina-c commented 5 months ago

For those who still experience this, you can enable auto memory snapshotting for analyzer.

Do not worry, it will not fill all you hard drive with snapshots, it will stop at the configured limit.

Here is the steps how to configure your IDE to turn on analyzer autosnapshotting: https://docs.google.com/document/d/1mxCKhvyHUtGVhIH5Apx9y7V7itqCxAQPse6ghbjaDMM/edit

Then, with DevTools starting flutter 3.22.0-1.0.pre.10 or fresher (you do not have to migrate your project, just switch to flutter master to get DevTools) you can import and diff the collected snapshots. Or, if the snapshots do not contain sensitive information, just share them here so that analyzer team can check them.