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 Analyzer very slow/stuck #55281

Open
JonasJW opened this issue Mar 22, 2024 · 41 comments
Open

Dart Analyzer very slow/stuck #55281

JonasJW opened this issue Mar 22, 2024 · 41 comments
Labels
analyzer-stability area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-performance Issue relates to performance or code size

Comments

@JonasJW
Copy link

JonasJW commented Mar 22, 2024

Dart & Flutter has suddenly become unusable slow in VSCode. Intellisense won't load within 30+ seconds, syntax highlighting won't update, jumping to code definitions loads infinitely, etc.

This seems to be especially the case on bigger projects, on a newly created project it works fine. I tried switching to Android Studio which seems to behave similarly (maybe a little better).

I tried uninstalling all extensions, even completely removing VSCode with any data stored and reinstalling it. As soon as I install the Dart extension, it is unusable. I also tried setting the following settings:

"dart.previewLsp": true,
"dart.useLegacyAnalyzerProtocol": true,
"dart.useLsp": false,
"dart.autoImportCompletions": false,

I'm on macOS 14.4, VSCode Version 1.87.2 (Universal),

In the Activity Monitor, there is the dart:analysis_server.dart.snapshot process running with around 1 GB of used memory. I'm not sure if this is normal.

Here is a screenshot from the Dart Analyzer (which I'm also having trouble opening)

Screenshot 2024-03-22 at 20 47 42

dart info output:

General info

  • Dart 3.3.2 (stable) (Tue Mar 19 20:44:48 2024 +0000) on "macos_arm64"
  • on macos / Version 14.4 (Build 23E214)

Project info

  • sdk constraint: '>=2.17.0 <3.0.0'

Process info

Memory CPU Elapsed time Command line
6 MB 0.0% 11:53 dart devtools --machine --allow-embedding
393 MB 100.6% 11:53 dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.85.20240318
29 MB 0.0% 11:53 flutter_tools.snapshot daemon
35 MB 0.1% 00:23 flutter_tools.snapshot debug_adapter
121 MB 10.8% 00:23 flutter_tools.snapshot run --machine --start-paused -d B95DD896-131D-4163-A83C-1AC8A70E8560 --devtools-server-address http:/ --target /main.dart --web-renderer canvaskit --web-port 5000

Any recommendations on how I could possible fix this would be very welcome!

@JonasJW JonasJW changed the title Dart Dart Analyzer very slow/stuck Mar 22, 2024
@lrhn lrhn added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Mar 24, 2024
@keertip keertip added type-performance Issue relates to performance or code size P1 A high priority bug; for example, a single project is unusable or has many test failures labels Mar 26, 2024
@keertip
Copy link
Contributor

keertip commented Mar 26, 2024

@DanTup , do you see this? Have there been more reports of this kind?

@keertip
Copy link
Contributor

keertip commented Mar 26, 2024

/ cc @bwilkerson

@DanTup
Copy link
Collaborator

DanTup commented Mar 26, 2024

I've not seen any other reports like this. 100% CPU certainly does not look healthy if it's persisting for a long period after initial analysis.

@JonasJW a few questions:

  • How big is the open workspace (code --status I think should give a summary of the number of each file type)
  • Might it contain any symlinks (that could result in analyzing more than just this folder, or even cycles?)
  • You noted that this issue started recently - are there any things that you updated around the time it started (VS Code, the VS Code extensions, the Dart/Flutter SDKs)?
  • Are you able to get a screenshot of the servers Timing page (the one you gave above was the Completion page) which will include timings for a larger set of requests

@MaximeRougieux
Copy link

We were having the same issue and using the custom_lint package (v0.5.7).

Removing it completely seems to have solved the issue for us, are you using it too, and can you try to remove it to confirm it comes from there if you are ?

@keertip
Copy link
Contributor

keertip commented Mar 27, 2024

/cc @scheglov

@keertip keertip added P2 A bug or feature request we're likely to work on and removed P1 A high priority bug; for example, a single project is unusable or has many test failures labels Mar 27, 2024
@JonasJW
Copy link
Author

JonasJW commented Mar 29, 2024

@DanTup Thanks for the response and sorry for the late reply.

code --status output:

Version:          Code 1.87.2 (863d2581ecda6849923a2118d93a088b0745d9d6, 2024-03-08T15:21:31.043Z)
OS Version:       Darwin arm64 23.4.0
CPUs:             Apple M1 Pro (8 x 24)
Memory (System):  16.00GB (0.06GB free)
Load (avg):       5, 5, 6
VM:               0%
Screen Reader:    no
Process Argv:     --crash-reporter-id 0c0cb32f-913b-418e-b987-7370929419d6
GPU Status:       2d_canvas:                              enabled
                  canvas_oop_rasterization:               enabled_on
                  direct_rendering_display_compositor:    disabled_off_ok
                  gpu_compositing:                        enabled
                  multiple_raster_threads:                enabled_on
                  opengl:                                 enabled_on
                  rasterization:                          enabled
                  raw_draw:                               disabled_off_ok
                  skia_graphite:                          disabled_off
                  video_decode:                           enabled
                  video_encode:                           enabled
                  webgl:                                  enabled
                  webgl2:                                 enabled
                  webgpu:                                 enabled

CPU %   Mem MB     PID  Process
    0      115   38907  code main
    7       66   38910     gpu-process
    0       16   38911     utility-network-service
    0       33   38923  shared-process
    0       33   82195  ptyHost
    0        0   83841       /bin/zsh -il
    0        0   90120         bash /usr/local/bin/code --status
    9       66   90129           electron-nodejs (cli.js )
    5      246   83837  window [5] (auto_router.gr.dart — exercisable_flutter)
    0       98   83839  extensionHost [5]
    0       33   83879       electron-nodejs (config.js )
    0        0   83961         /usr/bin/script -t 0 /dev/null /usr/bin/arch -arm64e xcrun xcdevice observe --usb
    0       16   83962           /Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe --usb
    0        0   83963         /usr/bin/script -t 0 /dev/null /usr/bin/arch -arm64e xcrun xcdevice observe --wifi
    0       16   83964           /Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe --wifi
    0      426   83884       /Users/jonas/Documents/flutter/bin/cache/dart-sdk/bin/dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.85.20240327
    0        0   83886       /Users/jonas/Documents/flutter/bin/cache/dart-sdk/bin/dart devtools --machine --allow-embedding
    0       33   89935       electron-nodejs (config.js )
    0       33   89961         electron-nodejs (config.js )
  170     1081   90000           electron-nodejs (config.js )
    0       33   83840  fileWatcher [5]

Workspace Stats: 
|  Window (auto_router.gr.dart — exercisable_flutter)
|    Folder (exercisable_flutter): more than 20346 files
|      File types: transitive_digest(3856) json(1582) png(1354) flat(1004)
|                  jar(976) xml(843) webp(646) ttf(344) stamp(334)
|                  len(275)
|      Conf files: launch.json(1)
|      Launch Configs: dart(13)

To be honest, I'm not quite sure what you mean by your question about symlinks or how I can find out.

Yes, this issue seems to have started just recently without making any noticeable changes such as updating SDKs, installing extensions, etc.

Here are further screenshots, I hope this is the server timing page you meant.

Screenshot 2024-03-29 at 09 58 32

Screenshot 2024-03-29 at 09 59 31

If you have any recommendations what I can try to fix this issue, I'm happy to try that. As mentioned, I have already tried uninstalling Flutter/Dart, VSCode, etc. at the moment I don't know what else I could try.

@lulupointu
Copy link

For us updating custom_lint to 0.6.4 fixed the issue 🎉

@DanTup
Copy link
Collaborator

DanTup commented Mar 29, 2024

@JonasJW thanks - the page I meant was the one marked "Timing" on the left.

Can you also confirm whether you're using any analyzer plugins? A few comments above suggest custom_lint might have have issues (that may be fixed in 0.6.4).

You should be able to check for symlinks by running find . -type l -ls in your project folder.

@JonasJW
Copy link
Author

JonasJW commented Mar 29, 2024

@DanTup thanks for the clarification!

I don't use custom_linter or any analyzer plugins.

When I run find . -type l -ls I get a long list of I suppose symlinks that probably just belong the the packages I use, for example:

111156169        0 lrwxr-xr-x    1 jonas            staff                  29 Mar  8 17:37 ./build/macos/Build/Products/Debug-platform/exercisable_flutter.app/Contents/Frameworks/FirebaseCore.framework/FirebaseCore -> Versions/Current/FirebaseCore

Is that anything out of the ordinary?

Here the screenshots of the "Timing" page:

Screenshot 2024-03-29 at 19 47 54

Screenshot 2024-03-29 at 19 48 15

@DanTup
Copy link
Collaborator

DanTup commented Apr 4, 2024

When I run find . -type l -ls I get a long list of I suppose symlinks that probably just belong the the packages I use, for example:

111156169        0 lrwxr-xr-x    1 jonas            staff                  29 Mar  8 17:37 ./build/macos/Build/Products/Debug-platform/exercisable_flutter.app/Contents/Frameworks/FirebaseCore.framework/FirebaseCore -> Versions/Current/FirebaseCore

Is that anything out of the ordinary?

That one doesn't look like a problem, but are there any that point back up the tree (eg. creating cycles or including other large parts of the disk in the the path)?

It may be useful to enable the analyzer instrumentation log (this file can get very large - be sure to turn it off afterwards) and reproduce the issue, and see if there is anything in the log file that looks out of place while this happens (for example exceptions, or paths you would not expect to be analyzed with this project open being analyzed).

You mentioned this only happens on large projects - are any of them public projects that I could test with (or that sharing logs from would not include anything sensitive)?

@JonasJW
Copy link
Author

JonasJW commented May 8, 2024

Hi @DanTup,

I apologize for taking so long to respond. I still have this issue and it's really slowing down my development process.

are there any that point back up the tree (eg. creating cycles or including other large parts of the disk in the the path)?

Here are a few symlinks, some point up but it doesn't appear to me that they would create a cycle

./windows/flutter/ephemeral/.plugin_symlinks/firebase_auth -> /Users/jonas/.pub-cache/hosted/pub.dev/firebase_auth-4.19.1/

./build/macos/Build/Intermediates.noindex/EagerLinkingTBDs/Debug/just_audio.framework/just_audio.tbd -> /Users/jonas/Documents/project_name/build/macos/Build/Intermediates.noindex/EagerLinkingTBDs/Debug/just_audio.framework/Versions/A/just_audio.tbd

./macos/Pods/Headers/Public/Firebase/Firebase.h -> ../../../Firebase/CoreOnly/Sources/Firebase.h

./ios/.symlinks/plugins/path_provider_foundation -> /Users/jonas/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.1/

./build/macos/Build/Products/Debug/FirebaseSharedSwift/FirebaseSharedSwift.framework/FirebaseSharedSwift -> Versions/Current/FirebaseSharedSwift

In total there are over 550 symlinks. Does any of this sound problematic?

I also tried the analyzer instrumentation logs but I can't really find anything that appears out of place. However, this document seems to log all kinds of stuff and I'm not sure how to analyze it or what to look for.

Yes, unfortunately, this project is private and can't be shared. I could probably share the analyzer instrumentation logs privately with you, if that would help.

I recently tested this project on a windows laptop and the issue occurs as well. (Thus, I think completely reinstalling my mac won't even help fix it).

These issues don't appear on new Flutter projects. Maybe I could try to download a big public project and see if I have problems with other bigger projects as well? If not it must be something specific with my project but I'm clueless about where the issue could be.

@DanTup
Copy link
Collaborator

DanTup commented May 8, 2024

In total there are over 550 symlinks. Does any of this sound problematic?

Nothing above looks like an issue to me - the issue would be if the link points further up the tree so that walking the tree could cause endless cycles.

I also tried the analyzer instrumentation logs but I can't really find anything that appears out of place

The most useful thing would be knowing what's being logged during the periods where performance is bad. So if the bad performance is during startup, it would be the start of the logs (until the first progress event with "kind": "end"). If it's during completion, it would be what occurs between the textDocument/completion request and the corresponding response.

Yes, unfortunately, this project is private and can't be shared. I could probably share the analyzer instrumentation logs privately with you, if that would help.

I can't accept anything confidential (instrumentation logs can contain contents of opened files and paths/errors for other files in the workspace), but if you're able to reproduce this on a copy of the project with anything confidential removed (and perhaps only a single test file open), you might be able to get a log that doesn't contain anything confidential you can share.

Something I forgot to ask earlier - can you confirm whether you have this option ticked in the VS Code (User or Workspace) settings?

image

@JonasJW
Copy link
Author

JonasJW commented May 8, 2024

Understood, I will go back to the logs and look for these progress events. If I have something to share I will follow up on it here.

The Dart: Only Analyze Projets With Open Files was disabled. I'm trying to enable it to see it that improves it, I will update you on this.

@DanTup
Copy link
Collaborator

DanTup commented May 8, 2024

The Dart: Only Analyze Projets With Open Files was disabled. I'm trying to enable it to see it that improves it, I will update you on this.

FWIW, my recommendation would be to not use that setting (and I should update the text). Although it sounds better for large projects, it was really added for a fairly specific case (command line editors that would provide the current working directory - which may be the user home dir - as the workspace folder). While the server will start up faster for very large workspaces, opening and closing files from different projects will trigger re-creating the analysis roots which can trigger "initial" analysis for those projects.

It's beneficial if you're opening a folder that contains 100 projects and maybe only opening files from a handful, but if you're jumping between a large portion of the projects in the workspace, it's probably worse overall.

@mraleph
Copy link
Member

mraleph commented Oct 3, 2024

@JonasJW what is your current experience with analysis performance? Are you still experiencing this weird behavior?

@JonasJW
Copy link
Author

JonasJW commented Oct 3, 2024

@mraleph yes, I'm still experiencing performance issues

@DanTup
Copy link
Collaborator

DanTup commented Oct 3, 2024

@JonasJW are you able to reproduce this issue with any public projects? It might be easier to narrow down with an instrumentation log, but that log will contain parts of source code from the open projects.

If it only occurs with this one specific internal project, is it possible to make a copy of it and see if you can narrow down what causes it (for example if it's made up of many packages, can you remove some of them to narrow down if it's caused by a specific package/set of packages)?

Do you also know if this issue occurs when typing in any file, or just some subset? This issue could be similar to #56307 which may be caused by the number of files that need to be reanalyzed as you modify a file (see #56307 (comment) and #56307 (comment)).

@amrgetment
Copy link

amrgetment commented Oct 3, 2024

Maybe a related issue
Memory Leaks in the custom_lint library
invertase/dart_custom_lint#248

@larssn
Copy link

larssn commented Oct 30, 2024

We have a pretty large project (internal, 200k lines), and this issue is pretty hard on productivity.

The worst of it comes from typing new class properties. The analyzer will get stuck on these for up to 20-30 seconds.

Here's my code --status and a screenshot of top memory in Activity Monitor.

Version:          Code 1.95.0 (912bb683695358a54ae0c670461738984cbb5b95, 2024-10-28T20:16:24.561Z)
OS Version:       Darwin arm64 24.0.0
CPUs:             Apple M1 Max (10 x 2400)
Memory (System):  32.00GB (0.28GB free)
Load (avg):       4, 5, 6
VM:               0%
Screen Reader:    no
Process Argv:     --crash-reporter-id 4e581022-c36a-4fd6-8d5e-12c2b8c113c3
GPU Status:       2d_canvas:                              enabled
                  canvas_oop_rasterization:               enabled_on
                  direct_rendering_display_compositor:    disabled_off_ok
                  gpu_compositing:                        enabled
                  multiple_raster_threads:                enabled_on
                  opengl:                                 enabled_on
                  rasterization:                          enabled
                  raw_draw:                               disabled_off_ok
                  skia_graphite:                          disabled_off
                  video_decode:                           enabled
                  video_encode:                           enabled
                  webgl:                                  enabled
                  webgl2:                                 enabled
                  webgpu:                                 enabled
                  webnn:                                  disabled_off

CPU %	Mem MB	   PID	Process
    0	   197	 47912	code main
    0	    98	 47915	   gpu-process
    0	    33	 47916	   utility-network-service
    0	   623	 47918	window [1] (sales_page.dart — tillty_pos)
    0	   492	 48349	extensionHost [1]
    1	    66	 48582	     electron-nodejs (config.js )
    0	     0	 48894	       /usr/bin/script -t 0 /dev/null /usr/bin/arch -arm64e xcrun xcdevice observe --usb
    0	    33	 48896	         /Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe --usb
    0	     0	 48895	       /usr/bin/script -t 0 /dev/null /usr/bin/arch -arm64e xcrun xcdevice observe --wifi
    0	    33	 48897	         /Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe --wifi
    6	  3736	 77823	       /Users/lars/Library/Android/sdk/emulator/qemu/darwin-aarch64/qemu-system-aarch64 -avd Pixel_Tablet_API_35
    1	    33	 77829	         /Users/lars/Library/Android/sdk/emulator/netsimd --host-dns=8.8.8.8,8.8.4.4
    0	    33	 48584	     /Users/lars/workspace/flutter/bin/cache/dart-sdk/bin/dart tooling-daemon --machine
    0	  1147	 48593	     /Users/lars/workspace/flutter/bin/cache/dart-sdk/bin/dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.98.1
    0	    33	 48836	     electron-nodejs (languageserver.js )
    0	    33	 48880	     /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json-language-features/server/dist/node/jsonServerMain --node-ipc --clientProcessId=48349
    0	    98	 48350	shared-process
    0	    33	 48351	fileWatcher [1]
    0	    66	 59875	ptyHost

Workspace Stats: 
|  Window (sales_page.dart — tillty_pos)
|    Folder (tillty_pos): more than 20467 files
|      File types: transitive_digest(3880) class(1518) dex(782) xml(648)
|                  h(635) len(597) grpc_back(510) json(440)
|                  jar(368) c(325)
|      Conf files: launch.json(1) tasks.json(1)
|      Launch Configs: dart(5)
image

(The top consumer seems to be the Android Emulator, which is probably fine)

Here's the Dart process (if relevant):
image

Anything else I can do to help debug this issue?

@mraleph
Copy link
Member

mraleph commented Oct 30, 2024

@larssn not much we can do about that qemu which is taking most your memory, but with respect to analyzer: can you look at the analyzer diagnostic page (e.g. Dart: Open Analyzer Diagnostics), click Collect Report and share that?

@larssn
Copy link

larssn commented Oct 30, 2024

@mraleph
Copy link
Member

mraleph commented Oct 30, 2024

@larssn thanks! unfortunately the report does not contain the most useful information about analyzer memory usage, due to a regression which accidentally snuck in when we changed how LSP is started. Could you try this instead:

$ dart pub global activate -sgit https://github.com/mraleph/dart_lsp_collect_global_report
$ dart pub global run dart_lsp_collect_global_report

This will try to find all dart language-server processes and then use vm-service protocol to pull some information from them. You can review the code here to know what exactly it is trying to do.

This should produce output like this:

$ dart pub global activate -sgit https://github.com/mraleph/dart_lsp_collect_global_report
Downloading packages... . 
+ collection 1.19.1
+ dart_lsp_collect_global_report 1.0.0 from git https://github.com/mraleph/dart_lsp_collect_global_report at 97e624
+ vm_service 14.3.1
Building package executables... 
Built dart_lsp_collect_global_report:dart_lsp_collect_global_report.
Installed executable dart_lsp_collect_global_report.
Activated dart_lsp_collect_global_report 1.0.0 from Git repository "https://github.com/mraleph/dart_lsp_collect_global_report".
$ dart pub global run dart_lsp_collect_global_report
Finding Dart LSP processes
Finding all open ports
Checking for development-service processes
Sending SIGQUIT to 87732 in attempt to start vm-service
... OK
Finding all open ports
Checking for development-service processes
Trying to fetch data from LSP process 35597 via ws://127.0.0.1:56167/RPaRxD3Yj0E=/ws
... OK
Trying to fetch data from LSP process 35651 via ws://127.0.0.1:56168/4ONWEeRWOrA=/ws
... OK
SUCCESS: written lsp-report.json

@DanTup
Copy link
Collaborator

DanTup commented Oct 30, 2024

@mraleph

due to a regression which accidentally snuck in when we changed how LSP is started

Is this fixed now, or does something need updating in the LSP server?

Sending SIGQUIT to 87732 in attempt to start vm-service

TIL! :)

@mraleph
Copy link
Member

mraleph commented Oct 30, 2024

Is this fixed now, or does something need updating in the LSP server?

I will take a look at it next. I have a work-around but I want to understand what happened. When we launch analysis server through dartdev (e.g. dart language-server ...) we end up with isolates which are classified as system isolates (this is inherited from dartdev isolate I guess), and the code collecting information was written in assumption that analyzer is running in a non-system isolate (which is what happens if you start it from source or directly from a snapshot). I want to check that this is intentional rather than accidental.

@larssn
Copy link

larssn commented Oct 30, 2024

@larssn thanks! unfortunately the report does not contain the most useful information about analyzer memory usage, due to a regression which accidentally snuck in when we changed how LSP is started. Could you try this instead:

$ dart pub global activate -sgit https://github.com/mraleph/dart_lsp_collect_global_report
$ dart pub global run dart_lsp_collect_global_report

This will try to find all dart language-server processes and then use vm-service protocol to pull some information from them. You can review the code here to know what exactly it is trying to do.

This should produce output like this:

$ dart pub global activate -sgit https://github.com/mraleph/dart_lsp_collect_global_report
Downloading packages... . 
+ collection 1.19.1
+ dart_lsp_collect_global_report 1.0.0 from git https://github.com/mraleph/dart_lsp_collect_global_report at 97e624
+ vm_service 14.3.1
Building package executables... 
Built dart_lsp_collect_global_report:dart_lsp_collect_global_report.
Installed executable dart_lsp_collect_global_report.
Activated dart_lsp_collect_global_report 1.0.0 from Git repository "https://github.com/mraleph/dart_lsp_collect_global_report".
$ dart pub global run dart_lsp_collect_global_report
Finding Dart LSP processes
Finding all open ports
Checking for development-service processes
Sending SIGQUIT to 87732 in attempt to start vm-service
... OK
Finding all open ports
Checking for development-service processes
Trying to fetch data from LSP process 35597 via ws://127.0.0.1:56167/RPaRxD3Yj0E=/ws
... OK
Trying to fetch data from LSP process 35651 via ws://127.0.0.1:56168/4ONWEeRWOrA=/ws
... OK
SUCCESS: written lsp-report.json

I checked out the source, and I see what it's trying to do.
It does shut down the server successfully, but it doesn't find any data.

Here's my output:

lars@Lars-MacBook-Pro tillty_pos % dart pub global run dart_lsp_collect_global_report                                      
Finding Dart LSP processes
Finding all open ports
Checking for development-service processes
Sending SIGQUIT to 11504 in attempt to start vm-service
... OK
Finding all open ports
Checking for development-service processes
SUCCESS: written lsp-report.json

The lsp-report.json only contains {}.

@mraleph
Copy link
Member

mraleph commented Oct 31, 2024

@larssn hmm, strange. Lets try again: I have added more logging so we can at least see what is going wrong:

$ dart pub global activate -sgit https://github.com/mraleph/dart_lsp_collect_global_report
Package dart_lsp_collect_global_report is currently active from Git repository "https://github.com/mraleph/dart_lsp_collect_global_report".
Downloading packages... . 
~ dart_lsp_collect_global_report 1.0.0 from git https://github.com/mraleph/dart_lsp_collect_global_report at e2f0f2 (was 1.0.0 from git https://github.com/mraleph/dart_lsp_collect_global_report at 96a2f2)
Building package executables... 
Built dart_lsp_collect_global_report:dart_lsp_collect_global_report.
Installed executable dart_lsp_collect_global_report.
Activated dart_lsp_collect_global_report 1.0.0 from Git repository "https://github.com/mraleph/dart_lsp_collect_global_report".
$ dart pub global run dart_lsp_collect_global_report
Finding Dart LSP processes
 | 35597 /Users/vegorov/src/flutter/flutter/bin/cache/dart-sdk/bin/dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.98.1
 | 35651 /Users/vegorov/src/flutter/flutter/bin/cache/dart-sdk/bin/dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.98.1
 | 77607 /Users/vegorov/src/flutter/flutter/bin/cache/dart-sdk/bin/dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.98.1

Trying to fetch vm-service URIs
Finding all open ports
-> Ports open by LSP processes:
 | 35597 [56167]
 | 35651 [56168]
 | 77607 [57784]

Checking for development-service processes
 | 71809 /Users/vegorov/src/flutter/flutter/bin/cache/dart-sdk/bin/dart development-service --vm-service-uri=http://127.0.0.1:56167/RPaRxD3Yj0E=/ --bind-address=localhost --bind-port=0 --serve-devtools
 | 71810 /Users/vegorov/src/flutter/flutter/bin/cache/dart-sdk/bin/dart development-service --vm-service-uri=http://127.0.0.1:56168/4ONWEeRWOrA=/ --bind-address=localhost --bind-port=0 --serve-devtools
 | 77657 /Users/vegorov/src/flutter/flutter/bin/cache/dart-sdk/bin/dart development-service --vm-service-uri=http://127.0.0.1:57784/xAxOESCVTeg=/ --bind-address=localhost --bind-port=0 --serve-devtools

 | 35597 ws://127.0.0.1:56167/RPaRxD3Yj0E=/ws
 | 35651 ws://127.0.0.1:56168/4ONWEeRWOrA=/ws
 | 77607 ws://127.0.0.1:57784/xAxOESCVTeg=/ws

Trying to fetch data from LSP process 35597 via ws://127.0.0.1:56167/RPaRxD3Yj0E=/ws
... OK
Trying to fetch data from LSP process 35651 via ws://127.0.0.1:56168/4ONWEeRWOrA=/ws
... OK
Trying to fetch data from LSP process 77607 via ws://127.0.0.1:57784/xAxOESCVTeg=/ws
... OK
SUCCESS: written lsp-report.json

@larssn
Copy link

larssn commented Oct 31, 2024

Cool, that did the trick.

lars@Lars-MacBook-Pro tillty_pos % dart pub global activate -sgit https://github.com/mraleph/dart_lsp_collect_global_report
Package dart_lsp_collect_global_report is currently active from Git repository "https://github.com/mraleph/dart_lsp_collect_global_report".
Downloading packages... . 
~ dart_lsp_collect_global_report 1.0.0 from git https://github.com/mraleph/dart_lsp_collect_global_report at e2f0f2 (was 1.0.0 from git https://github.com/mraleph/dart_lsp_collect_global_report at 97e624)
Building package executables... 
Built dart_lsp_collect_global_report:dart_lsp_collect_global_report.
Installed executable dart_lsp_collect_global_report.
Activated dart_lsp_collect_global_report 1.0.0 from Git repository "https://github.com/mraleph/dart_lsp_collect_global_report".
lars@Lars-MacBook-Pro tillty_pos % dart pub global run dart_lsp_collect_global_report
Finding Dart LSP processes
 | 51935 /Users/lars/workspace/flutter/bin/cache/dart-sdk/bin/dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.98.1

Trying to fetch vm-service URIs
Finding all open ports
-> Ports open by LSP processes:

Checking for development-service processes


-> LSP processes without service URI: {51935}
 | Sending SIGQUIT to 51935 in attempt to start vm-service
 | WARNING: this will damage connection between VS Code and LSP server and you will later need to restart analyzer
 | - OK
Waiting 5s for DDS to start.
Trying to fetch vm-service URIs
Finding all open ports
-> Ports open by LSP processes:
 | 51935 [52130]

Checking for development-service processes
 | 66104 /Users/lars/workspace/flutter/bin/cache/dart-sdk/bin/dart development-service --vm-service-uri=http://127.0.0.1:52130/MN978M7r1ac=/ --bind-address=localhost --bind-port=0 --serve-devtools

 | 51935 ws://127.0.0.1:52130/MN978M7r1ac=/ws

Trying to fetch data from LSP process 51935 via ws://127.0.0.1:52130/MN978M7r1ac=/ws
... OK
SUCCESS: written lsp-report.json

Here's the output:
lsp-report.json

@mraleph
Copy link
Member

mraleph commented Oct 31, 2024

Thanks! Top memory consumers seem to be:

className bytesCurrent
_OneByteString 582472320
Declaration 429231360
_Uint8List 308044912
_List 280073728
_GrowableList 175049760
_Uint32List 117865856
_TwoByteString 84699184

That's 600Mb in strings and 430Mb in Declaration objects. That's a huge amount, if you ask me. Any ideas why we see this @scheglov @jensjoha ?

@larssn what is the size of your code base? e.g. if you do cloc (brew install cloc) on the folder which you open in VS Code? Do you have any autogenerated Dart code?

@amrgetment
Copy link

My report if it helps

dart pub global run dart_lsp_collect_global_report
Finding Dart LSP processes
 | 2201 /Users/amr/fvm/versions/stable/bin/cache/dart-sdk/bin/dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.98.1

Trying to fetch vm-service URIs
Finding all open ports
-> Ports open by LSP processes:

Checking for development-service processes

-> LSP processes without service URI: {2201}
 | Sending SIGQUIT to 2201 in attempt to start vm-service
 | WARNING: this will damage connection between VS Code and LSP server and you will later need to restart analyzer
 | - OK
Waiting 5s for DDS to start.
Trying to fetch vm-service URIs
Finding all open ports
-> Ports open by LSP processes:
 | 2201 [55757]

Checking for development-service processes
 | 12620 /Users/amr/fvm/versions/stable/bin/cache/dart-sdk/bin/dart development-service --vm-service-uri=http://127.0.0.1:55757/AzjxvnRzW_E=/ --bind-address=localhost --bind-port=0 --serve-devtools

 | 2201 ws://127.0.0.1:55757/AzjxvnRzW_E=/ws

Trying to fetch data from LSP process 2201 via ws://127.0.0.1:55757/AzjxvnRzW_E=/ws
... OK
SUCCESS: written lsp-report.json

lsp-report.json

@larssn
Copy link

larssn commented Oct 31, 2024

@larssn what is the size of your code base? e.g. if you do cloc (brew install cloc) on the folder which you open in VS Code?

Here's the cloc output:

    9671 text files.
    7313 unique files.                                          
    2793 files ignored.

github.com/AlDanial/cloc v 2.02  T=6.69 s (1093.4 files/s, 255133.0 lines/s)
--------------------------------------------------------------------------------
Language                      files          blank        comment           code
--------------------------------------------------------------------------------
C/C++ Header                   2711          61798         141876         355439
C++                            1003          33866          44709         263781
YAML                             52             13             34         217732
Dart                           1225          29752          10005         186023
C                               713          20984          27956         132243
XML                             835           1305             32          50917
Objective-C                     296           8233           6830          40182
Swift                           306           6054          10078          26996
Markdown                         25           2495              0           9557
Objective-C++                    43           1307            988           5209
Text                              2              7              0           1964
JSON                             52             28              0           1621
Pascal                           13            356           2224            910
Bourne Shell                      7             85             98            595
PHP                              10            229            557            546
Java                              1              3              5            166
Gradle                            3             28             40            130
Bourne Again Shell                1             19             20            121
DOS Batch                         1             24              2             64
Fortran 77                        1              2              0             56
Properties                        6              0              2             23
ProGuard                          1              0              2             15
Ruby                              1              1              6             11
D                                 4              0              0              4
Kotlin                            1              6             40              4
--------------------------------------------------------------------------------
SUM:                           7313         166595         245504        1294309
--------------------------------------------------------------------------------

Do you have any autogenerated Dart code?

Yes, we use built_value and built_collection, which results in a fair chunk of autogenerated code.

@amrgetment
Copy link

I use freezed library but it is excluded from the analyzer

analyzer:
  exclude:
    - build/**
    - lib/**.g.dart
    - lib/**.freezed.dart

   31831 text files.
    7399 unique files.                                          
   30734 files ignored.

github.com/AlDanial/cloc v 2.02  T=137.71 s (53.7 files/s, 79579.9 lines/s)
--------------------------------------------------------------------------------
Language                      files          blank        comment           code
--------------------------------------------------------------------------------
Assembly                          2              0              0        8676068
JSON                            279             52              0         426810
XML                            1053           5389            231         391921
C/C++ Header                   2797          56001         134409         346975
Dart                           1827          52579          79008         318682
YAML                            193             83            112         265789
Objective-C                     470          13037          11993          65284
Swift                           300           5896           9374          26051
Text                            131              5              0          24010
Markdown                         34           3661              1          14416
C++                              38           1237           1012           8122
C                                26           1543           1061           6335
Bourne Shell                     20            257            236           2375
Pascal                           13            356           2224            910
SVG                             123              0              0            669
PHP                              10            229            557            546
Objective-C++                     2            113             76            445
JavaScript                        8             83             93            382
HTML                              5             53             20            336
CSS                               5             48             41            256
Java                             10             12             46            254
Gradle                            3             32             17            166
Properties                       17              5             38            128
Bourne Again Shell                1             19             20            121
ProGuard                          1             30             46            121
Python                            2             25              6             88
DOS Batch                         2             24              2             69
Fortran 77                        1              2              0             56
D                                17              0              0             17
Ruby                              1              1              6             11
SQL                               5              0              0             10
Dockerfile                        1              8              6              9
Kotlin                            1              2              0              4
CSV                               1              0              0              1
--------------------------------------------------------------------------------
SUM:                           7399         140782         240635       10577437
--------------------------------------------------------------------------------

@scheglov
Copy link
Contributor

I suspect that Declaration are these objects. We really should remove them. I think I removed almost all uses of it, except one for finding all DartDoc directives. Unfortunately I did not have time to finish this arc of work yet.

@scheglov
Copy link
Contributor

#55281 will remove Declaration and most of the related implementation.
Not ideal, we probably should eventually migrate to FileState.
But should reduce heap usage significantly.

@adityadua24
Copy link

adityadua24 commented Nov 3, 2024

I have been experiencing the same issue and it really effects productivity on VS Code
Memory consumption looks really high. Something isn't right.
A fix for this would be great !
image

@mraleph
Copy link
Member

mraleph commented Nov 4, 2024

@larssn @amrgetment would it be possible for you to try a bleeding edge SDK build to see if there a significant improvement in memory usage? Bleeding edge build for Apple Silicon Macs is located here. Dev build with @scheglov's change is not ready yet (c17dd35 is in 3.7.0-95.0.dev or newer).

You should be able to download and unpack SDK somewhere and then simply point VS Code to it via (dart.sdkPaths or dart.sdkPath). Though maybe some workflows will get broken like this, not sure.

@larssn
Copy link

larssn commented Nov 4, 2024

@larssn @amrgetment would it be possible for you to try a bleeding edge SDK build to see if there a significant improvement in memory usage? Bleeding edge build for Apple Silicon Macs is located here. Dev build with @scheglov's change is not ready yet (c17dd35 is in 3.7.0-95.0.dev or newer).

You should be able to download and unpack SDK somewhere and then simply point VS Code to it via (dart.sdkPaths or dart.sdkPath). Though maybe some workflows will get broken like this, not sure.

Done. Seems to have helped greatly with performance.
What took upwards to 30 seconds before, now maybe takes 2-5 seconds.

Good job!

@mraleph
Copy link
Member

mraleph commented Nov 4, 2024

@larssn could you try an dart_lsp_collect_global_report on it (I hope it works :))? I would like to see what happened to memory usage.

@larssn
Copy link

larssn commented Nov 4, 2024

Of course!

lsp-report.json

edit
And another "of course": my previous response was based on a short test.
I think I could give a better answer regarding performance after working with it for a day or two.

@mraleph And if you need me onsite, it's but a short bike ride 😁

@mraleph
Copy link
Member

mraleph commented Nov 4, 2024

@larssn nice diff comparing to the previous report, which I think confirms improvements from @scheglov's patch. Nice improvement!

Library Class Size Diff Count Diff
dart.core _OneByteString -401335200 -6025567
Declaration -392022240 -1633426
dart.core _GrowableList -152551904 -4767247
dart.core _List -65571216 -2624485
dart.typed_data _Uint16List -22660560 -47964

Total change in memory consumption: -788815120

Diffs are not directly comparable because, I think, depending on the timing when snapshot is taken there might be different things hanging in memory, but if this holds this is huge improvement to memory usage.

PS.

@mraleph And if you need me onsite, it's but a short bike ride 😁

I would not be able to look at your code for reasons, but I made a mental note of that :)

@amrgetment
Copy link

how could I use it for Intel Mac or when will this fix be released?

@mraleph
Copy link
Member

mraleph commented Nov 4, 2024

how could I use it for Intel Mac

You can download bleeding edge SDK to try it from here:

https://storage.googleapis.com/dart-archive/channels/main/raw/latest/sdk/dartsdk-macos-x64-release.zip

or when will this fix be released?

If you are asking when it will be included into a stable release - then the answer is: 3-6 months from now, because we are just past one stable release.

copybara-service bot pushed a commit that referenced this issue Nov 4, 2024
Bug: #55281
Change-Id: Ie8d2a7f3d5ea9408320312d49eb67561ca463289
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393480
Reviewed-by: Phil Quitslund <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-stability area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-performance Issue relates to performance or code size
Projects
None yet
Development

No branches or pull requests