-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
fileExists() is called multiple times during module resolution on directories that do not exist #5601
Comments
This behaves as i would expect it to. what is the issue/question? |
Candidate directories are generated during node module resolution which are passed to loadNodeModuleFormFile ( or Directory ). If the candidate directory does not exist then 7 calls to fileExists() will be made. |
tsc uses a caching host implementation. the language services caches resolution results if they did not change, so this should not happen often. your host implementation can add optimizations to check if part of the path does not exist. |
@mhegazy Not sure why you wouldn't want to put a ts.sys.directoryExists() call on candidate directories to totally eliminate the chatter. Yes, I could optimize non-existing directories out of my caching host, but why not fix the root cause? It is all well and good that LS works well, but module resolution in program and compiler host should be efficient too. |
To improve the efficiency of node module resolution, you should consider starting the search at the process.cwd ( not the containing directory of the source file ). In any event, It is unlikely that node_modules will be found anywhere in the source sub-tree. |
I think there are two items to discuss:
In these circumstances I don't think that it is safe to apply this optimization.
|
Marking as |
I'd be happy to make a few changes to this area. I've already added a directoryExists optimization to my base compilerHost class. It will most likely be the first week in Dec before I can do the work to issue the PR however. I'd also like to work on the overall algorithm for external module resolution in program (I'll address your concerns above ). Please let me know if this is something you want. |
@vladima While setting up caching for module resolution in the host, I've run across module names that differ only in casing. What is the rule to use when module names only differ by case? Should host.useCaseSensitiveFileNames() apply? |
@vladima Module resolution in program should cache resolved modules. From looking at the code in LSHost this is the case. I understand that LS needs to be more performant, but why not put the same logic in program? |
the reason for this is current design of VS integration. In VS module resolution is done on the completely different instance of JS engine so it does not have access to the old instance of the program. |
@vladima Your idea to use baseUrl for module resolution is a good one ( issue #5039 ). I was going to make the suggestion that baseUrl be just the base directory of tsconfig.json and then have all module references be absolute or relative to the containing file or from the baseUrl. I was beginning to think this through, but it looks like you've got it figured out. |
During a single compile run of a small app, we see one fstat per parent directory per file. I.e. if you compile an application that has 200 files with an average directory depth of 6 or so, you'll end up doing The total number of possible If TSC would cache the absence of a folder instead of fstating over and over again, this could easily shave off a second of a 200 file compile. Though of course it's tricky to invalidate that cache. This problem is exacerbated in our particular setup as some folders are much more expensive to fstat than others (up to 100 ms). |
Note: in 1.8 |
When trying to resolve external modules, each module extension/location ( mod.ts, mod.tsx, mod.d.ts, mod/package.json, mod/index.ts, mod/index.tsx, mod/index.d.ts ), is tried even when the the base directory does not exist.
The text was updated successfully, but these errors were encountered: