Dart-code: Plugin uses a healthy amount of CPU

Created on 28 May 2019  路  18Comments  路  Source: Dart-Code/Dart-Code

So I'm using Android Studio on a laptop, and my fans are basically running all day, due to high CPU load. Checking Activity Monitor in MacOS, Android Studio averages from 50% - 100% (on one core), constantly, unless left alone for a while, then it settles. Restarting Android Studio doesn't seem to fix the problem.

This is in a Flutter project, in case that is relevant.

All 18 comments

@larssn This repo is for the VS Code plugin but you mention Android Studio :)

Did you mean VS Code, or did you raise this in the wrong place?

Apologies, thought this repo covered both.

No worries! I think https://github.com/flutter/flutter-intellij is the right place for Android Studio (assuming it's a Flutter/Dart issue and not the general IDE). @pq

Thanks Dan, I'll post it there.

I'll probably create one here too as well, seeing as I switched away from VSCode due to performance issues. But my time is limited atm.

Yeah, definitely open issues if you had problems. There are some known perf issues right now (for ex. a memory leak in VS Code means after a few hours the editor might crawl and then the extension host crash), but I'd love to know more about the issues you saw (and if you can easily repro them, I'm sure we can get to the bottom of them).

I definitely saw a memory leak, among other things. The main problem I had was intellisense slowly becoming more and more unresponsive, impacting my productivity. I think it was CPU related, but it might have been the CPU being overloaded due to too little memory, and thus excessive memory compression.

I'll post when I have some time.

@larssn was it within the last month or so? We only trigger the leak since 2.26 (released 2019-04-26) and it would cause the editor to come to a crawl (high memory, and more frequent GC). We were also not handling handled requests as well as we could, so doing more work if you were causing lots of cancelled completions (though I think in normal use this wouldn't happen).

The leak I found was fixed in VS Code today (https://github.com/microsoft/vscode/issues/74446) so should be in Insiders tomorrow and in the release in 1-2 weeks. The cancellation handling is in the beta for the next plugin release.

I'd be interested to know if you still see any issues when you have both those fixes.

It's been going on since our company started with Flutter (and Dart), which was this February.
I made a casual mention about it here, https://github.com/Dart-Code/Dart-Code/issues/1285#issuecomment-488378850

In any case, I'll wait a few weeks and see if the VSCode update fixes it. I'll let you know if it doesn't.

Interestingly, that comment came soon after the release that would've started triggering the leak (and code helper is where you'd have seen it). I can't tell what was happening before that though, but if you do get time to try it out in a few weeks, I'd definitely love to know if you're hitting issues. Even if you don't want to switch back to VS Code, it's unlikely it's a bug that would only affect you, so I appreciate any info you can give to help me track it down 馃憤

Will do.

In the mean time, if you have access to any low memory environments like mine (4GB), you could try and see if you have any problems. I'll buy a better computer in the future, I promise.

if you have access to any low memory environments like mine (4GB)

With VS Code Remote I should be able to trivially run the backend in a container with a stingy amount of memory, though it would only be backend, and I suspect electron and co are probably eating up a good portion of yours.

That said, Android Studio probably isn't particularly lean, so if that works with Flutter I think VS Code should work. For the recent issues my money is on the leak though, so it might be best to re-test once that's out and then if we see issues we can at least gather some meaningful data.

I presume you don't want to mess around with Insiders, but I'll ping you here when the leak fix is out in VS Code stable (and the cancellation fixes in Dart-Code) in case you're interested in giving it a test.

Yeah I prefer stable versions. So yeah, I'd appreciate a ping. 馃憤

@larssn VS Code 1.35 released end of last week and fixes the memory leak we were seeing in the code completion. If you feel like trying it out again, I'd be interested to know if you still see issues (and if you do, if you can get some info on the CPU/memory usage of the offending processes - including the output of code --status) - when it happens.

Thanks Dan, I'll definitely give it a look.

Rarely have a seen such a big change in performance: Memory stays at a stable level, and the CPU load is much lower! 馃憤

Running in debug mode is still a bit tough on the CPU, but so is Android Studio.

I've switched back to VS Code because of this, thanks!

Glad to hear it made a notable difference! Can you check what process(es) are using the CPU when debugging? It might be something I can't affect (for example emulators/simulators), but if it's VS Code or the extension host (or any Dart process) it may be worth some investigation.

Now that I've used it a few days, I can supply a bit more detail.

  • Intellisense is still somewhat slow to react when I need it (3-5 seconds at times), but I recall hearing something about that being VSCode's fault, in general. Currently it's the only thing I miss from Android Studio.
  • There might still be a few memory leaks, but they seem to be minor. Before my memory would rocket to 1.8GB for a Code Helper after 20 minutes, while now I can go most of the day without restarting VS Code.
  • CPU load is much lower - my fans run more infrequently now.

I'm not using any emulators, only physical devices. How would you prefer that I investigate, and how?

If you're on the latest VS Code, then I don't think there are any outstanding issues there, so this is on us.

A few things that would be useful when you see this:

  1. Output of running code --status (this will show the memory/CPU of the extension host and sub-processes)
  2. A log from the extension that includes the request/response for code completion to the server

    • Run Dart: Capture Logs

    • Tick only the Analysis Server option

    • Invoke code completion, wait for it to complete

    • (maybe repeat a few times with a few second pause in between so we get a few timings)

    • Click Stop Logging

  3. A CPU profile when this happens

    • Run the Show Running Extensions command

    • Right-click Dart and click Start Extension Host Profile

    • Invoke completion and wait for it to complete

    • (maybe repeat a few times with a few second pause in between)

    • Switch back to the running extensions list

    • Right-click on Dart and go to Stop Extension Host Profile

    • Right click on Dart and click Save Extension Host Profile

If you attach those three things to a new issue, I'll take a look. Thanks!

Was this page helpful?
0 / 5 - 0 ratings