perf: avoid unnecessary fs.statSync
calls
#206
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Only resolve a module dir when we now that the mapped path is a directory. This improves linting time by about 18% in projects with lots of files.
The reason for the speedup is an accidental overhead in the callback of the filter function.
eslint-import-resolver-typescript/src/index.ts
Line 290 in 46de0e8
There we check if something resolves to file, and if not we'll check if it is a module directory. But in 99% of cases we'll be resolving file extensions in this callback. If
/foo/bar/package.json
is not a file, then it's very unlikely that/foo/bar.ts/package.json
will be, unless/foo/bar.ts
is a directory. Before this PR we'd check for the latter regardless which lead to anENOTDIR
error being thrown. The mere overhead of constantly throwing this error is where most of the time was spent in the traces I looked at.Overall the logic can be improved further, but I think for now this PR reduces most of the overhead of calling into
fs.statSync
.Before:
After: