microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.27k stars 28.57k forks source link

Extremely slow startup on a reasonably powerful Win 11 machine #174420

Closed sjaffe314 closed 12 months ago

sjaffe314 commented 1 year ago

Vscode takes about 30 seconds to launch for me, but is perfectly fast after that.

My Windows 11 Dell laptop has all the latest Windows Updates, and all the latest Dell driver updates (graphics card, et al). I uninstalled vscode, deleted all the installation directories (so extensions didn't carry forward), and reinstalled vscode.

I have a fair bit of other software on my machine. But other things like Pycharm Community have a visual representation within 1 second of launch, and is fully functional within 3-5 seconds of launch. But vscode takes about 10 seconds before a faint outline of the vscode window appear, another 5-10 seconds before that faint outline fills entirely with black, and another 5-10 seconds until I typically get a "The window is not responding" dialog and vscode content starts to render under that. I seem to be able to reliably click "Close" on that dialog, which leaves vscode running after about a 30 second startup lag. Vscode seems perfectly responsive after that. And, again, pretty much every other application I start on my computer feels responsive right from the point of launch.

Turning off Antivirus (Windows Security > real-time protection) didn't help. And I don't have the Nahimic audio driver that people attributed similar performance problems to (rooted in Electron and discussed under #22087).

Below are the startup profiling files:

And here is the result of my "Startup Performance" stats:

System Info

Performance Marks

What Duration Process Info
start => app.isReady 6832 [main] initial startup: true
nls:start => nls:end 0 [main] initial startup: true
require(main.bundle.js) 229 [main] initial startup: true
start crash reporter 6766 [main] initial startup: true
serve main IPC handle 4 [main] initial startup: true
create window 38 [main] initial startup: true, state: 1ms, widget: 33ms, show: 0ms
app.isReady => window.loadUrl() 342 [main] initial startup: true
window.loadUrl() => begin to require(workbench.desktop.main.js) 21046 [main->renderer] NewWindow
require(workbench.desktop.main.js) 1287 [renderer] cached data: NO, node_modules took 0ms
wait for window config 0 [renderer] -
init storage (global & workspace) 48 [renderer] -
init workspace service 49 [renderer] -
register extensions & spawn extension host 451 [renderer] -
restore viewlet 27 [renderer] workbench.view.explorer
restore panel 0 [renderer] -
restore & resolve visible editors 110 [renderer] 1: workbench.editors.gettingStartedInput
overall workbench load 523 [renderer] -
workbench ready 30105 [main->renderer] -
renderer ready 1902 [renderer] -
shared process connection ready 0 [renderer->sharedprocess] -
extensions registered 30648 [renderer] -

Raw Perf Marks: main

Name    Timestamp   Delta   Total
code/timeOrigin 1676431080699.56    0   0
code/didStartMain   1676431080835   135.43994140625 135.43994140625
code/willStartCrashReporter 1676431080856   21  156.43994140625
code/didStartCrashReporter  1676431087622   6766    6922.43994140625
code/mainAppReady   1676431087667   45  6967.43994140625
code/willLoadMainBundle 1676431087670   3   6970.43994140625
code/fork/willLoadCode  1676431087699   29  6999.43994140625
code/registerFilesystem/file    1676431087872   173 7172.43994140625
code/didLoadMainBundle  1676431087899   27  7199.43994140625
code/willStartMainServer    1676431087917   18  7217.43994140625
code/didStartMainServer 1676431087921   4   7221.43994140625
code/willCreateCodeWindow   1676431087967   46  7267.43994140625
code/willRestoreCodeWindowState 1676431087968   1   7268.43994140625
code/didRestoreCodeWindowState  1676431087969   1   7269.43994140625
code/willCreateCodeBrowserWindow    1676431087970   1   7270.43994140625
code/didCreateCodeBrowserWindow 1676431088003   33  7303.43994140625
code/didCreateCodeWindow    1676431088005   2   7305.43994140625
code/willOpenNewWindow  1676431088009   4   7309.43994140625

Raw Perf Marks: renderer

Name    Timestamp   Delta   Total
code/timeOrigin 1676431088019   0   0
code/didStartRenderer   1676431109038   21019   21019
code/willWaitForWindowConfig    1676431109039   1   21020
code/didWaitForWindowConfig 1676431109039   0   21020
code/willShowPartsSplash    1676431109039   0   21020
code/didShowPartsSplash 1676431109040   1   21021
code/willLoadWorkbenchMain  1676431109055   15  21036
code/didLoadWorkbenchMain   1676431110342   1287    22323
code/registerFilesystem/file    1676431110354   12  22335
code/registerFilesystem/vscode-userdata 1676431110354   0   22335
code/willInitWorkspaceService   1676431110359   5   22340
code/willInitStorage    1676431110361   2   22342
code/willInitUserConfiguration  1676431110372   11  22353
code/didInitUserConfiguration   1676431110404   32  22385
code/willInitWorkspaceConfiguration 1676431110404   0   22385
code/didInitWorkspaceConfiguration  1676431110407   3   22388
code/didInitWorkspaceService    1676431110408   1   22389
code/didInitStorage 1676431110409   1   22390
code/willStartWorkbench 1676431110417   8   22398
code/LifecyclePhase/Ready   1676431110422   5   22403
code/willCreateWorkbenchContributions/1 1676431110515   93  22496
code/didCreateWorkbenchContributions/1  1676431110573   58  22554
code/willCreateWorkbenchContributions/2 1676431110573   0   22554
code/registerFilesystem/trustedDomains  1676431110577   4   22558
code/registerFilesystem/vscode-interactive  1676431110580   3   22561
code/registerFilesystem/vscode-local-history    1676431110585   5   22566
code/didCreateWorkbenchContributions/2  1676431110590   5   22571
code/willRestoreEditors 1676431110830   240 22811
code/willRestoreViewlet 1676431110873   43  22854
code/didRestoreViewlet  1676431110900   27  22881
code/didRestoreEditors  1676431110940   40  22921
code/didStartWorkbench  1676431110940   0   22921
code/LifecyclePhase/Restored    1676431110940   0   22921
code/didRemovePartsSplash   1676431110940   0   22921
code/willCreateWorkbenchContributions/3 1676431110940   0   22921
code/willConnectSharedProcess   1676431110941   1   22922
code/willLoadExtensions 1676431111032   91  23013
code/willHandleExtensionPoints  1676431111255   223 23236
code/willHandleExtensionPoint/configurationDefaults 1676431111255   0   23236
code/didHandleExtensionPoint/configurationDefaults  1676431111258   3   23239
code/willHandleExtensionPoint/configuration 1676431111258   0   23239
code/didHandleExtensionPoint/configuration  1676431111342   84  23323
code/willHandleExtensionPoint/jsonValidation    1676431111342   0   23323
code/didHandleExtensionPoint/jsonValidation 1676431111343   1   23324
code/willHandleExtensionPoint/debuggers 1676431111343   0   23324
code/didHandleExtensionPoint/debuggers  1676431111344   1   23325
code/willHandleExtensionPoint/breakpoints   1676431111344   0   23325
code/didHandleExtensionPoint/breakpoints    1676431111344   0   23325
code/willHandleExtensionPoint/notebooks 1676431111344   0   23325
code/didHandleExtensionPoint/notebooks  1676431111345   1   23326
code/willHandleExtensionPoint/notebookRenderer  1676431111345   0   23326
code/didHandleExtensionPoint/notebookRenderer   1676431111351   6   23332
code/willHandleExtensionPoint/problemPatterns   1676431111351   0   23332
code/didHandleExtensionPoint/problemPatterns    1676431111353   2   23334
code/willHandleExtensionPoint/problemMatchers   1676431111353   0   23334
code/didHandleExtensionPoint/problemMatchers    1676431111355   2   23336
code/willHandleExtensionPoint/taskDefinitions   1676431111355   0   23336
code/didHandleExtensionPoint/taskDefinitions    1676431111359   4   23340
code/willHandleExtensionPoint/terminal  1676431111359   0   23340
code/didHandleExtensionPoint/terminal   1676431111359   0   23340
code/willHandleExtensionPoint/walkthroughs  1676431111359   0   23340
code/didHandleExtensionPoint/walkthroughs   1676431111360   1   23341
code/willHandleExtensionPoint/commands  1676431111360   0   23341
code/didHandleExtensionPoint/commands   1676431111368   8   23349
code/willHandleExtensionPoint/submenus  1676431111368   0   23349
code/didHandleExtensionPoint/submenus   1676431111368   0   23349
code/willHandleExtensionPoint/menus 1676431111368   0   23349
code/didHandleExtensionPoint/menus  1676431111389   21  23370
code/willHandleExtensionPoint/authentication    1676431111389   0   23370
code/didHandleExtensionPoint/authentication 1676431111389   0   23370
code/willHandleExtensionPoint/languages 1676431111389   0   23370
code/didHandleExtensionPoint/languages  1676431111408   19  23389
code/willHandleExtensionPoint/customEditors 1676431111408   0   23389
code/didHandleExtensionPoint/customEditors  1676431111408   0   23389
code/willHandleExtensionPoint/codeActions   1676431111408   0   23389
code/didHandleExtensionPoint/codeActions    1676431111409   1   23390
code/willHandleExtensionPoint/viewsWelcome  1676431111409   0   23390
code/didHandleExtensionPoint/viewsWelcome   1676431111409   0   23390
code/willHandleExtensionPoint/grammars  1676431111409   0   23390
code/didHandleExtensionPoint/grammars   1676431111421   12  23402
code/willHandleExtensionPoint/colors    1676431111421   0   23402
code/didHandleExtensionPoint/colors 1676431111423   2   23404
code/willHandleExtensionPoint/semanticTokenScopes   1676431111423   0   23404
code/didHandleExtensionPoint/semanticTokenScopes    1676431111424   1   23405
code/willHandleExtensionPoint/snippets  1676431111424   0   23405
code/didHandleExtensionPoint/snippets   1676431111424   0   23405
code/willHandleExtensionPoint/keybindings   1676431111424   0   23405
code/didHandleExtensionPoint/keybindings    1676431111449   25  23430
code/willHandleExtensionPoint/themes    1676431111449   0   23430
code/didHandleExtensionPoint/themes 1676431111453   4   23434
code/willHandleExtensionPoint/iconThemes    1676431111453   0   23434
code/didHandleExtensionPoint/iconThemes 1676431111453   0   23434
code/willHandleExtensionPoint/continueEditSession   1676431111453   0   23434
code/didHandleExtensionPoint/continueEditSession    1676431111453   0   23434
code/willHandleExtensionPoint/viewsContainers   1676431111453   0   23434
code/didHandleExtensionPoint/viewsContainers    1676431111467   14  23448
code/willHandleExtensionPoint/views 1676431111467   0   23448
code/didHandleExtensionPoint/views  1676431111472   5   23453
code/didHandleExtensionPoints   1676431111472   0   23453
code/didLoadExtensions  1676431111483   11  23464

Node Cached Data Stats

cached data used

cached data missed

cached data rejected

cached data created (lazy, might need refreshes)

i27ae15 commented 1 year ago

Did you solve the issue? I got the same problem here

deepak1556 commented 1 year ago

@sjaffe314 can you confirm if you are using Mcafee AV ?

i27ae15 commented 1 year ago

For me was that the issue related to Mcafee.

https://stackoverflow.com/questions/75931344/vs-code-is-not-responding-slow-startup-and-unresponsive

Is fine now

sjaffe314 commented 1 year ago

Thanks for giving this some thought @deepak1556. I do not have McAfee AV installed on my system. Just the standard Windows Security Antivirus (Defender). And I get the same ~30 second vscode startup time even after adding code.exe to the exclusion list or fully disabling Windows Security Virus Protection.

I still hope to find time to write a hello world Electron app, to see if the startup overhead is reproducible on that, but I haven't been able to set aside the time to do that yet. I've just fallen back to using the VS.NET IDE.

deepak1556 commented 1 year ago

Thanks for the clarification, if you have chance to try the latest stable v1.78, can you collect a trace following the steps in https://github.com/microsoft/vscode/issues/178962#issuecomment-1543836137

sjaffe314 commented 1 year ago

@deepak1556 - Per the instructions you referenced, I sent you an email with a WPR session that captured the slow startup of vscode v1.78.2 on my machine

deepak1556 commented 1 year ago

Thanks @sjaffe314 , I will get back to you on this issue after looking at the trace.

fc4525 commented 1 year ago

Regarding McAfee, to confirm what others have seen, I noticed that vscode takes about 20-25 secs to load with McAfee "Real-Time Scanning" on and less tha 5 secs with it off.

deepak1556 commented 1 year ago

@sjaffe314 can you please check if the issue has been addressed with latest insiders https://code.visualstudio.com/insiders which comes with an updated version of the runtime. Thanks!

sjaffe314 commented 1 year ago

@deepak1556 - I tried with the latest insider build (1.82.0-insider), and the slow startup occurs with that as well.

In case it helps, I'm emailing you a WPR trace of it. Let me know if there are additional metrics you would like.

So, to recap, I see the slow startup (~15 seconds before any visual artifact, a completely black window at 20 seconds, and the rendered vscode window at ~30 seconds) in both of my now parallel installations:

Version: 1.82.0-insider (user setup) Commit: ebd67244fb2da33ab078bb2baa96106fda29f336 Date: 2023-08-29T05:32:55.965Z Electron: 25.5.0 ElectronBuildId: 23084831 Chromium: 114.0.5735.289 Node.js: 18.15.0 V8: 11.4.183.29-electron.0 OS: Windows_NT x64 10.0.22621

And:

Version: 1.81.1 (user setup) Commit: 6c3e3dba23e8fadc360aed75ce363ba185c49794 Date: 2023-08-09T22:22:42.175Z Electron: 22.3.18 ElectronBuildId: 22689846 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Windows_NT x64 10.0.22621

deepak1556 commented 12 months ago

@sjaffe314 thanks for the trace, I looked into it today and found that the process launch calls are delayed by a kernel driver routine from BadlionAnticheat.sys that hooks into all process creation and deletion events. I am not sure what this routine does but it seems to originate from Badlion client, do you have it installed ? This reminded me of an old issue https://github.com/microsoft/vscode/issues/56644#issuecomment-613858693 maybe it is still relevant. Can you try uninstalling the client and see if it helps in improving the startup times of VS Code.

Slow_launch_badlion

sjaffe314 commented 12 months ago

@deepak1556 - thanks so much for your additional investigation! I'm thrilled to say that VSCode now opens lightening fast for me!

I believe I had installed the Badlion Client several years ago to manage mods for Minecraft, and had subsequently uninstalled it awhile ago. I couldn't find any obvious references to it yesterday in my Windows "Add or Remove Programs" or C:\Program Files, and the only file system artifact I could find was the C:\Windows\System32\drivers\BadlionAnticheat.sys file your screen capture referenced, and a registry reference to badlion under a discord key. Anyway, I renamed the file to BadlionAnticheat.sys.disabled, rebooted my OS, and now VSCode opens instantly!

Thanks again for your time. I realize a OS hook like this is outside the bounds of the VSCode system, but I deeply appreciate your effort to isolate that unexpected interaction. I'm still curious why VSCode seemed to be so disproportionately affected as compared to other applications I ran on my computer, but that's not something I'm going to lose any sleep over. I may also try to get familiar with reading those Windows Performance Recorder traces, so I can be more self sufficient on this kind of diagnosis in the future!

Thanks again!

deepak1556 commented 12 months ago

Glad to know that the issue is resolved, thanks for your patience!