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

UpdateProjectIfDirty is slow on large projects #60633

Open
dbaeumer opened this issue Nov 28, 2024 · 1 comment
Open

UpdateProjectIfDirty is slow on large projects #60633

dbaeumer opened this issue Nov 28, 2024 · 1 comment

Comments

@dbaeumer
Copy link
Member

πŸ”Ž Search Terms

UpdateProjectIfDirty language server slow

πŸ•— Version & Regression Information

  • tested the version that ships with VS Code

⏯ Playground Link

No response

πŸ’» Code

Steps to reproduce:

  • clone VS Code (https://github.com/microsoft/vscode.git)
  • npm install
  • open VS Code on the vscode repository
  • open file task.constribution.ts
  • open the TS server log
  • add a new line to _ignoreEventForUpdateRunningTasksCount

Observe: updateGraphWorker takes roughly 300ms on my machine

I took a performance trace and a lot of time is spent in GC and getNormalizedAbsolutePath. I added a simply unbound cache to the method like

const pathCache = new Map();
function getNormalizedAbsolutePath(fileName, currentDirectory) {
  let cache = pathCache.get(currentDirectory);
  if (cache === undefined) {
    cache = new Map();
    pathCache.set(currentDirectory, cache);
  }
  let normalized = cache.get(fileName);
  if (normalized === undefined) {
    normalized = getPathFromPathComponents(getNormalizedPathComponents(fileName, currentDirectory));
    cache.set(fileName, normalized);
  }
  return normalized;
}

which cuts the time for updateGraphWorker in half. However there are still some GCs going on and a lot of time is now spent in verifyCompilerOptions / getNormalizedPathComponents.

πŸ™ Actual behavior

Takes 300ms to update on key stroke

πŸ™‚ Expected behavior

Adding a new line should be even in large project only cost a couple of ms :-)

Additional information about the issue

No response

@dbaeumer
Copy link
Member Author

Doing a comparable cache in getNormalizedPathComponents brings the time down to 75ms.

vscode-profile-2024-11-28-09-36-24.cpuprofile
vscode-profile-2024-11-28-12-42-42.cpuprofile
vscode-profile-2024-11-28-15-29-10.cpuprofile

Here are also some of the CPU profiles I captured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant