Skip to content

Autocomplete is slow #3255

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

Open
feinstein opened this issue Mar 5, 2019 · 59 comments
Open

Autocomplete is slow #3255

feinstein opened this issue Mar 5, 2019 · 59 comments

Comments

@feinstein
Copy link

feinstein commented Mar 5, 2019

When I type any code in IntelliJ IDEA, it becomes marked with red squiggly lines, then some 2 seconds later it will generate some autocomplete options, it gets kinda annoying.

I understand the Dart support was made with a Dart Analysis Server, so at each new key I press, there will be some sort of client-server communication.

I also understand why this architecture was chosen, it's the best way to make something quickly and for every platform out there.

But maybe we should start thinking how to move forward from this so the performance and tweaking for IntelliJ could be improved.

Maybe the Dart Analysis Server could be embedded into the Dart plug-in, bypassing the client-server communications? I am not familiar with the whole architecture, just trying to figure out how to improve performance.

@pq
Copy link
Contributor

pq commented Mar 5, 2019

Thanks for the feedback.

@scheglov: what details would be useful for us to quantify the performance @feinstein is experiencing?

@scheglov
Copy link
Contributor

scheglov commented Mar 5, 2019

  1. How big is the file in which you type and get slow completions?
  2. How many other libraries import this file, directly or indirectly?
  3. How many libraries the file imports itself?
  4. What is your operating system?
  5. What version of Dart do you use?

@feinstein
Copy link
Author

feinstein commented Mar 5, 2019

  1. 10Kb, 300 lines
  2. and 3.
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

import 'package:myproject/blocs/authentication_bloc.dart';
import 'package:myproject/configurations/assets.dart';
  1. I am using a Dell Inspiron 13 7368 running Windows 10

Flutter 1.2.1 • channel stable • https://github.com/flutter/flutter.git Framework • revision 8661d8aecd (3 weeks ago) • 2019-02-14 19:19:53 -0800 Engine • revision 3757390fa4 Tools • Dart 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)

@scheglov
Copy link
Contributor

scheglov commented Mar 5, 2019

  1. 300 lines is not much, OK.
  2. This does not answer my question. You listed flutter libraries, I doubt they import the file where you have performance problem with completions.
  3. Again, I think there is misunderstanding. I asked which libraries the file imports.
  4. Can you try to remove C:\Users\<your_name>\AppData\Local\.dartServer (this is the cache of Analysis Server, we had reports of performance problems with it on Windows, and think that they are fixed, but might worth to reset it). Then restart the server.

@feinstein
Copy link
Author

Sorry, I didn't understand.

  1. None.
  2. This is the list of libraries the file imports at the beginning, isn't this what you asked for?

@scheglov
Copy link
Contributor

scheglov commented Mar 5, 2019

  1. This is weird. Then analysis and completions should be very fast.
  2. Ah, OK. Yes, this is what I asked. Again, not too many libraries, should be fast.

We can try to log analysis activity in Analysis Server.

  1. Triple-press Shift in IntelliJ.
  2. Search for Registry...
  3. Add to dart.server.additional.arguments: --new-analysis-driver-log=file:/Users/scheglov/tmp/444/analysis_driver.log
  4. Restart Analysis Server.
  5. Look in the file for suspiciously a lot of analysis or long time of analysis while you are completing.

@feinstein
Copy link
Author

Ok, will do, thanks!

@bossbeagle1509
Copy link

Deleting the dart analysis server files as suggested by @scheglov immediately fixed the problem. Thanks !

@cyberpwnn
Copy link

I have to clean out these files every day or else im waiting literally 10 seconds for autocomplete to even show up. Idea locks up. I've have tons of disposable cores to do this work on, and plenty of memory to store all of those files on a ramdisk, why is this still a problem?

@ultimate-tester
Copy link

ultimate-tester commented Jun 19, 2022

Just to keep this issue active, this is still a thing in 2022. Autocomplete and the context menu need at least 10 seconds (I keep bashing CTRL+ SPACE or ALT + ENTER until I get the results I expect to see) to work properly every time.

After using Flutter for a year, this is the stats of my .dartserver folder:
image

Deleting the entire .dartserver folder has unfortunately not solved this issue. I am experiencing the issue on my desktop with 16GB ram and 6 cores @ 3.60Ghz and consists of the following:

  • Slow autocomplete
  • Slow context menus
  • Slow syntax highlighting
  • On top of that, if I try context menu items like "replace child with children" or "add const modified" or any other menu item that would manipulate the code, 9 of of 10 times the new code ends up much higher in the file than where it's supposed to be causing a completely useless code.

image
Image portraying syntax highlighting issue

context_issue
GIF showing the context menu issue

@AleksMx
Copy link

AleksMx commented Oct 4, 2022

I have Core i9 with 16 CPU and 32 Gb RAM. After every 2-3 hot reloads, I get this picture for 3-4 seconds. In any project. Both in big ones and in hello world. The problem appeared a couple of months ago. It seems sometimes after a hot reload the analyzer starts re-analyzing all files in a project.

  1. .dartServer folder I removed
  2. Android Studio cache I cleaned

image

@Zohenn
Copy link

Zohenn commented Oct 4, 2022

I remember reading somebody stating that this was Windows only problem, but that claim should be verified. Happens to me and my friend, and we are both running Windows 10. At first I thought that this was a problem with my 25k lines project with many dependencies, but I was bummed to find out that the same exact thing happens in a fresh project.

@AleksMx What operating system are you using?

@pq
Copy link
Contributor

pq commented Oct 4, 2022

@scheglov, @bwilkerson: FYI and should we transfer this to the SDK repo?

@Elixell
Copy link

Elixell commented Oct 4, 2022

I have Core i9 with 16 CPU and 32 Gb RAM. After every 2-3 hot reloads, I get this picture for 3-4 seconds. In any project. Both in big ones and in hello world. The problem appeared a couple of months ago. It seems sometimes after a hot reload the analyzer starts re-analyzing all files in a project.

  1. .dartServer folder I removed
  2. Android Studio cache I cleaned

image

Three of us working on windows 11 (IntellIj IDEA Ultimate) have the same problem. A tried the above mentiond solutions (cache and dartServer folder removing) but didn't work. Also the context menu for the widget tree manipulations is dead for seconds a lot.

@ultimate-tester
Copy link

ultimate-tester commented Oct 4, 2022

Small update: in my case I found that pressing CTRL + ALT + L fixes the issue once. So every time I have issues with context menus or syntax highlighting I bash those keys and it works again.

To provide to the investigation: I am on windows 10.

@feinstein
Copy link
Author

This shortcut is for auto formatting, that's not something I would want to do all the time.

I face this issue on a regular basis with all my computers, personal or work laptop, both with windows 10

@azimuthdeveloper
Copy link

I also experience this in Android Studio, Intel i9 12900 with 32GB of RAM. Really affects productivity. How can we help resolve this issue?

@AleksMx
Copy link

AleksMx commented Nov 5, 2022

This is terrible. A significant number of developers experience difficulties at work. And we have a reduced priority of solving the problem

@AleksMx
Copy link

AleksMx commented Nov 5, 2022

image

My error appears as follows. When I connect an Android smartphone via USB and run an application on it in debug mode. That is, during the saving of changes in the code, a hot reload occurs. At this point, sometimes this bug occurs, which blocks the work for 5 seconds. This is very annoying!

I ran the following command:
flutter analyze --watch -v

It can be seen from it that after saving there are no delays from the work of the dart server.

The problem is somehow connected with hot reload. Change is happening quickly, but something is blocking the work. Let's think about how to catch the error. Otherwise, what are we all here for?

@pq
Copy link
Contributor

pq commented Nov 7, 2022

/fyi @jwren @kenzieschmoll

@esDotDev
Copy link

I have Core i9 with 16 CPU and 32 Gb RAM. After every 2-3 hot reloads, I get this picture for 3-4 seconds. In any project. Both in big ones and in hello world. The problem appeared a couple of months ago. It seems sometimes after a hot reload the analyzer starts re-analyzing all files in a project.

  1. .dartServer folder I removed
  2. Android Studio cache I cleaned

image

Three of us working on windows 11 (IntellIj IDEA Ultimate) have the same problem. A tried the above mentiond solutions (cache and dartServer folder removing) but didn't work. Also the context menu for the widget tree manipulations is dead for seconds a lot.

This is happening to me as well and has made code-complete almost unusable.

What I have to do now is hit the "Alt" and then wait for 2-5 seconds, until the lightbulb shows up, then I can hit "Enter" to bring up code complete.

@jacob314
Copy link
Contributor

Fyi @srawlins

@Sese-Schneider
Copy link

+1 for usability issues. A lot of our orgs developers experience very slow autocomplete with Flutter in our large codebase (70k+ LOC)

@feinstein
Copy link
Author

I would love that the language server could be optimized to give intellij all it needs to bring all the tools Java have to Dart. All the times that I asked for something that exists for Java, to be ported for dart, the guys at intellij says they can't because the language server doesn't provide them with the information, os something similar.

@esDotDev
Copy link

esDotDev commented Nov 16, 2022

It really sucks cause I almost am being forced to switch to VSCode, even though I prefer Android Studio in a wide number of ways, ever since upgrading a few months ago everything just went to shit, and at least VSCode is fast.

It does feel like VSCode gets a lot more attention because that is what the core Flutter team uses. I doubt this would still be an issue if any members of the Flutter team actually used AS on a regular basis as it really kills the programming flow.

Maybe I will try some older versions and see if we can at least pin-point when everything went south.

It does seem to be related to trying to do code-assist, while an existing error is present in the code, but haven't been able to narrow down and specific reproduction steps.

@feinstein
Copy link
Author

I also have this behavior all the time, for years now.

@srawlins I understand your points and think it's very valid. But at the same time it's what you said, if we improve the root (language server and analyze) it probably will fix all the rest.

@scheglov
Copy link
Contributor

I wonder if this is caused by https://github.com/dart-lang/sdk/blob/27d417dc0937bb1a8f1ae6d12754a95adf488364/pkg/analysis_server/lib/src/legacy_analysis_server.dart#L348 See also the comment above that describes why we decided to implement it. But if it causes issues for many external users, we might want to avoid it. Or it could be unrelated...

@pq
Copy link
Contributor

pq commented Nov 16, 2022

Thanks @esDotDev!

It really sucks cause I almost am being forced to switch to VSCode, even though I prefer Android Studio in a wide number of ways, ever since upgrading a few months ago everything just went to shit, and at least VSCode is fast.

To confirm: you don't see the same issues with VSCode on the same code base?

@bwilkerson
Copy link

do we have instructions on opening the diagnostics page the Code Completion page and the diagnostics pages in general? Specifically for IntelliJ users?

I'm not aware of any documentation, but from IntelliJ and Android Studio, open the Dart Analysis view, click on the gear icon, and select "View analyzer diagnostics".

I wonder if this is caused by ...

10 seconds is a long time. It might be worth adding a flag to disable it so that users can try turning it off and let us know whether it helps.

@esDotDev
Copy link

esDotDev commented Nov 16, 2022

To confirm: you don't see the same issues with VSCode on the same code base?

Nope, VSCode is very fast.

As an example, look how long the lightbulb takes to show up here (until lightbulb shows up, I won't get valid code-assist for Flutter):
T1LwJhyNvi
Looks ~2500ms

Now, same code in VSCode:
L1HqtHaY55
Looks ~300ms

This is on a Ryzen 7 3700X w/ 32GB ram, PC utilization overall is very low:
Taskmgr_yidLLB4nrQ

@pq
Copy link
Contributor

pq commented Nov 16, 2022

This is really helpful. Thank you!

@esDotDev
Copy link

nw! If it's helpful, you can view this codebase in question here: https://github.com/gskinnerTeam/flutter-wonderous-app but from my experience, it's any codebase of any size

@pq
Copy link
Contributor

pq commented Nov 16, 2022

Much appreciated @esDotDev! Does wonderous development get unusably slow (that is beyond the 2s lag in the video above)? I've got that reproduced locally but haven't seen anything worse after some casual edits. Does running the app and triggering reloads have any effect? (I haven't successfully run ios or android just yet myself but will try and debug tomorrow.)

@esDotDev
Copy link

esDotDev commented Nov 16, 2022

Well it does that thing like this often after a save, and then formatting correctly after 3+ seconds:
image

I don't know that it's related but it seems to have started at the same time as this general slowness. It is the kindof thing you would not notice if the delay was 300ms, but becomes super obvious when the delay is multiple seconds.

I've found I can usually fix it by closing the file and re-opening, which is often faster than waiting for it to properly parse the code.

I haven't noticed any relationship to reloads, but I am always reloading so it would be hard to say :)

It's still "useable", but I have to be very deliberate / patient, and really look for that lightbulb icon to appear before hitting alt+enter.

@mariusvn
Copy link

Well it does that thing like this often after a save, and then formatting correctly after 3+ seconds: image

I don't know that it's related but it seems to have started at the same time as this general slowness. It is the kindof thing you would not notice if the delay was 300ms, but becomes super obvious when the delay is multiple seconds.

I've found I can usually fix it by closing the file and re-opening, which is often faster than waiting for it to properly parse the code.

I haven't noticed any relationship to reloads, but I am always reloading so it would be hard to say :)

It's still "useable", but I have to be very deliberate / patient, and really look for that lightbulb icon to appear before hitting alt+enter.

same issue here, really slowing my work.

Also while the syntax highlighing is bugged, the autocomplete or any suggestion don't work at all.

It happens when saving

@pq
Copy link
Contributor

pq commented Nov 17, 2022

This is all super useful. Thanks!

Do you happen to have any plugins installed that might kick things off on a save (for example https://plugins.jetbrains.com/plugin/13666-flutter-intl)? Do you have any save actions setup?

@pq
Copy link
Contributor

pq commented Nov 17, 2022

@esDotDev: I'd be interested to see the communication between our language server and the IDE. There could be some clues there.

If you wouldn't mind enabling logging and sending what you capture when see this lag, that'd be great. (Do note that this file will include full paths so you'll want to scan it to make sure there's nothing sensitive.)

This post explains how to turn on instrumentation in IntelliJ:

https://intellij-support.jetbrains.com/hc/en-us/community/posts/4407710497682-Dart-analysis-server-log

@esDotDev
Copy link

This is a long session, but right before I saved it, I lost code analysis on a file for 5 seconds+, I was just moving my cursor around and all of a sudden highlighting broke (maybe this was some background task finishing from a recent save?).

I inserted a new line, and that seemed to prompt code formatting to pop back in properly:
flutter_ide_issues - lost code analysis for a few seconds after save.txt

@esDotDev
Copy link

esDotDev commented Nov 18, 2022

Captured some pretty good footage here, and some repro steps maybe?

All I do here:

  • Two projects are open at once
    • One is /example so it exists inside the other
  • I duplicate a line in one project, save, and then focus into the other project

Going back and forth you can see it happen often, near the end, from 0:22 - 0:33 the project on the right is exhibiting the issue:

dPTBdYEzMA.mp4

Here's another much smaller log where it happened twice within a couple minutes of re-starting android studio.
flutter_ide_issues - issues after save.txt

@AleksMx
Copy link

AleksMx commented Nov 20, 2022

Sorry for the lack of attention here. We're looking to allocate resources to look at issues like this.

There is a small problem with this specific issue though, which is that it has become a waste bin issue; it is no longer focused. What is titled "Autocomplete is slow" is now filled with comments about time-to-analyze, or time-to-code-assist, or syntax highlighting bad state bugs. These are all legitimate issues. I don't fault anyone for piling on as this is an active thread. Anyone experiencing any of these is certainly experiencing an unintentional bad time, and that sucks and fixes should be made. But to address what is more than likely a myriad of issues, we need separate issues with separate reproductions.

I encourage anyone who can readily reproduce your issue above to please file an issue at https://github.com/dart-lang/sdk/issues, and tag me. Include as much detail as you can: flutter doctor, repro steps; code checkout if you see this working on open source. (It is of course possible that the some performance bugs are in this flutter/flutter-intellij repo; but honestly it the roots are more likely on the Dart / Dart Analysis Server / analyzer side, as that is where work is being done. flutter/flutter-intellij should be a pretty thin layer in the static analysis stack. If duplicate issues get filed, I can worry about deduplicating; please just file an individual issue for specific problems.

I can also look into this issue above, with a narrow focus on autocomplete.

@bwilkerson do we have instructions on opening the diagnostics page the Code Completion page and the diagnostics pages in general? Specifically for IntelliJ users?

Yes, there are several problems described here, but the root is the same. Race condition on the IDE side, which leads to blocking - syntax highlighting or autocomplete (it doesn't matter). This is not a dartServer issue.

@AleksMx
Copy link

AleksMx commented Nov 20, 2022

I wonder if this is caused by https://github.com/dart-lang/sdk/blob/27d417dc0937bb1a8f1ae6d12754a95adf488364/pkg/analysis_server/lib/src/legacy_analysis_server.dart#L348 See also the comment above that describes why we decided to implement it. But if it causes issues for many external users, we might want to avoid it. Or it could be unrelated...

This is very similar to the source of the problem. There is a feeling that sometimes saving a file leads to blocking of some process. But as I showed above, the work of dartServer is already done by this time.

@pq
Copy link
Contributor

pq commented Nov 23, 2022

Race condition on the IDE side, which leads to blocking - syntax highlighting or autocomplete (it doesn't matter). This is not a dartServer issue.

/fyi @jwren @alexander-doroshko

@srawlins
Copy link
Contributor

Thanks for the details. I am trying to reproduce, without success so far, so I have more questions :)

@esDotDev:

  1. @pq asked earlier:

    Do you happen to have any plugins installed that might kick things off on a save (for example https://plugins.jetbrains.com/plugin/13666-flutter-intl)? Do you have any save actions setup?

    But I didn't see an answer from you.

  2. Can you confirm your versions of a few things:

    • IntelliJ or Android Studio? What version?
    • Flutter plugin version (under Preferences > Plugins, I have 71.0.2)
    • Under Preferences > Languages & Frameworks > Flutter, do you have "Perform hot reload on Save" checked? (As per @AleksMx's theory) Are you running an emulator or simulator?
  3. You pointed to https://github.com/gskinnerTeam/flutter-wonderous-app as an example reproduction repo, but this does not follow the "package within a package" reproduction you mentioned here. I also can't find any files in wonderous with Widget getTopArea which you have in some of your screenshots. Do you have a different reproduction I can try? I'm not able to reproduce any problem in wonderous, but I'm also not hot reloading.

  4. Do you have any analyzer plugins in play? These would be found in a project's analysis_options.yaml file; one common one is dart_code_metrics.

@AleksMx:

Yes, there are several problems described here, but the root is the same. Race condition on the IDE side, which leads to blocking - syntax highlighting or autocomplete (it doesn't matter). This is not a dartServer issue.

I've re-read the comments above (but its hard to get a cohesive stream), and I can't quite connect the proof that this is a problem in IntelliJ (or Android Studio?) or the Flutter plugin for IntelliJ. I think you've shown that the delays are tied to hot reload, but I'm not sure that this is a requirement in other commenter's reproduction cases. (But again, people are reporting many issues here.) For example in the initial (4-year-old) summary above, @feinstein does not mention hot reload. If you have good reproductions that are tied to hot reload, I recommend opening a new issue with reproduction steps.

One common thread in some comments above does seem to tie the slowness at least to saving a file, which could trigger hot reload, certainly. But the issue could be tied to something else which is part of the saving process, like maybe "format on save", or a file watch event that comes into Dart Analysis Server as part of a save...

@feinstein
Copy link
Author

When I first started this thread only the auto-complete was slow, but after all these years I am also seeing the hot reload issue, where the text colors get weird.

@srawlins if you want we can jump into a Google Meet call and I can show you.

@alexander-doroshko
Copy link
Contributor

alexander-doroshko commented Nov 29, 2022

Hi from JetBrains. We now know that the weird highlighting after save is related to CRLF line endings.
image

Note that this is not connected with slow completion or whatever else discussed here. It's a separate isolated bug.

I haven’t managed to reproduce it so far so I can't say for sure where the bug is. Let's track it in the Dart plugin issue tracker: https://youtrack.jetbrains.com/issue/WEB-56916.

The workaround is to switch to LF line endings. The widget in the IDE status bar allows to do it easily per file (any OS). IDE also allows to change line separators for a specific folder of for the whole project (Find Action -> Line Separators).

So now there's one less problem to track within this issue.

@feinstein
Copy link
Author

Great! So now we can focus on performance?

@AleksMx
Copy link

AleksMx commented Nov 30, 2022

I have a good news!

By advice @alexander-doroshko I changed line separators from CRLF to LF. Just chose an option in the bottom menu.

Previously, after 4-5 hot reloads, syntax highlighting and autocomplete was blocked:
image

Now everything works as it should:
image

This explains why the issue only affects Windows users.

@esDotDev
Copy link

I switched to LF yesterday across the entire project, and it seems to be running fast again. Will update if the issue re-appears.

@AleksMx
Copy link

AleksMx commented Nov 30, 2022

The final solution to my problem:

image
image

@mariusvn
Copy link

mariusvn commented Dec 1, 2022

I confirm its works on my side too

@EduardoYamauchi
Copy link

Worked for me. My team and I are suffering with this problem years.

Following the instructions, I switched from CRLF to LF and it worked successfully. It appears that CRLF might cause performance problems with Dart.

How to convert your project

1 - Go to IntelliJ settings. File > Settings > Code Style.
2 - In the Line Separator option: select Unix and macOS (\n).
3 - In the project root, create a file named .gitattributes.
4 - In the file, insert the following code:

# Ensure all dart files use LF.
text=auto
*.dart eol=lf

5 - Commit this file.
6 - Clear the git cache with the following commands in the terminal:

git rm --cached -r .
git reset --hard

7 - Click on the folders/files you want to convert. With them selected, click on File > File Properties > Line Separators > LF - Unix and macOS (\n).

Done, the selected files/folders will be converted and new files will be create using LF.

@esDotDev
Copy link

esDotDev commented Apr 5, 2023

Thanks for this, while changing line ending fixes the issue, there is no way in the IDE to set the default for new files, so it was really annoying having to set this by hand in each project.

Will give this a shot!

@mahdiqdi
Copy link

mahdiqdi commented Apr 20, 2025

after upgrading to latest version of flutter (v3.29.3) my android studio is too laggy. auto complete and syntax highlighting does not work properly. note that with previous version of flutter (v3.24.0) everything was ok.
can anyone help me to fix this issue?
line separator is in LF mode also

@bwilkerson
Copy link

after upgrading to latest version of flutter (v3.29.3) ...

That sounds like it might be this issue: dart-lang/sdk#60335.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests