Dart-Code icon indicating copy to clipboard operation
Dart-Code copied to clipboard

"Dart: New Project" is slow (with no UI) after selecting a folder

Open DanTup opened this issue 8 months ago • 6 comments

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.

DanTup avatar Jun 09 '25 14:06 DanTup

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?) 🤔

DanTup avatar Jun 09 '25 14:06 DanTup

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.

DanTup avatar Jun 18 '25 15:06 DanTup

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

DanTup avatar Jun 18 '25 17:06 DanTup

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

DanTup avatar Jun 19 '25 14:06 DanTup

Nothing in the profile trace captured from the dev tools either:

vs_code_devtools_profile-20250619T165606.json

DanTup avatar Jun 19 '25 16:06 DanTup

I've filed https://github.com/microsoft/vscode/issues/251921 in the hope of getting some more pointers about what else we can profile.

DanTup avatar Jun 19 '25 16:06 DanTup