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 · 165 comments
Open

Dart Analyzer very slow/stuck #55281

JonasJW opened this issue Mar 22, 2024 · 165 comments
Labels
analyzer-stability area-dart-model Use area-dart-model for issues related to packages analyzer, front_end, and kernel. model-performance Performance/memory issues in analyzer/cfe 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?

@pq
Copy link
Member

pq commented Mar 4, 2025

@gisborne currently the diagnostics report does not contain the "Analysis Driver Timings".

@jensjoha: should we update the report to do so?

@rodrigo-itao
Copy link

rodrigo-itao commented Mar 4, 2025

For anyone experiencing the analyzer being very slow it would be really helpful if you could:

  • Go to the "Analyzer" page (in VSCode you can get here by opening the command pallette and executing the Dart: Open Analyzer Diagnostics option - in IntelliJ it's shown at Dart Analyzer very slow/stuck #55281 (comment) to to get there),
  • navigate to the Analysis Driver Timings tab (found in the links on the left),
  • copy-paste the text in the grey box,
  • click the Reset Timers button,
  • reproduce some slowness, e.g. autocompletion being really slow,
  • update the page and copy-paste the text in the grey box again,
  • then go to the "Collect Report" tab (found in the links at the top right),
  • click the Download report button and download the file,
  • attach the downloaded file here
  • furthermore describe exactly what you're experiencing (e.g. "it's slow" isn't super helpful, but something like "completion takes 10+ seconds to appear after I change the name of a top-level method" is)

Furthermore: If anyone is experiencing this on something that is available as open source, please please tell us and provide us reproduction steps.

Before Reset Timers:

before_reset_timers.txt

After Reset Timers:

after_reset_timers.txt

Report file:

dart_analyzer_diagnostics_report.json

Video of what I was doing:

Untitled.video.mp4

@scheglov
Copy link
Contributor

scheglov commented Mar 4, 2025

I see quite a lot libraries loaded in the examples above: libraryLoadCount: 24716 and libraryLoadCount: 32004.
But there was only one link of a library cycle even if with name: libraryFile, count: 668 files.
This somewhat surprising, I'd expect that any such dependencies are loaded once, and not discarded.

Also, the number of name: getUnitElement, count: 403282 is huge.
Especially for 10 seconds of log.
I have half a much for 26 minutes logged, over a few hours of using IntelliJ.

@rodrigo-itao
Copy link

I see quite a lot libraries loaded in the examples above: libraryLoadCount: 24716 and libraryLoadCount: 32004. But there was only one link of a library cycle even if with name: libraryFile, count: 668 files. This somewhat surprising, I'd expect that any such dependencies are loaded once, and not discarded.

Also, the number of name: getUnitElement, count: 403282 is huge. Especially for 10 seconds of log. I have half a much for 26 minutes logged, over a few hours of using IntelliJ.

Actually, since this bug is a bit difficult to reproduce on demand, I did the following:

  1. Reset the timers;
  2. Worked for about 10 minutes without major problems;
  3. Then the situation captured in the video happened.

@rodrigo-itao
Copy link

rodrigo-itao commented Mar 4, 2025

I see quite a lot libraries loaded in the examples above: libraryLoadCount: 24716 and libraryLoadCount: 32004. But there was only one link of a library cycle even if with name: libraryFile, count: 668 files. This somewhat surprising, I'd expect that any such dependencies are loaded once, and not discarded.
Also, the number of name: getUnitElement, count: 403282 is huge. Especially for 10 seconds of log. I have half a much for 26 minutes logged, over a few hours of using IntelliJ.

Actually, since this bug is a bit difficult to reproduce on demand, I did the following:

  1. Reset the timers;
  2. Worked for about 10 minutes without major problems;
  3. Then the situation captured in the video happened.

I managed to reproduce this bug again. This time, the log corresponds to the duration of the video:

Before Reset Timers:

before_reset_timers.txt

After Reset Timers:

after_reset_timers.txt

Report file:

dart_analyzer_diagnostics_report.json

Video of what I was doing:

simplescreenrecorder-2025-03-04_19.29.22.mp4

@zhoushuangjian001
Copy link

I also encountered this situation, which greatly affected the development efficiency and experience

@jensjoha
Copy link
Contributor

jensjoha commented Mar 5, 2025

@gisborne currently the diagnostics report does not contain the "Analysis Driver Timings".

@jensjoha: should we update the report to do so?

I did that in 1e5a270 but it will take a while before it gets to users.

@jensjoha
Copy link
Contributor

jensjoha commented Mar 5, 2025

Thank you @luis901101.
Thank you @rodrigo-itao.

In both cases at least part of the problem seems to be that the IDE issues a whole lot of (similar) requests - edit.getFixes specifically - very quickly after each other. Each request takes longer to respond to, than the delay before the next one is send, and the latency (time from when the IDE sends the request to when the analysis server has time to receive it) keeps increasing.

E.g. I found one instance where over the span of less than 7.2 seconds, 27 edit.getFixes requests comes in, each taking an average of a little over 1 second to complete - and as a consequence naturally building up a latency of over 20 seconds on the last of those request.

Thoughts currently running through my mind:

  • Why does the IDE send so many requests? Probably it shouldn't.
  • Could the analysis server filter some of them out? E.g if it gets two (or more) edit.getFixes could it respond to only one of them? (sending a 'assumed cancelled' response or something to the other ones?)
  • Why are these requests taking so long?
  • edit.getFixes doesn't have any specified performance data shown. We should probably add that.

@johnniwinther johnniwinther added area-dart-model Use area-dart-model for issues related to packages analyzer, front_end, and kernel. and removed area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Mar 5, 2025
@bwilkerson
Copy link
Member

Why does the IDE send so many requests? Probably it shouldn't.

The IDE asks for fixes every time the cursor location changes so that the lightbulb menu has the fixes for the current location.

Could the analysis server filter some of them out?

Yes. I believe that we could and should de- dup the requests.

Why are these requests taking so long?

Good question. If we can reproduce this behavior we can add a way to get timing information from the operation so that we can answer that question.

@pq
Copy link
Member

pq commented Mar 5, 2025

@jensjoha:

In both cases at least part of the problem seems to be that the IDE issues a whole lot of (similar) requests

Confirming that this is w/ IntelliJ/Android (not vscode)?

@maxhuk
Copy link

maxhuk commented Mar 6, 2025

For me it happens with VSCode

@jensjoha
Copy link
Contributor

jensjoha commented Mar 6, 2025

@jensjoha:

In both cases at least part of the problem seems to be that the IDE issues a whole lot of (similar) requests

Confirming that this is w/ IntelliJ/Android (not vscode)?

For the two examples that we got data for here, yes - in both cases the client is Android-Studio.

@jensjoha
Copy link
Contributor

jensjoha commented Mar 6, 2025

For me it happens with VSCode

@maxhuk If you could follow the steps in #55281 (comment) and provide us data that would be helpful. Thanks!

@realth000
Copy link

I'm also suffering the latency in code completion and analyzing.

It often stuck at highlighting and preparing code completion (where before I can navigation to variable/class definition).

And it does not update analyze info after dart run build_runner build -d, I have to restart dart analyze server after that command every time, each time it took more than 20 seconds till code completion is ready. This issue seems only occurs on Windows, since Flutter 3.19, I think.

Post log here because on my machine it seems the most time consume stage is (name: analyzeFile, count: 1026, elapsed: 0:00:20.107960, elapsedSelf: 0:00:16.382974) which is different from logs above.

Logs

before reset timer, the server has been running for a while:

(name: <scheduler>, count: 0, elapsed: 0:00:00.000000, elapsedSelf: -0:02:53.211775)
  (name: analyzeFile, count: 6357, elapsed: 0:02:39.974931, elapsedSelf: 0:02:17.502826)
    (name: libraryContext, count: 6357, elapsed: 0:00:22.472105, elapsedSelf: 0:00:02.791197)(bytesGet: 518140765, bytesPut: 2438710, cycleCount: 26342, libraryCount: 63424, libraryLoadCount: 62725)
      (name: libraryCycle, count: 6357, elapsed: 0:00:18.088015, elapsedSelf: 0:00:06.103270)
        (name: fileState.refresh, count: 56364, elapsed: 0:00:11.984745, elapsedSelf: 0:00:11.891399)
          (name: getUnlinkedUnit, count: 56364, elapsed: 0:00:00.093346, elapsedSelf: 0:00:00.057271)
            (name: parseCode, count: 5, elapsed: 0:00:00.021770, elapsedSelf: 0:00:00.021770)(length: 438912)
            (name: compute, count: 5, elapsed: 0:00:00.014305, elapsedSelf: 0:00:00.004094)
              (name: serializeAstUnlinked2, count: 5, elapsed: 0:00:00.010211, elapsedSelf: 0:00:00.004533)
                (name: apiSignature, count: 5, elapsed: 0:00:00.005678, elapsedSelf: 0:00:00.005678)
      (name: link, count: 80, elapsed: 0:00:01.592893, elapsedSelf: 0:00:00.002090)
        (name: LibraryBuilder.build, count: 80, elapsed: 0:00:00.286748, elapsedSelf: 0:00:00.005361)
          (name: libraryFile, count: 699, elapsed: 0:00:00.281387, elapsedSelf: 0:00:00.000875)
            (name: parseCode, count: 699, elapsed: 0:00:00.280512, elapsedSelf: 0:00:00.280512)(length: 4028016)
        (name: buildOutlines, count: 80, elapsed: 0:00:01.229568, elapsedSelf: 0:00:00.965589)
          (name: computeLibraryScopes, count: 80, elapsed: 0:00:00.260745, elapsedSelf: 0:00:00.215827)
            (name: buildMacroApplier, count: 80, elapsed: 0:00:00.044431, elapsedSelf: 0:00:00.044431)
            (name: executeMacroTypesPhase, count: 80, elapsed: 0:00:00.000487, elapsedSelf: 0:00:00.000487)
          (name: executeMacroDeclarationsPhase, count: 80, elapsed: 0:00:00.001204, elapsedSelf: 0:00:00.001204)
          (name: executeMacroDefinitionsPhase, count: 80, elapsed: 0:00:00.000913, elapsedSelf: 0:00:00.000913)
          (name: mergeMacroAugmentations, count: 80, elapsed: 0:00:00.001117, elapsedSelf: 0:00:00.000747)
            (name: buildAugmentationLibraryCode, count: 699, elapsed: 0:00:00.000370, elapsedSelf: 0:00:00.000370)
        (name: writeLibraries, count: 80, elapsed: 0:00:00.074487, elapsedSelf: 0:00:00.074487)(length: 2438710)
  (name: getUnitElement, count: 165794, elapsed: 0:00:13.236844, elapsedSelf: 0:00:05.570062)
    (name: libraryContext, count: 165794, elapsed: 0:00:07.666782, elapsedSelf: 0:00:03.353340)(bytesGet: 226974256, bytesPut: 5639341, cycleCount: 34000, libraryCount: 34856, libraryLoadCount: 34014)
      (name: libraryCycle, count: 165794, elapsed: 0:00:01.243740, elapsedSelf: 0:00:01.243729)
        (name: fileState.refresh, count: 1, elapsed: 0:00:00.000011, elapsedSelf: 0:00:00.000010)
          (name: getUnlinkedUnit, count: 1, elapsed: 0:00:00.000001, elapsedSelf: 0:00:00.000001)
      (name: link, count: 839, elapsed: 0:00:03.069702, elapsedSelf: 0:00:00.013081)
        (name: LibraryBuilder.build, count: 839, elapsed: 0:00:00.458479, elapsedSelf: 0:00:00.010671)
          (name: libraryFile, count: 842, elapsed: 0:00:00.447808, elapsedSelf: 0:00:00.002020)
            (name: parseCode, count: 842, elapsed: 0:00:00.445788, elapsedSelf: 0:00:00.445788)(length: 5838366)
        (name: buildOutlines, count: 839, elapsed: 0:00:02.348338, elapsedSelf: 0:00:01.650645)
          (name: computeLibraryScopes, count: 839, elapsed: 0:00:00.682069, elapsedSelf: 0:00:00.626631)
            (name: buildMacroApplier, count: 839, elapsed: 0:00:00.053283, elapsedSelf: 0:00:00.053283)
            (name: executeMacroTypesPhase, count: 839, elapsed: 0:00:00.002155, elapsedSelf: 0:00:00.002155)
          (name: executeMacroDeclarationsPhase, count: 839, elapsed: 0:00:00.005185, elapsedSelf: 0:00:00.005185)
          (name: executeMacroDefinitionsPhase, count: 839, elapsed: 0:00:00.004768, elapsedSelf: 0:00:00.004768)
          (name: mergeMacroAugmentations, count: 839, elapsed: 0:00:00.005671, elapsedSelf: 0:00:00.003704)
            (name: buildAugmentationLibraryCode, count: 842, elapsed: 0:00:00.001967, elapsedSelf: 0:00:00.001967)
        (name: writeLibraries, count: 839, elapsed: 0:00:00.249804, elapsedSelf: 0:00:00.249804)(length: 5639341)

after reset timer and stuck again:

(name: <scheduler>, count: 0, elapsed: 0:00:00.000000, elapsedSelf: -0:00:20.246658)
  (name: getUnitElement, count: 5437, elapsed: 0:00:00.138698, elapsedSelf: 0:00:00.024330)
    (name: libraryContext, count: 5437, elapsed: 0:00:00.114368, elapsedSelf: 0:00:00.029478)(bytesGet: 94103, bytesPut: 188570, cycleCount: 18, libraryCount: 102, libraryLoadCount: 34)
      (name: libraryCycle, count: 5437, elapsed: 0:00:00.002420, elapsedSelf: 0:00:00.002420)
      (name: link, count: 12, elapsed: 0:00:00.082470, elapsedSelf: 0:00:00.000129)
        (name: LibraryBuilder.build, count: 12, elapsed: 0:00:00.023298, elapsedSelf: 0:00:00.000333)
          (name: libraryFile, count: 68, elapsed: 0:00:00.022965, elapsedSelf: 0:00:00.000039)
            (name: parseCode, count: 68, elapsed: 0:00:00.022926, elapsedSelf: 0:00:00.022926)(length: 381240)
        (name: buildOutlines, count: 12, elapsed: 0:00:00.053664, elapsedSelf: 0:00:00.042327)
          (name: computeLibraryScopes, count: 12, elapsed: 0:00:00.011027, elapsedSelf: 0:00:00.009688)
            (name: buildMacroApplier, count: 12, elapsed: 0:00:00.001288, elapsedSelf: 0:00:00.001288)
            (name: executeMacroTypesPhase, count: 12, elapsed: 0:00:00.000051, elapsedSelf: 0:00:00.000051)
          (name: executeMacroDeclarationsPhase, count: 12, elapsed: 0:00:00.000110, elapsedSelf: 0:00:00.000110)
          (name: executeMacroDefinitionsPhase, count: 12, elapsed: 0:00:00.000091, elapsedSelf: 0:00:00.000091)
          (name: mergeMacroAugmentations, count: 12, elapsed: 0:00:00.000109, elapsedSelf: 0:00:00.000076)
            (name: buildAugmentationLibraryCode, count: 68, elapsed: 0:00:00.000033, elapsedSelf: 0:00:00.000033)
        (name: writeLibraries, count: 12, elapsed: 0:00:00.005379, elapsedSelf: 0:00:00.005379)(length: 188570)
  (name: analyzeFile, count: 1026, elapsed: 0:00:20.107960, elapsedSelf: 0:00:16.382974)
    (name: libraryContext, count: 1026, elapsed: 0:00:03.724986, elapsedSelf: 0:00:00.291937)(bytesGet: 64145979, bytesPut: 997982, cycleCount: 3701, libraryCount: 7447, libraryLoadCount: 7080)
      (name: libraryCycle, count: 1026, elapsed: 0:00:02.719416, elapsedSelf: 0:00:00.850810)
        (name: fileState.refresh, count: 7618, elapsed: 0:00:01.868606, elapsedSelf: 0:00:01.684744)
          (name: getUnlinkedUnit, count: 7618, elapsed: 0:00:00.183862, elapsedSelf: 0:00:00.183862)
      (name: link, count: 83, elapsed: 0:00:00.713633, elapsedSelf: 0:00:00.000880)
        (name: LibraryBuilder.build, count: 83, elapsed: 0:00:00.142170, elapsedSelf: 0:00:00.001966)
          (name: libraryFile, count: 367, elapsed: 0:00:00.140204, elapsedSelf: 0:00:00.000242)
            (name: parseCode, count: 367, elapsed: 0:00:00.139962, elapsedSelf: 0:00:00.139962)(length: 1957674)
        (name: buildOutlines, count: 83, elapsed: 0:00:00.538433, elapsedSelf: 0:00:00.440174)
          (name: computeLibraryScopes, count: 83, elapsed: 0:00:00.096420, elapsedSelf: 0:00:00.089897)
            (name: buildMacroApplier, count: 83, elapsed: 0:00:00.006170, elapsedSelf: 0:00:00.006170)
            (name: executeMacroTypesPhase, count: 83, elapsed: 0:00:00.000353, elapsedSelf: 0:00:00.000353)
          (name: executeMacroDeclarationsPhase, count: 83, elapsed: 0:00:00.000655, elapsedSelf: 0:00:00.000655)
          (name: executeMacroDefinitionsPhase, count: 83, elapsed: 0:00:00.000503, elapsedSelf: 0:00:00.000503)
          (name: mergeMacroAugmentations, count: 83, elapsed: 0:00:00.000681, elapsedSelf: 0:00:00.000453)
            (name: buildAugmentationLibraryCode, count: 367, elapsed: 0:00:00.000228, elapsedSelf: 0:00:00.000228)
        (name: writeLibraries, count: 83, elapsed: 0:00:00.032150, elapsedSelf: 0:00:00.032150)(length: 997982)

json file:

dart_analyzer_diagnostics_report.json

What am i doing

Writing code and jump between files by navigating to definition, sometimes it lose highlighting and I have to wait for it.

Info

dart info

$ dart info

If providing this information as part of reporting a bug, please review the information
below to ensure it only contains things you're comfortable posting publicly.

#### General info

- Dart 3.7.0 (stable) (Wed Feb 5 04:53:58 2025 -0800) on "windows_x64"
- on windows / "Windows 11 专业版" 10.0 (Build 22631)
- locale is zh-CN

#### Project info

- sdk constraint: '>=3.7.0 <4.0.0'
- dependencies: args, bbob_dart, bloc, chat_bottom_container, collection, cookie_jar, dart_mappable, dio, dio_brotli_transformer, dio_cookie_manager, drift, drift_dev, drift_flutter, easy_refresh, equatable, extended_nested_scroll_view, file_picker, flex_color_scheme, flutter, flutter_bloc, flutter_local_notifications, flutter_localizations, flutter_markdown, flutter_svg, font_awesome_flutter, fpdart, get_it, gitsumu, go_router, html, image_picker, json_annotation, material_design_icons_flutter, path, path_provider, permission_handler, responsive_framework, rxdart, shimmer, slang, slang_flutter, sqlite3, sqlite3_flutter_libs, stream_transform, super_sliver_list, surf_lint_rules, system_theme, talker, talker_flutter, universal_html, url_launcher, uuid, web, widget_zoom, window_manager
- dev_dependencies: build_runner, custom_lint, dart_mappable_builder, flutter_launcher_icons, flutter_test, json_serializable, pyramid_lint, slang_build_runner, very_good_analysis
- elided dependencies: 2

#### Process info

|  Memory | CPU | Elapsed time | Command line |
| ------: | --: | -----------: | ------------ |
| 2077 MB |  -- |              | dart.exe     |
|   45 MB |  -- |              | dart.exe     |
|   16 MB |  -- |              | dart.exe     |
|   18 MB |  -- |              | dart.exe     |
|  117 MB |  -- |              | dart.exe     |
|  143 MB |  -- |              | dart.exe     |
|   25 MB |  -- |              | dart.exe     |
| 1494 MB |  -- |              | dart.exe     |
|  107 MB |  -- |              | dart.exe     |

Codebase size:

# Ignore codegen files. 

✿ tokei lib
===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 Dart                  427        42970        30106         7987         4877
 JSON                   10         2669         2669            0            0
===============================================================================
 Total                 437        45639        32775         7987         4877
===============================================================================

# Include codegen files.

✿ tokei lib --no-ignore
===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 Dart                  500       100752        78453         9295        13004
 JSON                   10         2669         2669            0            0
===============================================================================
 Total                 510       103421        81122         9295        13004
===============================================================================

IDE

IntelliJ IDEA 2024.3.4 (Ultimate Edition)
Build #IU-243.25659.39, built on February 27, 2025
Runtime version: 21.0.6+8-b631.39 amd64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.awt.windows.WToolkit
Windows 11.0
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 2048M
Cores: 16
Registry:
  debugger.new.tool.window.layout=true
  ide.experimental.ui=true
  terminal.new.ui=true
  org.toml.json.schema=false
Non-Bundled Plugins:
  com.jetbrains.gerryPurpleTheme (2025.1.0222)
  com.thvardhan.gradianto (5.5)
  monokai-pro (2.0.1)
  com.github.catppuccin.jetbrains (3.4.1)
  com.vecheslav.darculaDarkerTheme (1.2.0)
  com.arcticicestudio.nord.jetbrains (0.13.0)
  color.scheme.Tokyo Night (0.3)
  com.zeekbtye.tokyonight (0.2.0)
  club.nutsoft.Github3Theme (1.2.2)
  io.ddiu.moegi.theme.jetbrains (0.0.3)
  IdeaVIM (2.19.0)
  labs.hardhacker.theme.jetbrains (0.2.6)
  com.jetbrains.rust (243.24978.86)
  io.github.frykher.jetbrains-kanagawa-theme (1.2.2)
  com.jetbrains.darkPurpleTheme (1.3)
  com.github.ewwwdp.darker-horizon (1.0.1)
  neon-cat (1.0.3)
  com.herbert.george.dart.extensions (0.0.1+3)
  com.xinkun.theme.md (1.7.12)
  net.antelle.intellij-xcode-dark-theme (1.2.4)
  com.github.lonre.gruvbox-intellij-theme (0.6.3)
  GrepConsole (13.2.0-IJ2023.3)
  Dart (243.23654.44)
  com.localizely.flutter-intl (1.18.8-2024.2)
  com.nasller.CodeGlancePro (1.9.6)
  org.jetbrains.android (243.25659.39)
  io.flutter (83.0.4)
  androidx.compose.plugins.idea (243.23654.117)
  com.android.tools.design (243.23654.189)
  ru.adelf.idea.dotenv (2024.3)
  izhangzhihao.rainbow.brackets (2024.2.9-241)
  zielu.gittoolbox (600.0.14+243)
  com.brandiico.jetbrains-nightfall-theme (2.0.3)
Kotlin: 243.25659.39-IJ

@knopp
Copy link
Contributor

knopp commented Mar 8, 2025

Steps to reproduce:

open flutter framework in VSCode on Windows (seems to be less severe on macOS).

Open lib/src/widgets/binding.dart.

Wait for the dust to settle.

Go inside WidgetBindingsObserver, add empty method void x() { } and trigger autocomplete in method body.

abstract mixin class WidgetsBindingObserver {

  void x() {
     // trigger autocomplete here before saving the changes
  }

Analysis timing reset right before adding the method and triggering autocomplete:

(name: <scheduler>, count: 0, elapsed: 0:00:00.000000, elapsedSelf: -0:00:35.567119)
  (name: analyzeFile, count: 5, elapsed: 0:00:33.849900, elapsedSelf: 0:00:01.567126)
    (name: libraryContext, count: 5, elapsed: 0:00:30.367342, elapsedSelf: 0:00:00.089062)(bytesGet: 18947739, bytesPut: 20786812, cycleCount: 680, libraryCount: 3060, libraryLoadCount: 1734)
      (name: libraryCycle, count: 5, elapsed: 0:00:00.127969, elapsedSelf: 0:00:00.127969)
      (name: bundleReader, count: 677, elapsed: 0:00:00.077193, elapsedSelf: 0:00:00.077193)
      (name: link, count: 3, elapsed: 0:00:30.073118, elapsedSelf: 0:00:00.000133)
        (name: LibraryBuilder.build, count: 3, elapsed: 0:00:09.483828, elapsedSelf: 0:00:00.063373)
          (name: libraryFile, count: 1326, elapsed: 0:00:09.420455, elapsedSelf: 0:00:00.007854)
            (name: parseCode, count: 1326, elapsed: 0:00:09.412601, elapsedSelf: 0:00:09.412601)(length: 48431158)
        (name: buildOutlines, count: 3, elapsed: 0:00:18.240424, elapsedSelf: 0:00:14.398082)
          (name: computeLibraryScopes, count: 3, elapsed: 0:00:03.842342, elapsedSelf: 0:00:03.842342)
        (name: writeLibraries, count: 3, elapsed: 0:00:02.348733, elapsedSelf: 0:00:02.178561)(length: 20786812)
          (name: bundleWriteFinish, count: 3, elapsed: 0:00:00.170172, elapsedSelf: 0:00:00.170172)
    (name: LibraryAnalyzer, count: 5, elapsed: 0:00:01.915432, elapsedSelf: 0:00:00.000617)
      (name: parseAndResolve, count: 5, elapsed: 0:00:01.461612, elapsedSelf: 0:00:01.461612)
      (name: computeDiagnostics, count: 5, elapsed: 0:00:00.453203, elapsedSelf: 0:00:00.453203)
  (name: getUnitElement, count: 16, elapsed: 0:00:00.002090, elapsedSelf: 0:00:00.001987)
    (name: libraryContext, count: 16, elapsed: 0:00:00.000103, elapsedSelf: 0:00:00.000082)
      (name: libraryCycle, count: 16, elapsed: 0:00:00.000021, elapsedSelf: 0:00:00.000021)
  (name: produceErrors, count: 5, elapsed: 0:00:01.715129, elapsedSelf: 0:00:00.002320)
    (name: libraryContext, count: 5, elapsed: 0:00:00.000166, elapsedSelf: 0:00:00.000152)
      (name: libraryCycle, count: 5, elapsed: 0:00:00.000014, elapsedSelf: 0:00:00.000014)
    (name: analyzeFile, count: 5, elapsed: 0:00:01.712643, elapsedSelf: 0:00:00.068848)
      (name: libraryContext, count: 5, elapsed: 0:00:00.000027, elapsedSelf: 0:00:00.000022)
        (name: libraryCycle, count: 5, elapsed: 0:00:00.000005, elapsedSelf: 0:00:00.000005)
      (name: LibraryAnalyzer, count: 5, elapsed: 0:00:01.643768, elapsedSelf: 0:00:00.000349)
        (name: parseAndResolve, count: 5, elapsed: 0:00:00.778147, elapsedSelf: 0:00:00.778147)
        (name: computeDiagnostics, count: 5, elapsed: 0:00:00.865272, elapsedSelf: 0:00:00.865272)

After some editing things get so bad the analyzer basically stops responding and needs to be restarted.

This is with current main:

Flutter 3.30.0-1.0.pre.510 • channel [user-branch] • git@github.com:knopp/flutter.git
Framework • revision 77156a1f05 (6 hours ago) • 2025-03-04 16:17:55 +0100
Engine • revision 1b14b0c11a (27 hours ago) • 2025-03-07 10:56:08 -0500
Tools • Dart 3.8.0 (build 3.8.0-149.0.dev) • DevTools 2.43.0

@DanTup
Copy link
Collaborator

DanTup commented Mar 10, 2025

@realth000 thanks for the file - there are a lot of slow edit.getAssists requests so I think you're seeing the same issue as is discussed in #55281 (comment) (which I think @jensjoha may be working on some improvements for). I opened a sub-issue for this problem to make it easier to follow (since this issue contains multiple different issues): #60292

@knopp thanks, I can reproduce fairly long analysis when making a single-keystroke change to that file too (not to the point of needing to restart the server, but my testing was fairly limited). I've opened a specific sub-issue for this with my timings and a CPU profile at #60293.

copybara-service bot pushed a commit that referenced this issue Mar 10, 2025
Also add benchmark where lots of hover requests are fired,
mimicking IntelliJ behavior when holding ctrl and moving the mouse over
imports.

I'm getting these results on my machine:

```
4 files / CodeType.ImportCycle:
Initial analysis: 1.249438
Completion after change: 10.143719

4 files / CodeType.ImportChain:
Initial analysis: 1.367604
Completion after change: 9.936909

4 files / CodeType.ImportExportCycle:
Initial analysis: 1.233644
Completion after change: 10.011695

4 files / CodeType.ImportExportChain:
Initial analysis: 1.226382
Completion after change: 9.875991

4 files / CodeType.ImportCycleExportChain:
Initial analysis: 1.262932
Completion after change: 9.995607
```

notice the low number of files (in the chain*) or if it even is a chain
etc doesn't appear to change anything for the time it takes to become
responsive again.

Notice that in
#55281 (comment) I
noticed that something similar happened for `edit.getFixes`, but I'm yet
to actually reproduce that.

Change-Id: Iff04124825c6ea2f759b4d048a0f2988709eaebf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413981
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
copybara-service bot pushed a commit that referenced this issue Mar 10, 2025
TL;DR: By only responding (for real) to the newest hover request a
benchmark that used to take ~10 seconds now takes ~0.6 seconds.

Details:

In #55281 (comment)
I noticed that some of the performance issues people are seeing fom the
analyzer server stem from many requests being fired, each taking longer
the wait before the next is issued, naturally building up a longer and
loger queue before responses are made. Their it was for `edit.getFixes`,
but I'm yet to actually reproduce that. I did reproduce for hover
requests though, so here I'm debounsing those hover requests.
I'm hooking into the system that already debounces completion requests
and following the pattern used there.

On my machine, running

```
out/ReleaseX64/dart-sdk/bin/dart \
pkg/analysis_server/tool/benchmark_tools/big_chain_benchmark/legacy_many_hover_requests.dart
```

I get these numbers:

Before CL (taken from the parent CL that introduces the benchmark):

```
4 files / CodeType.ImportCycle:
Initial analysis: 1.249438
Completion after change: 10.143719

4 files / CodeType.ImportChain:
Initial analysis: 1.367604
Completion after change: 9.936909

4 files / CodeType.ImportExportCycle:
Initial analysis: 1.233644
Completion after change: 10.011695

4 files / CodeType.ImportExportChain:
Initial analysis: 1.226382
Completion after change: 9.875991

4 files / CodeType.ImportCycleExportChain:
Initial analysis: 1.262932
Completion after change: 9.995607
```

With CL:

```
4 files / CodeType.ImportCycle:
Initial analysis: 1.322501
Completion after change: 0.569768

4 files / CodeType.ImportChain:
Initial analysis: 1.347588
Completion after change: 0.635748

4 files / CodeType.ImportExportCycle:
Initial analysis: 1.492362
Completion after change: 0.575233

4 files / CodeType.ImportExportChain:
Initial analysis: 1.331619
Completion after change: 0.576199

4 files / CodeType.ImportCycleExportChain:
Initial analysis: 1.342130
Completion after change: 0.608064
```

Change-Id: Ide3dbc4dfb885af9e1c46a763338ba545c0ab7db
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413982
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
@johnniwinther johnniwinther added the model-performance Performance/memory issues in analyzer/cfe label Mar 10, 2025
@jensjoha
Copy link
Contributor

@realth000 thank you for the data!
There are a surprising amount of "analysis.setAnalysisRoots" operations, e.g. between ~01:46:51 and ~1:55:38 (less than 9 minutes) there are 27 such requests which combined spend something like 4 minutes 22 seconds answering --- about half the timespan.
Do you have any idea what caused that?
The only way I can come up with is adding a new folder to the open "project" or something, but some of these requests are less than a second apart so I doubt that's it.

@realth000
Copy link

realth000 commented Mar 10, 2025

@jensjoha I restarted the dart analyzer server after dart run build_runner build -d because it doesn't include the generated code (this may be another topic, not in this issue), maybe the restart made things worse?

I have some git submodules in my repo, those are also dart projects.

You can clone my project here https://github.com/realth000/tsdm_client if you'd like to.

Some new info I found yesterday: the performance got much better when I disabled most configs in actions on save:

Image

Before, for the first and second config I chose "all files types" and Whole file. organize imports, rearrange code and Run code cleanup were enabled.
I think the stuck are directly caused by these IDE features.

@parnesen
Copy link

FWIW I have this issue too. I'm running Dart/Flutter/Serverpod in VS Code in Windows 11

@DanTup
Copy link
Collaborator

DanTup commented Mar 10, 2025

@parnesen please check the instructions in #55281 (comment) to collect a diagnostic report after you've reproduced the issue you're seeing.

If you can reproduce on something open source / public, then please provide details and repro steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-stability area-dart-model Use area-dart-model for issues related to packages analyzer, front_end, and kernel. model-performance Performance/memory issues in analyzer/cfe 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