-
Notifications
You must be signed in to change notification settings - Fork 27.9k
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
[desktop] High memory consumption [Part 2] #95092
Comments
@ivk1800 we have an open issue in Dart Code Metrics repo and right now it looks like the problem is with the plugin, not the integration. But I'd really appreciate some help from the Dart team, just to be sure that the integration is solid and doesn't have memory leaks. |
After some investigation with different plugin setups I'm not that sure that it's our code leaking. Definitely need some help with checking the integration memory consumption. |
I tried the given zip and followed steps to replicate on latest master and stable on mac and can see CPU and memory consumed by dart, as below: stable, master flutter doctor -v
|
/cc @mraleph |
AFAIK plugins run in isolates so I would not be surprised that memory jumps considerably when you load additional analyser plugins. AST representation is likely duplicated between main analyser isolate and each plugin. @bwilkerson @scheglov should know how to diagnose this further. |
Looking into individual
|
Not sure whether it matters, but plugins are allowed to also contribute to code completions. |
It probably does not matter for plugins. We have to keep element models to ensure that element instances are mostly the same, so we can use |
Just clearing the libraries contexts does not help at all. We still have references to these elements via cached results for "priority" files. But I don't think this is a recent change in the analyzer. If the plugin always used to configure We cache resolved units for priority files because a priority file is a file that the user has open in the IDE. So, as he moves the caret in the file, we want to produce Quick Assists, and don't want to resolve file each time. It is not obvious to me that plugins need such caching. |
Probably the most common use cases for plugins are to provide custom lints and custom fixes. It would be better if the plugin didn't need to re-resolve the priority file when the user clicks in a highlighted error range to get quick fixes. |
If the plugin does provide quick fixes - yes. But if only diagnostics - no. Disabling caching priority files in plugins makes it somewhat better, but not totally. We still use a lot of heap, but most of it is garbage. It is unfortunate that VM continues to hold most of this heap. |
@scheglov first of all, thank you so much for the investigation!
Could you please share how to achieve this with the current API? Right now we use Another question - is it possible to share the
I don't know, if it's related or not, but right now we need to use hacks in order to highlight the errors we send to the analyzer in opened files. It was copied from another plugin. Maybe there is a better way to do it? |
@scheglov For what it's worth. I noticed the high memory consumption early this year. It's not something new to a recent release. |
I don't have great understanding of plugins and the APIs that they should be based on. I will leave it to @bwilkerson regarding plugins API. I just want to note that once you step inside the non-API territory with As for which implementation of Nothing of this is API of course. My understanding of why you need these hacks is that when a file (that was If we stay in a plugin, a more direct way to achieve this is to a callback to |
Unfortunately, we use implementation imports just because there is no other way to create a driver without them. We'd be really happy to use public API instead, but I got your point, I think we can at least give it a try in order to resolve current performance issue.
Thank you, do we need to define it outside of
But why? Are you not interested in investing into plugins API or it's just so low on the priority list and you don't have time for it? I mean, I understand that it's barely used right now, but the potential of custom lint rules for a specific team requirements is underestimated right now.
You mean, why the functionality that the package provides is not added to the linter package directly, instead of a separate package with custom lint rules? |
I meant if you're able to run the plugin from source, could you add something like I haven't tested it, but it might be possible to attach a debugger by running the analysis server with the VM Service enabled (using VS Code's |
Funny, but creating files worked 😄 . Never tried this before. Okay, I see the problem: path from analyzeFile: /Users/dimannich/Desktop/code/master-dart-code-metrics/lib/src/analyzer_plugin/analyzer_plugin.dart path from analyzeFile: /Users/dimannich/Desktop/code/master-dart-code-metrics/lib/src/analyzer_plugin/analyzer_plugin.dart So, it seems to me that it's like one file is being analyzed by 2 contexts and the second one overrides the result of the first analysis. I'd say that behaviour is unexpected and looks like the analysis context from tools/analyzer_plugin should not be used to analyze files not in the tools/analyzer_plugin. |
And I still get the plugin removed by the analysis server after some time... 😞 |
Could be dart-lang/sdk#49404 |
Actually, yeah, looks like it, thanks! Any ideas why the plugin might be removed after few minutes? We also faced a problem with the files not being analysed when they are not open, but we're collecting more info on that. |
@DanTup thank you for the help! |
Not really, maybe https://github.com/dart-lang/sdk/blob/f6aaa72e58b0d11d4ae9d84037bbacc17807e7d5/pkg/analysis_server/lib/src/plugin/plugin_manager.dart#L881 Maybe @bwilkerson can remember when else plugins might be unloaded. Maybe you could hack the plugin (right in the pub cache), and write into a file all notifications that are sent to the server. This way you could see which exception happens. |
Also received reports about flickering, now the plugin is not removed, but flickers or after some time just shows no errors. Another problem that people started to report the issues from the newer package version when they haven't yet updated. Like they have DCM 4.17.0, but IDE somehow reports an issue from 4.18.0. I'm not sure, if it's even possible, but it's already two reports. |
@incendial just ran into this same issue in a private custom-lint plugin that was also built with What we were observing: When We fixed it by changing our return MemoryCachingByteStore(
FileByteStore(
stateLocation.path,
tempNameSuffix: DateTime.now().millisecondsSinceEpoch.toString(),
),
memoryCacheSize,
); Now what we're seeing is that initial analysis after opening the IDE still adds about 4-5GB to the memory utilization of the |
This issue is marked P1 but has had no recent status updates. The P1 label indicates high-priority issues that are at the top of the work list. This is the highest priority level a bug can have if it isn't affecting a top-tier customer or breaking the build. Bugs marked P1 are generally actively being worked on unless the assignee is dealing with a P0 bug (or another P1 bug). Issues at this level should be resolved in a matter of months and should have monthly updates on GitHub. Please consider where this bug really falls in our current priorities, and label it or assign it accordingly. This allows people to have a clearer picture of what work is actually planned. Thanks! |
//cc @srawlins |
I believe we can close this. This thread does not represent a single P1 issue. There is not a clear exit state. Much of the changes have been made to one Dart analyzer plugin. We've mitigated issues that arise from multiple Dart analyzer plugins by limiting to one. We're working on a new plugin API. I just don't think there is much to track here. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
continue of #90868
in multi modules project consumes too much memory. project contains 40 modules with included
dart_code_metrics
. I attach test project for reproduce.Steps fo reproduce:
dart_code_metrics: 4.8.1
Dart version 2.15.0, macOS 11.5.2 20G95 darwin-x64
HighMemoryConsumption.zip
memory.mov
The text was updated successfully, but these errors were encountered: