microsoft/sarif-vscode-extension

Entering any text in any file is causing numerous launches of rg.exe processes causing global system slowdown

theficus opened this issue · 21 comments

Type: Performance Issue

After opening a large project in VSCode, I found my system performance was slowing to a crawl whenever typing in any text. Doing an ETW trace found hundreds of rg.exe processes being launched in a very short period of time.

These all had a command line like this:
"c:\Users\XXXX\AppData\Local\Programs\Microsoft VS Code\resources\app\node_modules.asar.unpacked\@vscode\ripgrep\bin\rg.exe" --files --hidden --case-sensitive -g **/untitled:Untitled-1 -g !**/.git -g !**/.svn -g !**/.hg -g !**/CVS -g !**/.DS_Store -g !**/Thumbs.db -g !**/QLocal -g !**/obj -g !**/objd -g !/__cacheOutput --no-ignore --follow --no-config --no-ignore-global

This caused system-wide slowdowns and made VSCode largely unusable. Using VSCode's Extension Bisect feature narrowed down the culprit to being this extension.

After disabling this extension, the problems went away immediately.

These slowdowns were observed in any type of document, even untitled ones.

Extension version: 3.3.3
VS Code version: Code 1.72.1 (129500ee4c8ab7263461ffe327268ba56b9f210d, 2022-10-10T17:22:48.346Z)
OS version: Windows_NT x64 10.0.22621
Modes:
Sandboxed: No

System Info
Item Value
CPUs 12th Gen Intel(R) Core(TM) i7-1255U (12 x 2611)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) undefined
Memory (System) 31.83GB (9.02GB free)
Process Argv . --crash-reporter-id b766c3b0-53b1-48b7-8318-261d783cda1f
Screen Reader no
VM 0%
Process Info
CPU %	Mem MB	   PID	Process
    1	   129	 53372	code main
    3	   332	 13068	   window (● commonfunctions.ps1 - AdvancedAppManagement - Visual Studio Code)
    0	   136	 15084	   extensionHost
    0	    72	 46984	     "C:\Program Files\Microsoft VS Code\Code.exe" --ms-enable-electron-run-as-node "c:\Program Files\Microsoft VS Code\resources\app\extensions\json-language-features\server\dist\node\jsonServerMain" --node-ipc --clientProcessId=15084
    2	   149	 17064	   shared-process
    0	    94	 35080	     fileWatcher
    0	    78	 48896	     fileWatcher
    0	    81	 57076	     ptyHost
    0	     8	  6024	       console-window-host (Windows internal process)
    0	     8	  8968	       console-window-host (Windows internal process)
    0	     7	 14600	       console-window-host (Windows internal process)
    0	     5	 28124	       C:\Windows\System32\cmd.exe
    1	   131	 33556	       "C:\Program Files\PowerShell\7\pwsh.exe" -NoProfile -ExecutionPolicy Bypass -Command "Import-Module 'c:\Users\XXXX\.vscode\extensions\ms-vscode.powershell-2022.11.0\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2022.11.0' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'c:\Users\XXXX\.vscode\extensions\ms-vscode.powershell-2022.11.0\modules' -EnableConsoleRepl -StartupBanner '' -LogLevel 'Normal' -LogPath 'c:\Users\XXXX\AppData\Roaming\Code\User\globalStorage\ms-vscode.powershell\logs\1669070606-ebc94e7b-8089-4cae-9c7f-9001c80176a81669070604607\EditorServices.log' -SessionDetailsPath 'c:\Users\XXXX\AppData\Roaming\Code\User\globalStorage\ms-vscode.powershell\sessions\PSES-VSCode-53372-647236.json' -FeatureFlags @() "
    0	     5	 41620	       C:\Windows\System32\cmd.exe
    0	     5	 41764	       C:\Windows\System32\cmd.exe
    0	   435	 45920	       "C:\Program Files\PowerShell\7\pwsh.exe" -NoProfile -ExecutionPolicy Bypass -Command "Import-Module 'c:\Users\XXXX\.vscode\extensions\ms-vscode.powershell-2022.11.0\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2022.11.0' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'c:\Users\XXXX\.vscode\extensions\ms-vscode.powershell-2022.11.0\modules' -EnableConsoleRepl -StartupBanner '' -LogLevel 'Normal' -LogPath 'c:\Users\XXXX\AppData\Roaming\Code\User\globalStorage\ms-vscode.powershell\logs\1669061428-8e811345-169f-4de5-aebb-3aa1507222151669061426992\EditorServices.log' -SessionDetailsPath 'c:\Users\XXXX\AppData\Roaming\Code\User\globalStorage\ms-vscode.powershell\sessions\PSES-VSCode-53372-915177.json' -FeatureFlags @() "
    0	     7	 57756	       console-window-host (Windows internal process)
    0	     7	 67712	       console-window-host (Windows internal process)
    6	   204	 25988	   extensionHost
    0	     3	 69560	     "C:\Program Files\Git\cmd\git.exe" symbolic-ref --short HEAD
    0	    11	 45032	       console-window-host (Windows internal process)
    0	   244	 30704	   window (.gitignore - sync-func - Visual Studio Code)
    0	    39	 32268	   utility-network-service
    1	    99	 36092	   issue-reporter
    0	    24	 39744	   crashpad-handler
    2	   314	 46500	   gpu-process
Workspace Info
|  Window (● commonfunctions.ps1 - AdvancedAppManagement - Visual Studio Code)
|  Window (.gitignore - sync-func - Visual Studio Code)
|    Folder (XXXX): more than 22186 files
|      File types: yaml(14114) validation(131) md(32) json(15) txt(5)
|                  gitignore(4) ps1(4) yml(4) gitmodules(1)
|                  dockerignore(1)
|      Conf files: launch.json(2) settings.json(2) tasks.json(2) dockerfile(1)
|      Launch Configs: PowerShell
|    Folder (sync-func): 16 files
|      File types: json(5) ps1(4) dockerignore(1) gitignore(1) psd1(1)
|      Conf files: dockerfile(1);
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242:30382549
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscoreces:30445986
pythondataviewer:30285071
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593:30376534
pythonvs932:30410667
cppdebug:30492333
vsclangdc:30486549
c4g48928:30535728
dsvsc012:30540252
azure-dev_surveyone:30548225
pyindex848cf:30577861
nodejswelcome1cf:30587006
2e4cg342:30602488
gswce1:30612156
iaj6b796:30613358
pyind779cf:30617257
dbltrim-noruby:30604474
89544117:30613380

+1
I observed the same behavior - I had to disable this extension in order to work around the problem of numerous ripgrep processes running.

For me, all I have to do is visit a file to incur this issue.

+1 I observed the same behavior - I had to disable this extension in order to work around the problem of numerous ripgrep processes running.

I had to do the same.

+1 Same observation. Sometimes saving file also takes very long time. Unsure if it's the same root cause, but it does show getting code actions from 'sarif viewer'.

cc @EasyRhinoMSFT

Thanks for the report, we'll look into it.

@BowerBao could you please try disabling the extension's Github Code Scanning feature to see if the symptoms stop? This can be done in the extension settings:

image

@EasyRhinoMSFT Thanks for quick response! I will try it with "off". It was on "prompt" for me, same as your image showed.

The Connect To Github Code Scanning: off doesn't affect the behavior. Still lots of rg.exe spawning and lagging.

I'm observing numerous lines of messages in the output panel of Sarif Viewer, with the same
updateDiags <file path>. 0 Results.
And it seems to be in sync with the rg.exe spawning. i.e., it kept printing at a pretty fast rate when rg.exe processes are present, and stopped printing when rg.exe processes are gone. Wonder if they are related.

This is very helpful, thanks @BowenBao. What do you have open in your workspace?

~10 python files + sarif viewer on split editor. The workspace contains 3 repositories.

Ok thanks, I haven't been able to repro yet so I'm trying to set up conditions as close to yours as I can.

@EasyRhinoMSFT it is, I think it is one of the factors impacting performance: large workspace makes rg slow. While the other factor here is somehow a lot of these processes are spawned. I turned on vscode trace logging for my workspace, and did two experiments.

  • Disabled sarif viewer extension, reloaded window. [Log starts] Start writing comments in a python file, add one line of code to trigger intellisense, then save file.
  • Enabled sarif viewer extension, reloaded window. Opened one sarif log. [Log starts] Start writing comments in a python file, add one line of code to trigger intellisense (lagged so it didn't show), then save file (lagged).

I hope this helps.
https://microsoft-my.sharepoint.com/:f:/p/bowbao/EtlC3TQP2eJHjYVJWLYcBz0B8iLnfDQxlr8dKa33L-8C-A?e=6zEhuD

Does anyone have a repo I can use to get this behavior?

Hi folks,

I've prepared a build that restricts the file crawling to repos that have GitHub Advanced Security enabled. That was the original purpose for this feature, and clearly it's not appropriate for large repos. Please install this vsix and see if it resolves the issue (download then rename to .vsix).
sarif-viewer-3.3.5-beta.zip
Thanks!

@EasyRhinoMSFT I did some initial testing with the new extension you posted. I'm still getting a ton of rg.exe processes being spawned to the point where it cripples my system.

Related question: What is the purpose of the scanning? What is it scanning for? I see you mentioned something about Github Advanced Security. I'm curious why a SARIF viewer is scanning my repo in the first place, especially since it's a private repo and not cloned from github. I also see the default behavior for code scanning is to prompt but I was never prompted to enable scanning of my repo.

Thanks @MichaelSquires

GHAS is a service-side scan, so nothing is being scanned locally. The feature that is causing this issue exists to keep defect locations reported by GHAS (or any other static analysis tool) up to date as you make changes to the code. What I want (and apparently failed) to do is turn it off unless you are working in a GHAS-enabled GitHub repo.

Thanks for trying, I'll go do some more tinkering.

@EasyRhinoMSFT Thanks for the explanation! Let me know when you are ready to try out your changes and I'll be happy to test again. This issue repros very quickly on the repository I'm working in so it's easy to check.

@EasyRhinoMSFT were you able to repro this issue? I had to downgrade to an earlier version of this extension.

Apologies for the silence -- unfortunately I haven't been able to repro and time is in short supply right now.

I can reproduce with the latest version. VSCode

Version: 1.77.3 (user setup)
Commit: 704ed70d4fd1c6bd6342c436f1ede30d1cff4710
Date: 2023-04-12T09:16:02.548Z
Electron: 19.1.11
Chromium: 102.0.5005.196
Node.js: 16.14.2
V8: 10.2.154.26-electron.0
OS: Windows_NT x64 10.0.22624
Sandboxed: Yes