microsoft / sarif-vscode-extension

SARIF Microsoft Visual Studio Code extension
MIT License
110 stars 49 forks source link

Implement cache for 'workspaceHasDistinctFilename' #502

Closed BowenBao closed 1 year ago

BowenBao commented 1 year ago

Fixes #472

Before this fix, workspace.findFiles('**/${filename}'); is invoked by setDiags callback registered at workspace.onDidChangeTextDocument(({ document }) => setDiags(document)) in src/extension/index.ts. Meaning a whole workspace search is triggered for each keystroke in vscode. For large workspaces, this results in loads of rg.exe spawning and global system slowdown as observed in #472.

This PR is a simple fix implementing a caching system on top of existing code. Cache invalidation callback is registered for onDidCreateFiles, onDidRenameFiles, and onDidDeleteFiles.

Before this change: sarif_pre

After this change: sarif_post

EasyRhinoMSFT commented 1 year ago

This is awesome Bowen, thanks a lot for solving it. I'm loaded with other work but this one is having an impact so I was trying (and failing) to put some more time into it.