Skip to content

Watch with way fewer globs in LSP #971

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

Merged
merged 6 commits into from
May 29, 2025
Merged

Watch with way fewer globs in LSP #971

merged 6 commits into from
May 29, 2025

Conversation

jakebailey
Copy link
Member

@jakebailey jakebailey commented May 29, 2025

Fixes #956

Before, opening the VS Code source would net a super large number of file watchers:

image
image

With this PR, this is much reduced:

image

And, the root file globs have been fixed (though it's possible VS Code was normalizing them).

This is not particularly fast; for VS Code it takes some 60ms to process all of the failed lookup locations, but it doesn't change often. Mainly, this is to make things better than they were.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR reduces the number of file watchers set up by fixing the root file globs and updating the logic for gathering failed lookup locations.

  • Introduces a new glob mapping function (createGlobMapper) for consolidating failed lookup directories with proper normalization
  • Updates the initialization of watched files in project.go to use the new glob mapper and NormalizePath for consistency

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/project/watch.go Adds the glob mapper function and refactors directory lookup logic
internal/project/project.go Modifies watcher initialization to use the new glob mapper

packageDirPath *tspath.Path
}

func getDirectoryToWatchFailedLookupLocation(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pure port, basically line for line. I made no attempts to make it go any faster.

@ctrlplusb
Copy link

thank you for this. my machine was absolutely crunching.

@jakebailey jakebailey enabled auto-merge May 29, 2025 15:26
Copy link
Member

@andrewbranch andrewbranch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jakebailey jakebailey added this pull request to the merge queue May 29, 2025
Merged via the queue into main with commit ca643a8 May 29, 2025
23 checks passed
@jakebailey jakebailey deleted the jabaile/less-watch branch May 29, 2025 15:55
isRootWatchable bool,
currentDirectory string,
preferNonRecursiveWatch bool,
) *directoryOfFailedLookupWatch {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strada has baselines on what to watch : https://github.com/microsoft/TypeScript/blob/main/tests/baselines/reference/canWatch/getDirectoryToWatchFailedLookupLocationIndirDos.baseline.md like these. do we want these atleast till we have this logic and dont make this any faster.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do that, though I'm wary of continuing to have these sorts of super large baselines.

}

globs := make([]string, 0, len(globSet))
for dir, recursive := range globSet {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In strada there is code to watch "packageDir" if it exits and dir otherwise so we can handle the symlinks .. a note here to handle package symlinks later would be good

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I should have added that, yeah. Will follow up with that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was dogfooding tsgo so couldn't find all refs on it; is it just packageDir ?? dir?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its packageDir if packageDir exists and is symlink otherwise dir. Its in createDirectoryWatcherForPackageDir in strada. Its little complicated with having to manage state but since you dont need to, it should make it easier.

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

Successfully merging this pull request may close these issues.

Running the lsp causes my editor to rapidly consume all available memory
5 participants