"Dart: New Project" is slow (with no UI) after selecting a folder
When I run "Dart: New Project", it asks me for a template, then a folder. After selecting a folder there is multiple-second delay before it asks for a project name, but there is no indication of what's happening during that time. Multiple times I've thought something was broken.
If the delay is unavoidable (eg. because we're running another process) we should show some progress.
Cannot repro after adding debug logging... There's not a lot of code between these two steps, but it does call nextAvailableFilename which will look for a suitable default folder name. I wonder if the disk access is slow (Defender?) 🤔
I found that the place where this stalled was inconsistent, and it turns out to be other code blocking the thread when we hit one of the awaits during the dialog/quick-pick. For example in this captured case, we were computing tasks (which involves fetching projects) during that time:
[4:02:40 PM:784] [General] [Info] Returning cached results for project search
Error:
at getAllProjectFoldersAndExclusions (d:\Dev\Dart-Code\Dart-Code\out\dist\extension.js:64800:71)
at getAllProjectFolders (d:\Dev\Dart-Code\Dart-Code\out\dist\extension.js:64787:27)
at DartTaskProvider.provideTasks (d:\Dev\Dart-Code\Dart-Code\out\dist\extension.js:44773:71)
at file:///c:/Users/danny/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:128:54879
at file:///c:/Users/danny/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:28:70206
at new Promise (<anonymous>)
at ai (file:///c:/Users/danny/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:28:70178)
at i4.$provideTasks (file:///c:/Users/danny/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:128:54861)
We should consider making things like getAllProjectFolders async so that we don't block the thread so much if VS Code calls APIs (like provideTasks) while the user may be trying to do other things.
Profiling extension startup currently seems broken - https://github.com/microsoft/vscode/issues/251014 so we might need to find another way to profile the startup (such as a fake delay that allows us to manually start profiling).
I was able to capture a trace of the extension host when this happened.. However, it shows no code taking any time. So my guess is that this delay is not coming from the extension host, but from part of VS Code.
slow_flutter_new_project.cpuprofile.zip
I'll try to capture a profile using the normal DevTools in VS Code, however I'm not sure which of the many processes that profiles. If it doesn't capture anything either, we might need to wait for --prof-startup to be fixed (and if that automatically stops after startup, find an equivalent that does not).
Nothing in the profile trace captured from the dev tools either:
I've filed https://github.com/microsoft/vscode/issues/251921 in the hope of getting some more pointers about what else we can profile.