Repository: vscode
Issue: Switching code editor tabs slow in workspace with many tests (~150,000)
Labels: bug,author-verification-requested,testing

<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
Does this issue occur when all extensions are disabled?: No

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
- VS Code Version: 1.95.3
- OS Version: Windows 11 23H2

```
Version: 1.95.3 (system setup)
Commit: f1a4fb101478ce6ec82fe9627c43efbf9e98c813
Date: 2024-11-13T14:50:04.152Z
Electron: 32.2.1
ElectronBuildId: 10427718
Chromium: 128.0.6613.186
Node.js: 20.18.0
V8: 12.8.374.38-electron.0
OS: Windows_NT x64 10.0.22631
```

Steps to Reproduce:

1. Open a vscode workspace with many tests (in my case ~150,000)
2. Wait for the language extension to discover all the tests in the project. In my case this is done by C# Dev Kit, though I doubt this matters.
3. switching between code editor tabs takes a full second for vscode to become responsive again.

I profiled the extension host while it was hanging, which show practically 0% CPU usage.

Next, I profiled the main window. See [Trace-20241211T121347.json](https://github.com/user-attachments/files/18094526/Trace-20241211T121347.json)

The bulk of time is spent in `encodeURIComponentFast` which is triggered by [`testingDecorations.ts`](https://github.com/microsoft/vscode/blob/4fb4fc90310a408a4f5c6216372e634634ae8ea0/src/vs/workbench/contrib/testing/browser/testingDecorations.ts#L517-L526):

![Image](https://github.com/user-attachments/assets/f507c009-c307-41c0-98e3-5aec34ba6421)


Notes:
- This happens on all editors in the window, even on file types not associated with the tests. E.g. switching between Markdown files is slow too. Though, switching to e.g. the "Settings" tabs doesn't have this problem, presumably because it isn't a code editor.
- The delay is the same regardless of whether the open file contains any tests or not.
- I have the Test Gutter disabled, so AFAIK, there no need to be computing this information in the first place.
- Observation as someone not familiar with this codebase all: I notice the [code in question](https://github.com/microsoft/vscode/blob/4fb4fc90310a408a4f5c6216372e634634ae8ea0/src/vs/workbench/contrib/testing/browser/testingDecorations.ts#L517-L526) already "spawns" an `async` function to prevent blocking. Though, looking at the profile, all `await` points end up being scheduled on the microtask queue of the original `mousedown` event handler, so the UI rendering is blocked anyway.