-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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: in-memory public files check #15195
Conversation
Run & review this pull request in StackBlitz Codeflow. |
@ArnaudBarre is telling me he implemented the same (+the watcher) in rds: https://github.com/ArnaudBarre/rds/blob/main/src/server/public.ts, we should check rds more often :) |
For ideas only, most of my implementations where never tested on Windows 👀 |
The watcher is now used to delete/add publicFiles to the in-memory cache, and the cache is also used in The |
We can't remove the |
/ecosystem-ci run |
📝 Ran ecosystem CI on
|
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.
Cool!
Here's the results of https://github.com/yyx990803/vite-dev-server-perf on my Windows machine. It's around 3%. before
after
|
Co-authored-by: 翠 / green <[email protected]>
Thanks for benchmarking! That isn't bad 🙌🏼 |
Should we wait for 5.1 to merge this one? I think it is fine to release it in a patch. |
It depends on when we start 5.1 beta for me. If we are starting in a week, then I'd say let's wait for that. |
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 think we can cut this as a patch since it shouldn't work too differently that before to be noticable. Nice perf fix!
I don't think we have enough minor-only PRs yet to justify starting work on 5.1, so let's go with this one in a patch then. |
This seems like a user-hostile change that feels like a regression given that it comes as a patch release. It does not match expectations that people have about Vite, considering that it doesn't work like that for source code. If you are sticking with this approach, how about integrating the behavior of |
@cpojer I implemented watching of public files before this PR was merged, see #15195 (comment) Are you seeing a regression? The public dir should work in the same way as before. We're probably going to remove this approach once we merge #15279, as we can use that same cache for the checks (that is more performant when there are symlinks) |
Oh fantastic, sorry I missed that change was part of this PR already 🤦♂️ |
Description
Around 4% of the time when running https://github.com/yyx990803/vite-dev-server-perf is spent on the serve public middleware.
This middleware will check every request before getting into the transform pipeline. Internally, it uses
sirv
, which does afs.existsSync
check for bothfilePath
andfilePath + '/index'
. It seems that we can't configure it to avoid the/index
suffix check, which I don't think we should be serving from the public dir. Even if this is fixed, there will still be a toll for every request because of the public dir feature.This PR reads the public dir recursively on server start and keeps an in-memory set of all public files so we can avoid going through sirv.
The drawback is that a server restart is needed if new files are added to the public directory. If we want to move forward with this PR, we could decide to watch the public dir and add new files.
We are currently patching sirv to add a
shouldServe
option, so we can do a case check in case-insensitive platforms. If we merge this PR, we can also remove this patch and the check because the in-memory map will already filter these out.What is the purpose of this pull request?