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

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.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 44
  • Comments: 45 (20 by maintainers)

Most upvoted 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:

  • 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.

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!

In my case, it seemed like the problem was with cache, because restarting the server and then renaming would take less

@DanTup I run into this issue all the time as well. Freshly opened VSCode, everything works fine, but after 30-60 minutes of coding and hot reload work, the analysis server will come to a screeching halt. All intellisense becomes unresponsive or very delayed. It is weird because the problem gets resolved simply by closing VSCode and reopening. Same exact code will work just fine and analyzer will run through quick once I reopen. As I keep working, it will happen again and I need to close and reopen (just that, no other actions besides close/reopen).

So… I am wondering if it is related to something that the analysis server is caching? Does this sound familiar? Is there anything that the end user can change in the extension settings?

One more thing I will mention is that in the process of trying to see what the analyzer was doing, I enabled dart.analyzerInstrumentationLogFile. Nothing stood out (not to me at least), but I did notice that this file would grow VERY quickly. By the time I am done with one of my sessions and noticing that the analyzer was slowing down, the log file would reach multiple GBs in size. Yes… that is GBs. I have since disabled that setting because eventually that file is impossible to open in any text editor. Just wondering if the analysis server is doing similar caching to what is in the log file and trying to parse through some ever growing cache which is why it slows down as you work?

I have been trying to chase this issue for weeks. I saw something about the possibility that imports may be causing an issue for the analysis server. For example if the code base imports lots of libraries as opposed to single widgets from those libraries? I tend to break out my widgets into many file as part of a single library and import that entire library when it is needed. For context, this specific repo has a lib/ folder with 136 files. I suppose that is not “small” but it certainly is not unreasonable amount of files to house the source code of an entire app.

Even if that was an issue, why does that only happen after some time in the analysis server, it does not manifest right away so there seems to be some link to amount of time the analysis sever is running (which is why I mentioned cache).

@DanTup any information or insight you can provide would be incredibly helpful! This has been driving me up a wall for quite some time and has really hampered productivity.

Your log only shows traffic to the server, nothing from it - which certainly makes it seem like the server is busy. Are you able to provide a more complete log, that includes the last things from the server (they will contain <== instead of ==>) as it may be useful to understand what the last requests to the server were when it seemed to stop responding.

Hoping this helps. In this case, I restarted the server like @samandmoore mentioned, hit refactor (rename), and it seemed to hang for 8-10 seconds, so I did another refactor (rename) and it worked almost instantly. Not sure if there are any useful logs here, but there is traffic from the server. Perhaps something in the initial traffic to the server is indicative of the problem with the initial hang?

Logs
Dart Code extension: 3.22.0
Flutter extension: 3.22.0 (activated)

App: Visual Studio Code
Version: 1.56.2
Platform: mac

Workspace type: Dart, Flutter
Analyzer type: LSP
Multi-root?: false

Dart SDK:
    Loc: /Users/brandontrautmann/fvm/versions/2.2.0-10.2.pre/bin/cache/dart-sdk
    Ver: 2.13.0-211.13.beta
Flutter SDK:
    Loc: /Users/brandontrautmann/fvm/versions/2.2.0-10.2.pre
    Ver: 2.2.0-10.2.pre

HTTP_PROXY: undefined
NO_PROXY: undefined

Logging Categories:
    General, Analyzer

Tue May 18 2021 [11:45:32 GMT-0400 (Eastern Daylight Time)] Log file started
[11:45:34 AM] [Analyzer] [Info] ==> Content-Length: 217
[11:45:34 AM] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":5,"method":"textDocument/hover","params":{"textDocument":{"uri":"file:///Users/brandontrautmann/src/mobile/flutter/app/lib/widgets/home/embedded_home.dart"},"position":{"line":43,"character":9}}}
[11:45:35 AM] [Analyzer] [Info] ==> Content-Length: 62
[11:45:35 AM] [Analyzer] [Info] ==> {"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":5}}
[11:45:35 AM] [Analyzer] [Info] ==> Content-Length: 292
[11:45:35 AM] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":6,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///Users/brandontrautmann/src/mobile/flutter/app/lib/widgets/home/embedded_home.dart"},"range":{"start":{"line":44,"character":14},"end":{"line":44,"character":14}},"context":{"diagnostics":[]}}}
[11:45:35 AM] [Analyzer] [Info] ==> Content-Length: 62
[11:45:35 AM] [Analyzer] [Info] ==> {"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":2}}
[11:45:35 AM] [Analyzer] [Info] ==> Content-Length: 226
[11:45:35 AM] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":7,"method":"textDocument/prepareRename","params":{"textDocument":{"uri":"file:///Users/brandontrautmann/src/mobile/flutter/app/lib/widgets/home/embedded_home.dart"},"position":{"line":44,"character":14}}}
[11:45:39 AM] [Analyzer] [Info] ==> Content-Length: 62
[11:45:39 AM] [Analyzer] [Info] ==> {"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":7}}
[11:45:40 AM] [Analyzer] [Info] ==> Content-Length: 292
[11:45:40 AM] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":8,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///Users/brandontrautmann/src/mobile/flutter/app/lib/widgets/home/embedded_home.dart"},"range":{"start":{"line":44,"character":13},"end":{"line":44,"character":13}},"context":{"diagnostics":[]}}}
[11:45:40 AM] [Analyzer] [Info] ==> Content-Length: 62
[11:45:40 AM] [Analyzer] [Info] ==> {"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":6}}
[11:45:40 AM] [Analyzer] [Info] ==> Content-Length: 226
[11:45:40 AM] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":9,"method":"textDocument/prepareRename","params":{"textDocument":{"uri":"file:///Users/brandontrautmann/src/mobile/flutter/app/lib/widgets/home/embedded_home.dart"},"position":{"line":44,"character":10}}}
[11:45:40 AM] [Analyzer] [Info] ==> Content-Length: 293
[11:45:40 AM] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":10,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///Users/brandontrautmann/src/mobile/flutter/app/lib/widgets/home/embedded_home.dart"},"range":{"start":{"line":44,"character":10},"end":{"line":44,"character":10}},"context":{"diagnostics":[]}}}
[11:45:40 AM] [Analyzer] [Info] ==> Content-Length: 62
[11:45:40 AM] [Analyzer] [Info] ==> {"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":8}}
[11:45:41 AM] [Analyzer] [Info] <== Content-Length: 1057
Content-Type: application/vscode-jsonrpc; charset=utf-8
[11:45:41 AM] [Analyzer] [Info] <== {"id":4,"jsonrpc":"2.0","result":[{"startLine":5,"startCharacter":43,"endLine":16,"endCharacter":0},{"startLine":18,"startCharacter":54,"endLine":54,"endCharacter":0},{"startLine":20,"startCharacter":20,"endLine":25,"endCharacter":2},{"startLine":22,"startCharacter":51,"endLine":24,"endCharacter":5},{"startLine":22,"startCharacter":56,"endLine":24,"endCharacter":4},{"startLine":28,"startCharacter":38,"endLine":41,"endCharacter":2},{"startLine":29,"startCharacter":24,"endLine":40,"endCharacter":4},{"startLine":31,"startCharacter":25,"endLine":39,"endCharacter":6},{"startLine":32,"startCharacter":22,"endLine":38,"endCharacter":8},{"startLine":33,"startCharacter":21,"endLine":36,"endCharacter":10},{"startLine":43,"startCharacter":88,"endLine":53,"endCharacter":2},{"startLine":45,"startCharacter":35,"endLine":51,"endCharacter":4},{"startLine":46,"startCharacter":50,"endLine":47,"endCharacter":89},{"startLine":48,"startCharacter":14,"endLine":49,"endCharacter":49},{"startLine":0,"startCharacter":6,"endLine":3,"endCharacter":48,"kind":"imports"}]}
[11:45:41 AM] [Analyzer] [Info] <== Content-Length: 186
Content-Type: application/vscode-jsonrpc; charset=utf-8
[11:45:41 AM] [Analyzer] [Info] <== {"method":"textDocument/publishDiagnostics","params":{"uri":"file:///Users/brandontrautmann/src/mobile/flutter/app/lib/widgets/home/embedded_home.dart","diagnostics":[]},"jsonrpc":"2.0"}
[11:45:41 AM] [Analyzer] [Info] <== Content-Length: 487
Content-Type: application/vscode-jsonrpc; charset=utf-8
[11:45:41 AM] [Analyzer] [Info] <== {"method":"dart/textDocument/publishClosingLabels","params":{"uri":"file:///Users/brandontrautmann/src/mobile/flutter/app/lib/widgets/home/embedded_home.dart","labels":[{"range":{"start":{"line":29,"character":11},"end":{"line":40,"character":5}},"label":"WillPopScope"},{"range":{"start":{"line":31,"character":13},"end":{"line":39,"character":7}},"label":"AppScaffold"},{"range":{"start":{"line":32,"character":14},"end":{"line":38,"character":9}},"label":"InkWell"}]},"jsonrpc":"2.0"}
[11:45:41 AM] [Analyzer] [Info] <== Content-Length: 4404
Content-Type: application/vscode-jsonrpc; charset=utf-8
[11:45:41 AM] [Analyzer] [Info] <== {"method":"dart/textDocument/publishOutline","params":{"uri":"file:///Users/brandontrautmann/src/mobile/flutter/app/lib/widgets/home/embedded_home.dart","outline":{"element":{"range":{"start":{"line":0,"character":0},"end":{"line":55,"character":0}},"name":"<unit>","kind":"COMPILATION_UNIT"},"range":{"start":{"line":0,"character":0},"end":{"line":55,"character":0}},"codeRange":{"start":{"line":0,"character":0},"end":{"line":55,"character":0}},"children":[{"element":{"range":{"start":{"line":5,"character":6},"end":{"line":5,"character":18}},"name":"EmbeddedHome","kind":"CLASS"},"range":{"start":{"line":5,"character":0},"end":{"line":16,"character":1}},"codeRange":{"start":{"line":5,"character":0},"end":{"line":16,"character":1}},"children":[{"element":{"range":{"start":{"line":6,"character":8},"end":{"line":6,"character":20}},"name":"EmbeddedHome","kind":"CONSTRUCTOR","parameters":"({Key key, @required this.embeddedFeatureManager})"},"range":{"start":{"line":6,"character":2},"end":{"line":10,"character":24}},"codeRange":{"start":{"line":6,"character":2},"end":{"line":10,"character":24}}},{"element":{"range":{"start":{"line":12,"character":31},"end":{"line":12,"character":53}},"name":"embeddedFeatureManager","kind":"FIELD","returnType":"EmbeddedFeatureManager"},"range":{"start":{"line":12,"character":2},"end":{"line":12,"character":54}},"codeRange":{"start":{"line":12,"character":31},"end":{"line":12,"character":53}}},{"element":{"range":{"start":{"line":15,"character":21},"end":{"line":15,"character":32}},"name":"createState","kind":"METHOD","parameters":"()","returnType":"_EmbeddedHomeState"},"range":{"start":{"line":14,"character":2},"end":{"line":15,"character":59}},"codeRange":{"start":{"line":15,"character":2},"end":{"line":15,"character":59}}}]},{"element":{"range":{"start":{"line":18,"character":6},"end":{"line":18,"character":24}},"name":"_EmbeddedHomeState","kind":"CLASS"},"range":{"start":{"line":18,"character":0},"end":{"line":54,"character":1}},"codeR…
[11:45:41 AM] [Analyzer] [Info] <== Content-Length: 4586
Content-Type: application/vscode-jsonrpc; charset=utf-8

{"method":"dart/textDocument/publishFlutterOutline","params":{"uri":"file:///Users/brandontrautmann/src/mobile/flutter/app/lib/widgets/home/embedded_home.dart","outline":{"kind":"DART_ELEMENT","dartElement":{"range":{"start":{"line":0,"character":0},"end":{"line":55,"character":0}},"name":"<unit>","kind":"COMPILATION_UNIT"},"range":{"start":{"line":0,"character":0},"end":{"line":55,"character":0}},"codeRange":{"start":{"line":0,"character":0},"end":{"line":55,"character":0}},"children":[{"kind":"DART_ELEMENT","dartElement":{"range":{"start":{"line":5,"character":6},"end":{"line":5,"character":18}},"name":"EmbeddedHome","kind":"CLASS"},"range":{"start":{"line":5,"character":0},"end":{"line":16,"character":1}},"codeRange":{"start":{"line":5,"character":0},"end":{"line":16,"character":1}},"children":[{"kind":"DART_ELEMENT","dartElement":{"range":{"start":{"line":6,"character":8},"end":{"line":6,"character":20}},"name":"EmbeddedHome","kind":"CONSTRUCTOR","parameters":"({Key key, @required this.embeddedFeatureManager})"},"range":{"start":{"line":6,"character":2},"end":{"line":10,"character":24}},"codeRange":{"start":{"line":6,"character":2},"end":{"line":10,"character":24}}},{"kind":"DART_ELEMENT","dartElement":{"range":{"start":{"line":12,"character":31},"end":{"line":12,"character":53}},"name":"embeddedFeatureManager","kind":"FIELD","returnType":"EmbeddedFeatureManager"},"range":{"start":{"line":12,"character":2},"end":{"line":12,"character":54}},"codeRange":{"start":{"line":12,"character":31},"end":{"line":12,"character":53}}},{"kind":"DART_ELEMENT","dartElement":{"range":{"start":{"line":15,"character":21},"end":{"line":15,"character":32}},"name":"createState","kind":"METHOD","parameters":"()","returnType":"_EmbeddedHomeState"},"range":{"start":{"line":14,"character":2},"end":{"line":15,"character":59}},"codeRange":{"start":{"line":15,"character":2},"end":{"line":15,"character":59}}}…
[11:45:41 AM] [Analyzer] [Info] <== Content-Length: 118
Content-Type: application/vscode-jsonrpc; charset=utf-8

{"method":"$/progress","params":{"token":"ANALYZING","value":{"kind":"begin","title":"Analyzing…"}},"jsonrpc":"2.0"}Content-Length: 1968
Content-Type: application/vscode-jsonrpc; charset=utf-8

{"id":1,"jsonrpc":"2.0","result":[{"name":"EmbeddedHome","kind":5,"deprecated":false,"range":{"start":{"line":5,"character":0},"end":{"line":16,"character":1}},"selectionRange":{"start":{"line":5,"character":6},"end":{"line":5,"character":18}},"children":[{"name":"EmbeddedHome","detail":"({Key key, @required this.embeddedFeatureManager})","kind":9,"deprecated":false,"range":{"start":{"line":6,"character":2},"end":{"line":10,"character":24}},"selectionRange":{"start":{"line":6,"character":8},"end":{"line":6,"character":20}}},{"name":"embeddedFeatureManager","kind":8,"deprecated":false,"range":{"start":{"line":12,"character":31},"end":{"line":12,"character":53}},"selectionRange":{"start":{"line":12,"character":31},"end":{"line":12,"character":53}}},{"name":"createState","detail":"()","kind":6,"deprecated":false,"range":{"start":{"line":15,"character":2},"end":{"line":15,"character":59}},"selectionRange":{"start":{"line":15,"character":21},"end":{"line":15,"character":32}}}]},{"name":"_EmbeddedHomeState","kind":5,"deprecated":false,"range":{"start":{"line":18,"character":0},"end":{"line":54,"character":1}},"selectionRange":{"start":{"line":18,"character":6},"end":{"line":18,"character":24}},"children":[{"name":"initState","detail":"()","kind":6,"deprecated":false,"range":{"start":{"line":20,"character":2},"end":{"line":25,"character":3}},"selectionRange":{"start":{"line":20,"character":7},"end":{"line":20,"character":16}}},{"name":"build","detail":"(BuildContext context)","kind":6,"deprecated":false,"range":{"start":{"line":28,"character":2},"end":{"line":41,"character":3}},"selectionRange":{"start":{"line":28,"character":9},"end":{"line":28,"character":14}}},{"name":"_onFeatureStarted","detai…
[11:45:41 AM] [Analyzer] [Info] <== Content-Length: 1278
Content-Type: application/vscode-jsonrpc; charset=utf-8

{"id":3,"jsonrpc":"2.0","result":{"data":[0,0,6,1,0,0,7,43,14,0,1,0,6,1,0,0,7,31,14,0,1,0,6,1,0,0,7,32,14,0,1,0,6,1,0,0,7,40,14,0,2,0,5,1,0,0,6,12,2,0,0,13,7,1,0,0,8,14,2,0,1,8,12,2,0,1,4,3,2,0,0,4,3,5,2,1,4,1,0,0,0,1,8,9,0,0,14,22,4,0,1,15,22,5,0,0,26,4,1,0,1,8,5,1,0,0,6,3,5,16,0,5,3,5,0,2,2,5,1,0,0,6,22,2,0,0,23,22,4,2,2,2,1,0,0,0,1,8,9,0,1,2,18,2,0,0,19,11,10,2,0,17,18,2,0,3,0,5,1,0,0,6,18,2,0,0,19,7,1,0,0,8,5,2,0,0,6,12,2,0,1,2,1,0,0,0,1,8,9,0,1,2,4,1,0,0,5,9,10,2,1,10,9,10,0,1,4,16,2,0,0,17,8,9,4,0,9,20,10,0,0,22,1,5,2,1,6,6,9,0,0,7,22,9,0,0,23,4,10,0,0,5,17,10,0,4,2,1,0,0,0,1,8,9,0,1,2,6,2,0,0,7,5,10,2,0,6,12,2,0,0,13,7,5,2,1,4,6,1,8,0,7,12,2,0,1,6,9,5,16,0,14,5,1,8,0,9,5,12,0,1,6,5,5,16,0,7,11,2,0,1,8,4,5,16,0,6,7,2,0,1,10,5,5,16,1,12,5,15,0,0,6,45,14,0,1,12,6,9,0,0,7,22,9,0,0,23,9,10,0,2,10,5,5,16,0,7,5,1,0,0,6,8,2,0,0,9,6,2,0,6,2,6,2,0,0,7,4,1,0,0,6,17,10,2,0,18,26,2,0,0,27,19,5,2,0,21,5,1,8,1,4,5,1,0,0,6,5,4,2,0,8,19,5,0,0,20,7,9,0,0,8,7,10,0,1,4,5,1,0,0,6,6,4,2,0,9,5,1,8,0,9,5,1,8,1,6,2,1,8,0,4,19,5,0,0,20,17,9,0,1,8,6,1,8,0,7,9,2,0,0,10,2,10,4,0,3,7,9,0,0,9,18,10,0,0,19,5,4,0,0,8,5,5,2,0,10,5,5,0,0,6,7,9,0,1,8,4,1,8,1,8,6,1,8,0,7,9,2,0,0,10,2,10,4,0,3,7,9,0,0,9,4,10,0,0,5,5,4,0,3,4,6,9,0,0,7,22,9,0,0,23,11,10,0,0,12,19,5,0,0,20,7,9,0,0,9,6,4,0]}}Content-Length: 82
Content-Type: application/vscode-jsonrpc; charset=utf-8

{"id":2,"jsonrpc":"2.0","error":{"code":-32800,"message":"Request was cancelled"}}Content-Length: 82
Content-Type: application/vscode-jsonrpc; charset=utf-8

{"id":5,"jsonrpc":"2.0","error":{"code":-32800,"message":"Request was cancelled"}}Content-Length: 82
Content-Type: application/vscode-jsonrpc; charset=utf-8

{"id":7,"jsonrpc":"2.0","error":{"code":-32800,"message":"Request was cancelled"}}Content-Length: 135
Content-Type: application/vscode-jsonrpc; charset=utf-8

{"id":9,"jsonrpc":"2.0","result":{"range":{"start":{"line":44,"character":…
[11:45:41 AM] [Analyzer] [Info] <== {"id":6,"jsonrpc":"2.0","error":{"code":-32800,"message":"Request was cancelled"}}Content-Length: 82
Content-Type: application/vscode-jsonrpc; charset=utf-8

{"id":8,"jsonrpc":"2.0","error":{"code":-32800,"message":"Request was cancelled"}}Content-Length: 1023
Content-Type: application/vscode-jsonrpc; charset=utf-8

{"id":10,"jsonrpc":"2.0","result":[{"title":"Sort Members","kind":"source.sortMembers","command":{"title":"Sort Members","command":"edit.sortMembers","arguments":["/Users/brandontrautmann/src/mobile/flutter/app/lib/widgets/home/embedded_home.dart"]}},{"title":"Organize Imports","kind":"source.organizeImports","command":{"title":"Organize Imports","command":"edit.organizeImports","arguments":["/Users/brandontrautmann/src/mobile/flutter/app/lib/widgets/home/embedded_home.dart"]}},{"title":"Add type annotation","kind":"refactor.add.typeAnnotation","diagnostics":[],"edit":{"documentChanges":[{"textDocument":{"version":3,"uri":"file:///Users/brandontrautmann/src/mobile/flutter/app/lib/widgets/home/embedded_home.dart"},"edits":[{"range":{"start":{"line":44,"character":10},"end":{"line":44,"character":10}},"newText":"Route<FeatureResult> "},{"range":{"start":{"line":0,"character":51},"end":{"line":0,"character":51}},"newText":"\nimport 'package:betterment_flutter/shared/feature_result/feature_result.dart';"}]}]}}]}
Tue May 18 2021 [11:45:44 GMT-0400 (Eastern Daylight Time)] Log file ended

@walsha2 great, glad to hear! I suspect the issues were in the extension code that handles the auto-import completions (it has a lot of data to stitch together in each completion request) - it was definitely much slower in JS/node than the Dart server version is (though I hadn’t experienced it getting worse over time).

The goal is to move over to LSP by default gradually in the coming months (and ultimately have this be the only option) so hopefully it’ll become a non-issue in time. Thanks!

@DanTup thank you for the thorough response. I have been testing with dart.previewLsp enabled per your request and it has been night and day! I have not run into the same analyzer stalling issues I had in the past. I have worked in multiple hour long sessions and the analyzer was just as sporty at then end of the session as initial it was at initial VS Code launch. So that seems to have solved the issue I was seeing.

I will refrain from opening a new issue at the moment, but I will keep an eye on it and open an issue with more details if needed. Thank you again!

@rydmike I don’t think the termination issue is related to this - I believe that’s a Dart watcher issue (discussion about this is in https://github.com/Dart-Code/Dart-Code/issues/2805).

Renaming multiple folders/multiple files is something on my radar. I have a working prototype, but it’s too slow (it enumerates all of the files and does the move refactor individually which scales quite badly). There’s an issue about this at https://github.com/Dart-Code/Dart-Code/issues/2483 though we also need some LSP spec changes (I have an open PR at https://github.com/microsoft/language-server-protocol/pull/1074).

I believe the issue here may be related to the file(s) being indexed, though I haven’t been able to reliably repro it with logging. In a future LSP release, refactors will show a progress notification so it will be clear that something is happening and it won’t just look like it silently failed (that doesn’t solve the issue, but is at least an improvement).

@walsha2

I run into this issue all the time as well. Freshly opened VSCode, everything works fine, but after 30-60 minutes of coding and hot reload work, the analysis server will come to a screeching halt. All intellisense becomes unresponsive or very delayed.

This sounds like a different issue to what’s being discussed here (which is just refactors being slow the first time - which I think may be related to files being indexed). Please file a new issue about this and we can figure out how best to debug (in the meantime, enabling the analyzer log file may be worthwhile, so when it next happens you can grab a copy and we can see if the time is being spent in the server or not). You should also grab the output of running code --status in a terminal which will capture the CPU + memory usage of all processes from the extension host to the analysis server which might be useful.

If you haven’t already, I’d also recommend switching to LSP (“dart.previewLsp”) setting. This has several improvements in code completion that should improve performance.

One more thing I will mention is that in the process of trying to see what the analyzer was doing, I enabled dart.analyzerInstrumentationLogFile. Nothing stood out (not to me at least), but I did notice that this file would grow VERY quickly.

Yep, this logs all of the communication with the language server in full and can be very verbose. The log file I mentioned above should be smaller (it truncates long lines, and overwrites on each new session) and would is a better option if you’re leaving it enable over a longer period (ofc it’s not quite as insightful as the instrumentation log).

I saw something about the possibility that imports may be causing an issue for the analysis server. For example if the code base imports lots of libraries as opposed to single widgets from those libraries?

I’m not aware of any performance implications of this (though I’m less familiar all of the internals of the analysis server), though 130 files doesn’t seem very large in my opinion so I’d be surprised if that was a source of performance issues.

We should continue this discussion in another issue though - it gets tricky tracking issues when there are many things in the same (if things turn out to be the same, it’s easier to close an issue as a duplicate than separate the info in a single issue to multiple). Thanks!

In my case, it seemed like the problem was with cache, because restarting the server and then renaming would take less than the rename attempt which caused me to search for this issue. I’ll keep a look on this.