-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
statSync without throwIfNoEntry: false
causes great performance impact when processing typescript imports
#181
Comments
throwIfNoEntry: false
causes great performance impact when processing typescript imports
@chenxinyanc Thanks a lot for your investigation! Does this mean the |
I just notice webpack/enhanced-resolve#316, so a PR is very welcome! return !!(path && fs.statSync(path, { throwIfNoEntry: false })?.isFile()) |
@JounQin I suppose so (if we have the lesure to be aggressive). There is no documentation on other Errors // ENOENT will cause statSync to return undefined if throwIfNoEntry is false.
Welcome to Node.js v14.17.6.
Type ".help" for more information.
> const fs = require('fs')
undefined
> fs.statSync("???")
Uncaught Error: ENOENT: no such file or directory, stat '???'
at Object.statSync (fs.js:1127:3) {
errno: -4058,
syscall: 'stat',
code: 'ENOENT',
path: '???'
}
> fs.statSync("\\\\?\\TEST")
Uncaught Error: ENOENT: no such file or directory, stat '\\?\TEST'
at Object.statSync (fs.js:1127:3) {
errno: -4058,
syscall: 'stat',
code: 'ENOENT',
path: '\\\\?\\TEST'
}
> fs.statSync("\\\\.\\TEST")
Uncaught Error: ENOENT: no such file or directory, stat '\\.\TEST'
at Object.statSync (fs.js:1127:3) {
errno: -4058,
syscall: 'stat',
code: 'ENOENT',
path: '\\\\.\\TEST'
} |
I think I can work on a PR later today. |
As part of the effort to reduce our project's lint time, I've profiled eslint process to find out the hot path is on the following line of the
isFile
functioneslint-import-resolver-typescript/src/index.ts
Lines 244 to 250 in d8dd3ca
Please note that allowing
statSync
to throw error for non-existent files will take a lot of precious CPU time generating a user readable stack trace (captureLargerStackTrace
) only to be discarded by thetry...catch
block in thisisFile
function. Is it possible to usethrowIfNoEntry
in this case?I've tried to monkey-patch the package with the following diff (generated by yarn v2):
Here is the time consumption difference in a project with 478 files linted.
BEFORE PATCH
AFTER PATCH
Time consumed is reduced to around 1/2.8 by this little patch.
I don't have time for a clean repro for this, but if you have more data points by applying this patch, please post it here. It would be helpful. Thanks!
The text was updated successfully, but these errors were encountered: