Address CPU usage spike: Perform case-insensitive search on win32 and added workspace.findFiles maxResults value #556
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'sworkspace.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 asfooBar.ts
, the file search would look forfoobar.ts
(normalized to lowercase on Windows) andvscode.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 tovscode.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 utilizingvscode.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