perf: improve isFileReadable performance#12397
Conversation
|
|
patak-cat
left a comment
There was a problem hiding this comment.
Thanks for digging into Vite core @AriPerkkio! This sounds good to me.
|
We just noticed that the Anyway, I think it's still worth to merge this PR for possible future usage of |
|
For reference, @bluwy removed I still think we should merge this PR. |
bluwy
left a comment
There was a problem hiding this comment.
This seems to optimize towards failed checks more, which checking isFileReadable's usage, doesn't happen a lot, so I'm not sure 🤔
I'm not fully against not merging this though if others prefer to move forward, but I don't think there's a big reason to merge this yet, maybe it could be useful in the future. Thanks for investigating and fixing this though!
|
|
|
@sapphi-red would you like to break the tie here? I still think we should merge this one, as the cost of a failure is so much higger than the extra check introduced in the happy path. |
Description
In #6868 the
isFileReadablewas optimized to not usetry+catchfor figuring out if file does not exist. In #10793 this improvement was reverted in favor of filesystem access checks. This PR combines both of these together.This change has huge impact in performance when large amount of filesystem reads are done. In vitest-dev/vitest#3006 there is a reproduction case linked which runs 2.7s faster with these changes. If you need assistance for setting up the reproduction case let me know.
Before:
The
captureLargerStackTraceandhandleErrorFromBindingare fromfs.accessSync:After:
Additional context
There are existing tests which nicely cover all requirements:
vite/packages/vite/src/node/__tests__/utils.spec.ts
Lines 244 to 267 in a595b11
The cost of using
try+catchfor checking file system is well explained here: https://marvinh.dev/blog/speeding-up-javascript-ecosystem-part-2/What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).