question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VSCode + Flutter + Dart => Rename Symbol is really slow and sometimes not even working

See original GitHub issue

Rename symbol (shortcut key F2) in my flutter projects is really slow. Not sure if flutter is relevant of if this is a general dart problem. I think it is a dart problem so I’m posting here. When I have syntax/build errors I find it common that rename never finishes, the “infinite progress” in VS Code just keeps spinning what seems to be forever.

If I create a brand new (flutter) project: flutter create slow_refactor and then open the project, let everything initialize, pub get packages and let that complete as well. After this I go to main.dart, rename title to myTitle. This takes … 10? 15? seconds to complete. If I rename it to myTitle2 it takes a split second.

Can I mitigate this issue somehow? It’s really tedious to rename symbols and most often I just hit replace all feature instead because I’m convinced that the rename won’t work. Rename is such a common (simple) refactor that I expect it to work at all times.

I can’t find any known issues regarding this but I know that other members in my team have the same issue.

I’m running Windows 10, stable VS Code, flutter 1.13 and 1.14 (beta and master), dart 2.8.0-dev.3.0. My computer specs are category “great” so this is not due to slow cpu, disk or memory issues.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:40
  • Comments:38 (17 by maintainers)

github_iconTop GitHub Comments

5reactions
DanTupcommented, Feb 8, 2021

This week I found a performance bug in the LSP server that may be related. The issue was a combination of a few things:

  • We rebuild the data used to power the auto-import completions when the analysis roots (open folders) change
  • Opening files results in temporary analysis roots being created which triggers the rebuild mentioned above
  • VS Code sends a phantom “file open” event when you hold down Ctrl when hovering over a symbol (https://github.com/microsoft/vscode/issues/78453)

These things together can result in the server doing unnecessary work right when you’d want it to be doing other things (such as servicing a Ctrl+Click, or handling a file you’ve just opened).

The fix for that has landed in Flutter’s master branch. I wonder if anyone seeing these issues on is able to test whether temporarily switching to master seems to resolve this? (note: the first analysis of a project after changing branch will be slower, as the Flutter SDKs are seen for the first time). This appears to have helped for at least one user.

3reactions
mikeesouthcommented, Feb 27, 2020

I’ve been examining this for the last couple of weeks and it seems like it’s some kind of “startup” work (just as you’ve stated above). After the first rename, the following renames are more or less instant. However, this startup does not trigger for me until the first rename. I can open my project, work for 30 minutes, build, debug, open/close files, create classes, hot reloads etc - then I rename a symbol and it takes a long time (7 seconds in the above case). So this “startup” work isn’t triggered until the first rename.

Our project is currently 95 dart files (300k in total size). An interesting observation is that even if I’ve been running the project for say 30 or 60 minutes and then I rename a class or a field - it will take at least the above 7 seconds. But sometimes it takes more (e.g. 20 secs) and sometimes (quite often) it does not complete at all. I guess it’s a timeout after 30 seconds or so? If a rename times out the loading spinner in VS Code stops moving and no error message or other info is displayed (and the symbol isn’t renamed). If I try to rename the same thing (or something else) after this, it renames immediately. We are currently three people working on this project, we all have the same issue. Currently we’re using the beta branch (1.14.6) but we’ve had this problem for quite some time. I would say around version 1 and including current master (1.15).

Another observation is that “References: Find all references” (Shift + Alt + F12) has the same issue. Finding references for a symbol can take really long time and it often times out. I guess this triggers the same kind of “indexing” job that rename uses.

A workaround that is working for me is to trigger “Find all references” with my morning cup of coffee and keep VS Code open during the day.

I’d like to repro this with a open source project so I can provide easy steps to reproduce and no problems sharing the logs (considering that the logs may contain info about our project). I don’t have time to do that right now but hopefully in a couple of weeks or so.

Sorry for late responses in for this issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

VSCode + Flutter + Dart => Rename Symbol ... - Stack Overflow
Rename symbol (shortcut key F2) in my flutter projects is really slow. Not sure if flutter is relevant of if this is a...
Read more >
C++ intellisense/refactoring hangs and failures
Using the new completion engine on a C++, various operations are - sometimes - painfully slow. In particular, the Find All References feature...
Read more >
v3.48 - Dart Code - Dart & Flutter support for Visual Studio Code
Folder Renames​​ #2483: When using Flutter 3.3 / Dart 2.18, moving or renaming a single folder will now update import statements the same...
Read more >
rename | Dart Package - Pub.dev
Helps you to change or rename your flutter project BundleId and AppName for Ios, Android, MacOS and Linux platforms.
Read more >
VSCode Shortcuts, Extensions & Settings for Flutter ...
VSCode Extensions for Flutter Development · 1. Dart Data Class Generator · 2. Flutter Riverpod Snippets · 3. Error Lens · 4. Better...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found