Skip to content

Skip more work when creating LSP watch globs #1015

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 1 commit into from
Jun 2, 2025
Merged

Conversation

jakebailey
Copy link
Member

I realized after the fact that getDirectoryToWatchFailedLookupLocation doesn't really care about the actual contents of the path, just how the parts split apart and where node_modules is. This means that passing in /foo/node_modules/bar/index.js and /foo/node_modules/bar/blah.js will return identical results.

Prevent the expensive call to getDirectoryToWatchFailedLookupLocation by only doing it once per dirname.

In my testing, this halves the amount of time spent mapping paths to globs. From:

Info 9    [11:42:17.604] createGlobMapper took 86.409653ms to create 3 globs for 31663 failed lookups
Info 10   [11:42:17.739] failed lookup watches updated watcher-1:
	/home/jabaile/work/node_modules/**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,json}
	/home/jabaile/work/vscode/node_modules/**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,json}
	/home/jabaile/work/vscode/src/**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,json}

To:

Info 9    [11:43:02.173] createGlobMapper took 37.743599ms to create 3 globs for 31663 failed lookups
Info 10   [11:43:02.409] failed lookup watches updated watcher-1:
	/home/jabaile/work/node_modules/**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,json}
	/home/jabaile/work/vscode/node_modules/**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,json}
	/home/jabaile/work/vscode/src/**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,json}

The halving also carries over to #995.

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 improves performance by reducing redundant calls to getDirectoryToWatchFailedLookupLocation when creating LSP watch globs.

  • Introduces caching of directory paths using a Set from the core package.
  • Skips duplicate processing for files within the same directory to halve the work required for lookup globs.
Comments suppressed due to low confidence (1)

internal/project/watch.go:105

  • [nitpick] Consider renaming 'seenDirs' to 'processedDirectories' for improved clarity on its purpose.
var seenDirs core.Set[string]

@jakebailey
Copy link
Member Author

Test failure is an ATA flake. Looking into that right now.

@jakebailey jakebailey added this pull request to the merge queue Jun 2, 2025
Merged via the queue into main with commit e0c0e9c Jun 2, 2025
41 of 43 checks passed
@jakebailey jakebailey deleted the jabaile/fewer-globs branch June 2, 2025 21:03
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.

3 participants