Skip to content

resolutionCache getDirectoryToWatchFailedLookupLocation always sets recursive watcher for entire project #26002

Closed
@mprobst

Description

@mprobst

getDirectoryToWatchFailedLookupLocation in resolutionCache.ts checks if a failed lookup location is in the project's root dir, and if so, watches the entire project root, recursively (intentionally, it has a comment // Always watch root directory recursively).

For projects containing potentially very many subdirectories (just large projects, but also projects with large node_modules subtrees), this will read thousands of directories and create corresponding thousands of watchers.

I wonder if we could do better, but I don't understand the thinking that went into this. Was the idea that just having a recursive watch on the root is more effective than watching lots of more precise locations?

I'd consider only adding a watch for the closest non-existing file from the lookup location, e.g. for a location /foo/bar/baz/index.ts not being found, with baz/ not existing, a watch on /foo/bar would be sufficient, and create fewer watches and file reads than watching every file in the project recursively.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions