You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 function
constisFile=(path?: string|undefined): path is string=>{
try{
return!!path&&fs.statSync(path).isFile()
}catch{
returnfalse
}
}
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 the try...catch block in this isFile function. Is it possible to use throwIfNoEntry in this case?
constisFile=(path?: string|undefined): path is string=>{return!!path&&fs.statSync(path,{throwIfNoEntry: false})?.isFile();}
I've tried to monkey-patch the package with the following diff (generated by yarn v2):
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:
chenxinyanc
changed the title
statSync without throwIfNoEntry: false causes great performance impact when processing typescript imports
statSync without throwIfNoEntry: false causes great performance impact when processing typescript imports
Sep 7, 2022
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: