VSCode + Flutter + Dart => Rename Symbol is really slow and sometimes not even working
See original GitHub issueRename 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:
- Created 4 years ago
- Reactions:40
- Comments:38 (17 by maintainers)
Top GitHub Comments
This week I found a performance bug in the LSP server that may be related. The issue was a combination of a few things:
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.
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!