-
-
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(resolve): reduce vite client path checks #12471
Conversation
Run & review this pull request in StackBlitz Codeflow. |
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
Given (Currently trying some things out locally) |
The problem is what happens if you alias to The other issue is that aliases may not be resolved, so we could no longer do #12450 (maybe we need a new |
Yeah I was thinking we can do a one-time pass to verify if
I don't think it would affect #12450 since the idea doesn't interfere with |
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.
Through some test, optimizing alias that maps to absolute paths is doable, but makes the code a bit complex. They are usually resolved under 1ms too, so I don't think it's worth it for now. Since this Vite client path is something we control, I think we can try this 👍
packages/vite/src/node/config.ts
Outdated
{ find: /^\/?@vite\/env/, replacement: FS_PREFIX + ENV_ENTRY }, | ||
{ find: /^\/?@vite\/client/, replacement: FS_PREFIX + CLIENT_ENTRY }, |
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 wonder if we should also clean up and do path.posix.join
instead. It's done at ,
vite/packages/vite/src/node/plugins/asset.ts
Line 253 in 1a8af8d
rtn = path.posix.join(FS_PREFIX, id) |
url = path.posix.join(FS_PREFIX, resolved.id) |
but not at
const url = `${FS_PREFIX}${file}` |
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.
Switched to path.posix.join
in vitejs/vite@656e5d2
(#12471)
Should we add isFsPathId
and fsPathToId
in another PR and use them everywhere?
export function isFsPathId(id: string): boolean {
return id.startsWith(FS_PREFIX)
}
export function fsPathToId(fsPath: string): string {
return path.posix.join(FS_PREFIX, normalizePath(fsPath))
}
export function fsPathFromId(fsPath: string): string {
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.
Forgot to reply 😅 I don't really have a hard opinion if we want to abstract it, but usually I lean on not abstracting things until it becomes a problem.
Also maybe we can go ahead with this PR too now.
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 maybe we wait for this one a bit more. If #12450 is merged, then we will win a bit, but if not, I think we won't be winning much.
Let's try this one then now that #12450 has been merged |
Description
@vite/client
is an alias replaced by the resolved path to the vite client/root/.../client.mjs
. This id reaches the resolve plugin first and it is then tested against root here. SotryFsResolve
is called with/root/root/.../client.mjs
, resulting in failed checks (like/root/root/.../client.mjs.ts
, and all the default extensions).This PR modifies the alias to use
/@fs/root/.../client.mjs
, so the resolve plugin will directly try this path and resolve it.If #12450 is merged, then there will not even be a fs check for this path.
What is the purpose of this pull request?