perf: temporary hack to avoid fs checks for /@react-refresh#15299
Merged
perf: temporary hack to avoid fs checks for /@react-refresh#15299
Conversation
|
|
Member
Author
|
/ecosystem-ci run |
|
📝 Ran ecosystem CI on
|
Member
Author
|
/ecosystem-ci run rakkas |
|
📝 Ran ecosystem CI on
|
ArnaudBarre
previously approved these changes
Dec 10, 2023
Member
ArnaudBarre
left a comment
There was a problem hiding this comment.
In an ideal world I would like the rollup plugin API with the namespace notion of esbuild.
This sounds reasonable for me, I think we should let bundler have some reserved chars before meta framework takes them all 😁
bluwy
approved these changes
Dec 12, 2023
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Edit: after internal discussions, the PR is only doing the workaround for
/@react-refresh. We'll remove this check once we have a proper solution to move the vite-plugin-react to use the\0convention or decide to properly formalize a new convention. @bluwy was proposing a new meta flag returned from resolve id for example. I would prefer that conventions keep being reflected on the path itself. Maybe we should expose a functionisVirtualModule(id)so we can at one point have an easier time in case a change in conventions is needed.In the profile for windows shared by @sapphi-red (recorded against #15279), the internal
normalizeUrlin the import analysis plugin is now taking more time thanresolveId. Most of the time is spent infs.existsSync.This is 2% of the total work now.
The cached fs tree isn't kicking here because we are checking if an out-of-root absolute path exists in the fs. But the real problem is that we are calling
fs.existsSync('/@react-refresh')over and over in this benchmark.vite-plugin-react-swc is using
/@react-refreshboth for authoring, and as the resolved id. See https://github.com/vitejs/vite-plugin-react-swc/blob/37f002cc9ecdf7e616004ad61ad9eeb3e3b6e873/src/index.ts#L73C8-L73C8. It isn't prefixing the id with the virtual file convention of\0.We could start prefixing the resolved virtual module with
\0. @ArnaudBarre, I think we should try to add that in the next major. I'm a bit afraid though in this case because there may be integrations that expect the resolved id to be/@react-refresh. It seems the ecosystem has this id harcoded everywhere. I think there are some plugins that could break here: https://github.com/search?q=%2F%40react-refresh&type=codeThe other problem is that
/@plugin-name/xxxis a convention that the ecosystem has widely used for resolved ids. This was started by us, with/@vite/client,/@fs/...,/@id/..., and/@react-refresh. And I saw/@vite-plugin-pwa,/@vite-plugin-pages/..., among others.Given that we already don't support URLs that are absolute paths starting with
/@vite,/@fs,/@idat the root of the filesystem. This PR generalizes that to URLs starting with/@. It only touches the check that is causing issues, which is done after resolving so plugins can't avoid it (there is even a comment in the react plugin about using orderpreto avoid fs calls).This is only for the root of the filesystem, and not the root of the project. We don't support
/@vite,/@fs,/@ideither at the root of the project though. I think we could in the future (next minor or major), formalize that/@...is a valid virtual module convention and also avoid checks at the root of the project. For now, I only added this check so we stop doing these expensive fs exists calls.A detail, in my M1, it seems it these checks aren't that expensive. We could also avoid the check only for Windows, where it makes even less sense to be checking for these paths, but I think it is better to do it for all platforms.
What is the purpose of this pull request?