Skip to content
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

perf: avoid unnecessary fs.statSync calls #206

Merged
merged 1 commit into from Jan 11, 2023

Conversation

marvinhagemeister
Copy link
Contributor

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.

.filter(mappedPath => isFile(mappedPath) || isModule(mappedPath))

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 an ENOTDIR 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:

Screenshot 2023-01-10 at 15 09 11

After:

Screenshot 2023-01-10 at 15 09 16

@changeset-bot
Copy link

changeset-bot bot commented Jan 10, 2023

🦋 Changeset detected

Latest commit: a89bdbd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-import-resolver-typescript Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 10, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

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 many files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants