-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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: improve isFileReadable performance #12397
Conversation
Run & review this pull request in StackBlitz Codeflow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm slightly 👍 with this.
Description
In #6868 the
isFileReadable
was optimized to not usetry
+catch
for 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
captureLargerStackTrace
andhandleErrorFromBinding
are 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
+catch
for 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
).