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

Dart stays 99% cpu all the time #2219

Closed
nkoroste opened this issue Jan 14, 2020 · 27 comments
Closed

Dart stays 99% cpu all the time #2219

nkoroste opened this issue Jan 14, 2020 · 27 comments
Labels
upstream in dart / flutter Needs changing in Dart or Flutter upstream in vs code / lsp / dap Needs changing in VS Code, LSP or DAP protocols/libraries

Comments

@nkoroste
Copy link

Similar to #1114

image

1155 ?? 19:30.39 /Users/n.korostelev/flutter/flutter/bin/cache/dart-sdk/bin/dart /Users/n.korostelev/flutter/flutter/bin/cache/dart-sdk/bin/snapshots/analysis_server.dart.snapshot --client-id=Dart-Code.dart-code --client-version=3.7.1

Pretty sure it because VSCode is open. However, I don't even have an open flutter/dart project but the extension is installed

@DanTup
Copy link
Member

DanTup commented Jan 15, 2020

The Dart/Flutter extensions should not activate in VS Code unless you open a Flutter/Dart project (or unless you have just installed them - VS Code will eagerly activate them at install time). If you can reproduce this (closing VS Code, terminate any Dart process, then re-open VS Code without opening a Dart project) let me know and we can examine the logs to find the extension activation reason.

Can you run code --status from a terminal when it's using high CPU (note: leave it a minute or two after opening a project just to make sure it's not from the initial analysis) and post the output here? Thanks!

@DanTup DanTup added the awaiting info Requires more information from the customer to progress label Jan 15, 2020
@ww7
Copy link

ww7 commented Jan 15, 2020

I have issue when I open whole Home directory (for bash env edits), where in some subdirectories have some dart/flutter projects. After VSCode quitting I found zombie dart process what consume some 99%.
Every VSCode open/quit leave dart zombie.

@DanTup
Copy link
Member

DanTup commented Jan 16, 2020

I have issue when I open whole Home directory

If you open your home directory, then the Dart analyzer is going to try and analyze your entire home directory. If this is very large , it could take a long time. If you have symlinks that cause loops, then it may get stuck analyzing forever.

I don't know if there's a great solution to this besides only opening the files you need to edit from the home directory directly.

@ww7
Copy link

ww7 commented Jan 17, 2020

I don't know if there's a great solution to this besides only opening the files you need to edit from the home directory directly.

Sure, I know. Better way is use workspace with disabled extension, also good to use
a excluding folders with files.exclude, files.watcherExclude, search.exclude and dart.analysisExcludedFolders.

@DanTup
Copy link
Member

DanTup commented Jan 21, 2020

Yeah, those are options too.

@nkoroste are you still seeing this issue? Can you get the output of code --status when it's happening?

@nkoroste
Copy link
Author

--status flag is not found for me but I got process explorer from the gui:

CPU %	Memory (MB)	pid	Name
3	98	10123	code main
0	66	10125	     gpu-process
0	197	10129	     window (BUCK — Foo)
0	98	10173	         extensionHost
80	328	10304	             /Users/n.korostelev/.vscode/extensions/ms-python.python-2020.1.58038/languageServer.0.5.30/Microsoft.Python.LanguageServer
95	328	10328	             /Users/n.korostelev/flutter/flutter/bin/cache/dart-sdk/bin/dart /Users/n.korostelev/flutter/flutter/bin/cache/dart-sdk/bin/snapshots/analysis_server.dart.snapshot --client-id=Dart-Code.dart-code --client-version=3.7.1
0	33	10812	             /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Renderer).app/Contents/MacOS/Code Helper (Renderer) /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json-language-features/server/dist/jsonServerMain --node-ipc --clientProcessId=10173
0	590	11236	             /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/bin/java -Declipse.application=org.eclipse.jdt.ls.core.id1 -Dosgi.bundles.defaultStartLevel=4 -Declipse.product=org.eclipse.jdt.ls.core.product -Dfile.encoding=utf8 -noverify -Xmx1G -XX:+UseG1GC -XX:+UseStringDeduplication -jar /Users/n.korostelev/.vscode/extensions/redhat.java-0.55.1/server/plugins/org.eclipse.equinox.launcher_1.5.600.v20191014-2022.jar -configuration /Users/n.korostelev/.vscode/extensions/redhat.java-0.55.1/server/config_mac -data /Users/n.korostelev/Library/Application Support/Code/User/workspaceStorage/8b9be4925cbfc93208f39a55bc528ffa/redhat.java/jdt_ws
0	1180	13347	                 /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/bin/java -XX:+UseG1GC -Xmx9g -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp /Users/n.korostelev/.gradle/wrapper/dists/gradle-5.5-all/byeise1led9a3w3p149d02kfj/gradle-5.5/lib/gradle-launcher-5.5.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 5.5
0	66	10174	         watcherService
0	295	10202	         searchService
0	66	10201	     shared-process
0	98	24708	     window (Process Explorer)
0	0	25044	     /bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command=

@DanTup
Copy link
Member

DanTup commented Jan 29, 2020

code --status includes some extra info about the workspace. I'm not sure why the flag doesn't work for you though:

PS C:\Users\danny> code --status

Version:          Code 1.41.1 (26076a4de974ead31f97692a0d32f90d735645c0, 2019-12-18T14:58:56.166Z)
OS Version:       Windows_NT x64 10.0.18363
CPUs:             Intel(R) Core(TM) i5-4430 CPU @ 3.00GHz (4 x 2999)
Memory (System):  15.93GB (11.61GB free)
VM:               0%
Screen Reader:    no
Process Argv:
GPU Status:       2d_canvas:                     enabled
                  flash_3d:                      enabled
                  flash_stage3d:                 enabled
                  flash_stage3d_baseline:        enabled
                  gpu_compositing:               enabled
                  metal:                         disabled_off
                  multiple_raster_threads:       enabled_on
                  oop_rasterization:             disabled_off
                  protected_video_decode:        unavailable_off
                  rasterization:                 enabled
                  skia_renderer:                 disabled_off
                  surface_control:               disabled_off
                  surface_synchronization:       enabled_on
                  video_decode:                  enabled
                  viz_display_compositor:        enabled_on
                  viz_hit_test_surface_layer:    disabled_off
                  webgl:                         enabled
                  webgl2:                        enabled

CPU %   Mem MB     PID  Process
    0       76    2252  code main
    0      213    3144     window (CHANGELOG.md - webdev - Visual Studio Code)
    1      203     320       extensionHost
    0        4    7748         C:\WINDOWS\system32\cmd.exe /d /s /c ""N:\Apps\Dart\v2.7.0\bin\dart.exe" "N:\Apps\Dart\v2.7.0\bin\snapshots\analysis_server.dart.snapshot" "--client-id=Dart-Code.dart-code" "--client-version=3.7.1""
   10      169    4028           "N:\Apps\Dart\v2.7.0\bin\dart.exe"  "N:\Apps\Dart\v2.7.0\bin\snapshots\analysis_server.dart.snapshot" "--client-id=Dart-Code.dart-code" "--client-version=3.7.1"
    0       11    8492           console-window-host (Windows internal process)
    0       11    3688       watcherService
    0       11    4900         console-window-host (Windows internal process)
    0       37    6504       searchService
    3       89    7008     gpu-process
    0       14    9556     electron-crash-reporter
    0       85   11936     shared-process

Workspace Stats:
|  Window (CHANGELOG.md - webdev - Visual Studio Code)
|    Folder (webdev): 296 files
|      File types: dart(131) dart2(18) yaml(15) md(9) json(8) packages(6)
|                  lock(6) html(5) sh(3) js(2)
|      Conf files:

Can you confirm how big the folder you have open is? It looks like the Python language server is also consuming significant CPU - is it a big tree?

@nkoroste
Copy link
Author

nkoroste commented Feb 5, 2020

code --status does not work for me and I'm not sure why. Yes it is a big tree but it doesn't contain any .dart at all. We do have some python though but mainly Java/Kotlin.

@DanTup
Copy link
Member

DanTup commented Feb 6, 2020

If there's no Dart at all, then the extension should not be activating. If it's a large workspace, you could be hitting microsoft/vscode#73656 where VS Code automatically activates unrelated extensions (that use workspaceContains) if it takes longer than 7 seconds to scan your workspace. I don't think there's any great way an extension can fix this - if we scan your whole workspace we're just re-doing the work VS Code was trying to avoid. I think it needs a better fix from VS Code.

To confirm this, you could run Developer: Show Logs and select Extension Host and look for a line like this:

[2020-02-06 10:45:14.457] [exthost] [info] ExtensionService#_doActivateExtension Dart-Code.dart-code {"startup":true,"extensionId":{"value":"Dart-Code.dart-code","_lower":"dart-code.dart-code"},"activationEvent":"workspaceContains:/pubspec.yaml,/*.dart"}

the activationEvent is the interesting part, which should explain why the extension activated.

@nkoroste
Copy link
Author

[2020-02-09 18:27:58.326] [exthost] [info] ExtensionService#_doActivateExtension Dart-Code.dart-code {"startup":true,"extensionId":{"value":"Dart-Code.dart-code","_lower":"dart-code.dart-code"},"activationEvent":"workspaceContainsTimeout:**/pubspec.yaml,**/*.dart"}

@DanTup
Copy link
Member

DanTup commented Feb 10, 2020

"activationEvent":"workspaceContainsTimeout:

Yep, this looks like microsoft/vscode#73656. The issue is that you're opening a large workspace and VS Code is unable to check whether it contains any Dart/pubspec before timing out (7 seconds), so it pre-emptively activates all of the extensions that might be needed. This results in language servers being started, which then also scan the whole workspace (because they think the workspace contains their language).

I don't know of a good fix - VS Code's timeout seems counter-productive IMO - it's designed to improve performance, but seems to make it worse. While we could scan the workspace ourselves before spawning the language server, this is doing exactly the work VS Code was trying to avoid (and doing it a second time, so it'll take 7 seconds longer overall than if VS Code had finished it).

I would recommend adding a 👍 and/or comment to that issue - so far it's not had much activity.

@DanTup DanTup added blocked on vs code / lsp / dap Requires a change in VS Code to progress and removed awaiting info Requires more information from the customer to progress labels Feb 10, 2020
@MarcusTomlinson
Copy link
Contributor

MarcusTomlinson commented Jun 18, 2020

I'm seeing the issue of multiple dart zombie processes on Linux, but for me it's when builds fail (in my case, the error being 'unable to generate build files') that it leaves the dart processes behind.

After 5 failed build attempts:

Screenshot 2020-06-18 at 16 04 12

@DanTup
Copy link
Member

DanTup commented Jun 18, 2020

@MarcusTomlinson I don't think that's the same issue as this, those all have 0% CPU. Could you file another issue, and include the full command line for the processes are being left behind? Thanks!

@Arkey-zeng
Copy link

So do i (我也一样)
20201021150819

@DanTup
Copy link
Member

DanTup commented Oct 21, 2020

I think there may be two issues here:

  1. VS Code is activating the Dart extension when there are no Dart files. That's Improve handling of extensions when workspaceContains times out microsoft/vscode#73656 and I don't think we can do much to fix it in the extension.

  2. Analysis server is consuming CPU forever

I don't know that 2 is an issue - but I'm guessing it may be from these reports. If someone can reliably reproduce the CPU remaining high after many minutes (and they have not opened a huge folder, like their entire user profile) then I'd be interested in an analysis server instrumentation log (note: this log may include parts of your source files!).

@SteveAlexander
Copy link

@DanTup I believe 2 is an issue for me.

The analysis log file gets huge pretty fast (multi GB) and as you point out may contain confidential information. How can I get such a log file to you without making it public?

@SteveAlexander
Copy link

Also, I posted the relevant part of the log file here, along with the code that seems to be triggering the problem:

dart-lang/sdk#43765

@DanTup
Copy link
Member

DanTup commented Oct 21, 2020

@SteveAlexander you probably don't need to send the whole thing - if it's stuck in a loop or something (which I suspect it could be), it might be obvious from just the last few tends/hundreds of lines. You can email to me at logs@dartcode.org (but still ensure there's nothing confidential in there) - though I think it has around a 25MB limit (shouldn't need more than that from the end though - but the first hundred lines or so may also be useful as it has startup stuff).

One thing that has caused issues like this in the past is circular symlinks (which has resulted in the server walking down the tree forever). I'm not sure if that's handled correctly yet.

@DanTup
Copy link
Member

DanTup commented Oct 21, 2020

@SteveAlexander ah yes, I remember that. That does look pretty suspicious to me. It seems like something is being duplicated a lot (whether it's in a loop, or just growing very large, I'm not sure - though that it was able to start writing the JSN makes me think it must just be large).

I don't know if it's the same issue as this original case (I think your problem could be triggered by the codegen or something?), but if you're able to strip your project down to something you can share (on that issue), I can try to reproduce here where I could step through the server code or add more logging.

@DanTup
Copy link
Member

DanTup commented Oct 27, 2020

I think there have been a few issues discussed here, but I think they're all now covered by other issues:

VS Code activating the Dart extension without a Dart project open was a regression in vS Code that's fixed for the next version (with the fix available in Insiders now).

The high CPU issue and huge log files has been raised in the SDK repo at dart-lang/sdk#43765.

To avoid confusion, I'm going to close this one - but if you're having an problem other than these, please file separate issues for them. Thanks!

@DanTup DanTup added upstream in dart / flutter Needs changing in Dart or Flutter and removed blocked on vs code / lsp / dap Requires a change in VS Code to progress labels Oct 27, 2020
@DanTup DanTup added the upstream in vs code / lsp / dap Needs changing in VS Code, LSP or DAP protocols/libraries label Oct 27, 2020
@DanTup DanTup removed this from the v3.16.0 milestone Oct 27, 2020
@DanTup DanTup closed this as completed Oct 27, 2020
@mahmoudatef955
Copy link

dart.analysisExcludedFolders

How could i do that?

@DanTup
Copy link
Member

DanTup commented Feb 2, 2022

@mahmoudatef955 it's in the VS Code settings:

Screenshot 2022-02-02 at 10 46 45

@mahmoudatef955
Copy link

mahmoudatef955 commented Feb 2, 2022 via email

@DanTup
Copy link
Member

DanTup commented Feb 2, 2022

I'm afraid I'm not familiar with IntelliJ, although I would suggest trying to use the exclude: option in analysis_options.yaml:

https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis

@mahmoudatef955
Copy link

mahmoudatef955 commented Feb 2, 2022 via email

@DanTup
Copy link
Member

DanTup commented Feb 2, 2022

I don't, but things I'd try:

  • ensure you're on the last version of the Flutter SDK
  • ensure you have the latest version of the Dart/Flutter plugins for IntelliJ
  • check if it happens with a branch new Flutter project, or only with this specific project

If it only happens with one specific project and not the new one, you should try to find what's different between the two that might be triggering it (or, get the problematic project into a state where you can zip it up and share it).

Assuming it's the Dart Analysis Server using up all the CPU, the best repo to file the issue is https://github.com/dart-lang/sdk.

@mahmoudatef955
Copy link

mahmoudatef955 commented Feb 2, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream in dart / flutter Needs changing in Dart or Flutter upstream in vs code / lsp / dap Needs changing in VS Code, LSP or DAP protocols/libraries
Projects
None yet
Development

No branches or pull requests

7 participants