Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address CPU usage spike: Perform case-insensitive search on win32 and added workspace.findFiles maxResults value #556

Merged
merged 6 commits into from
Mar 27, 2024

Conversation

chrishuynhc
Copy link
Collaborator

@chrishuynhc chrishuynhc commented Mar 21, 2024

Overview

This change addresses the high CPU usage issue caused by the SARIF Viewer mentioned here: #548

For context, the high CPU usage was caused by the spawning of rg.exe (rigrep) processes to perform VSCode's workspace.findFiles searches. This file search is triggered on text document changes and is used for the uri rebaser logic of matching workspace files to SARIF log artifacts.

The Issue/Fix

The issue was due to the vscode.workspace.findFiles method being case-sensitive while the path being searched is normalized to lowercase on Windows. This was triggered on every text document change/keystroke resulting in the numerous rg.exe spawns. So, if the user happens to have a file open that contains capitalization in the file name, such as fooBar.ts, the file search would look for foobar.ts (normalized to lowercase on Windows) and vscode.workspace.findFiles would result in 0 matches. As a result, this file search would repeat as fooBar.ts would never be found and cached resulting in repetitive calls to vscode.workspace.findFiles when trying to resolve artifact matches and fill the distinct files cache.

To address this, we now perform a case-insensitive file search if on a Windows platform, otherwise do the default case-sensitive search when determining if a workspace has a distinct file name. In addition, this issue is compounded on larger workspace which is why a maxLimit of 5000 files is now specified when utilizing vscode.workspace.findFiles. This helps to prevent perf issues when working in large workspaces such as the windows OS repo by stopping the search when the limit is hit.

Note:
Tests were also updated to reflect this

@chrishuynhc chrishuynhc marked this pull request as ready for review March 26, 2024 18:13
@chrishuynhc chrishuynhc changed the title Address CPU usage spike: Remove uriRebaser normalize and added workspace.findFiles maxResults value Address CPU usage spike: Perform case-insensitive search on wind32 and added workspace.findFiles maxResults value Mar 26, 2024
@chrishuynhc chrishuynhc changed the title Address CPU usage spike: Perform case-insensitive search on wind32 and added workspace.findFiles maxResults value Address CPU usage spike: Perform case-insensitive search on win32 and added workspace.findFiles maxResults value Mar 26, 2024
@chrishuynhc chrishuynhc added the wave things the WAVE-team is tracking label Mar 26, 2024
Copy link
Contributor

@EasyRhinoMSFT EasyRhinoMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@winstliu winstliu merged commit 3c8f6aa into main Mar 27, 2024
7 checks passed
@winstliu winstliu deleted the user/chhuynh/addressCpuUsage branch March 27, 2024 20:34
@nekomeowww nekomeowww mentioned this pull request Jul 8, 2024
@stmillMSFT
Copy link

This issue is absolutely still repro, btw. I'm having this issue too. Same thing: no SARIF files in repo, and not even that big of a repo, but about a million rg.exe instances are spawned, and I can't type anymore. Since this extension seems to have been pushed out via group policy for some unknown reason, please address as a higher severity; this is making internal work miserable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wave things the WAVE-team is tracking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

100% cpu usage VS Code lags to the point of being unusable in large repos
4 participants