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

Nonresponsive editor with large project when typescript.tsserver.watchOptions: vscode #237351

Closed
pelmers-db opened this issue Jan 6, 2025 · 5 comments
Assignees
Labels
author-verification-requested Issues potentially verifiable by issue author bug Issue identified by VS Code Team member as probable bug confirmed Issue has been confirmed by VS Code Team member file-watcher File watcher freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues insiders-released Patch has been released in VS Code Insiders typescript Typescript support issues
Milestone

Comments

@pelmers-db
Copy link

pelmers-db commented Jan 6, 2025

Does this issue occur when all extensions are disabled?: No

  • VS Code Version: 1.96.2
  • OS Version: Client = Macos 14.7, Remote = Linux 5.4

Steps to Reproduce:

  1. Connect to remote ssh
  2. Open a project with 20000+ .tsx files
  3. Observe extreme slowness (5+ seconds to respond) with basic editor file actions: open file, save file, close file, etc.

Debugging notes:

  1. when set typescript output to trace mode I see one watch event per file, e.g. [trace] <semantic> Event received: createFileWatcher (0). { "id": 364, "path": "/home/peter.elmers/fortesting/generated_tsx_project/src/Component10322.tsx" }
  2. from reading code, looks like this hits the nonRecursiveWatcher which is nodejs: https://github.com/microsoft/vscode/blob/292d0bd51af8d7e107fa34b00955aceb7d9c03d5/src/vs/platform/files/node/watcher/watcher.ts/#L16-L17
  3. all the watchers pile up and get sent to the nodejs watcher code, I believe that triggers a quadratic time loop in this function: https://github.com/microsoft/vscode/blob/292d0bd51af8d7e107fa34b00955aceb7d9c03d5/src/vs/platform/files/node/watcher/nodejs/nodejsWatcher.ts/#L45-L52

The issue seems to be that every time watchers change then we send in all of the watchers, so the watch code needs to loop through the list many times and find which ones to remove and which ones to keep. But this is just a cursory look.

cc @bpasero

@mjbvz mjbvz added javascript JavaScript support issues freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues labels Jan 6, 2025
@bpasero
Copy link
Member

bpasero commented Jan 6, 2025

Is this project open source for us to reproduce?

@pelmers-db
Copy link
Author

pelmers-db commented Jan 7, 2025

repro project: https://github.com/pelmers-db/lots-of-tsx-files-slow-vscode

the steps to repro:

  1. open the project on remote linux
  2. open a bunch of .tsx files by clicking in the file tree
  3. observe vs code unresponsive

@bpasero bpasero added typescript Typescript support issues file-watcher File watcher confirmed Issue has been confirmed by VS Code Team member and removed javascript JavaScript support issues labels Jan 8, 2025
bpasero added a commit that referenced this issue Jan 8, 2025
@bpasero bpasero added this to the January 2025 milestone Jan 8, 2025
@bpasero
Copy link
Member

bpasero commented Jan 8, 2025

@pelmers-db thanks, this issue is spot on, not only because I can reproduce but also because you actually found the perf issue in code 👏

In #237459 I am changing to a Map for lookups, both for non-recursive and recursive watchers (the latter is less likely to be a problem simply because typically there is not thousands of folders in a project, nor would TS watch as many folders).

After my fix, there is still a CPU spike but it settles rather quickly. Would be great if you could then confirm this fix in insiders when it lands tomorrow.

@bpasero bpasero closed this as completed in b0d6d34 Jan 8, 2025
@vs-code-engineering vs-code-engineering bot added the unreleased Patch has not yet been released in VS Code Insiders label Jan 8, 2025
@bpasero bpasero added the bug Issue identified by VS Code Team member as probable bug label Jan 8, 2025
bpasero added a commit that referenced this issue Jan 8, 2025
In testing with many thousand individual files, this operation is very expensive.

Refs: #237351
bpasero added a commit that referenced this issue Jan 8, 2025
…237472)

In testing with many thousand individual files, this operation is very expensive.

Refs: #237351
@vs-code-engineering vs-code-engineering bot added insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Jan 8, 2025
@bpasero bpasero added the author-verification-requested Issues potentially verifiable by issue author label Jan 8, 2025
Copy link

This bug has been fixed in the latest release of VS Code Insiders!

@pelmers-db, you can help us out by commenting /verified if things are now working as expected.

If things still don't seem right, please ensure you're on version 2569d71 of Insiders (today's or later - you can use Help: About in the command palette to check), and leave a comment letting us know what isn't working as expected.

Happy Coding!

@bpasero
Copy link
Member

bpasero commented Jan 9, 2025

I even found more optimisations thanks to your workspace:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author-verification-requested Issues potentially verifiable by issue author bug Issue identified by VS Code Team member as probable bug confirmed Issue has been confirmed by VS Code Team member file-watcher File watcher freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues insiders-released Patch has been released in VS Code Insiders typescript Typescript support issues
Projects
None yet
Development

No branches or pull requests

3 participants