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: reduce size of injected __vite__mapDeps code #16184
Conversation
This also replaces the lazy initialization of with eager one.
Run & review this pull request in StackBlitz Codeflow. |
Lint failed but I couldn't find any linter output, so I don't see what is the problem |
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! This looks great to me. Something I'd also like to followup later is to remove the mapDeps
altogether if no preloading is needed for the file. Currently it's added unconditionally. And the changes could get a bit big.
Also related: #15300 (comment)
Yea, I noticed that too. It can also be removed when there's only single callsite, which is another pretty common case (at least in my codebase). (Even more generalized version could also omit it when the imported files at each callsite are distinct or distinct enough to outweigh the added code) |
I think this should be a simple fix in a patch and not for 5.3 🤔 |
In the past, there have been downstream projects doing regexes over our preload handling to inject or modify stuff. So I'm always a bit worried about touching this part. I'll trigger a ecosystem CI run. I'm ok if you want to move forward with this in a patch if it is all green. /ecosystem-ci run |
I felt this to be in the blur between minor and patch. If the ecosystem-ci passes, I'm fine with merging it with a patch.
|
/ecosystem-ci run |
📝 Ran ecosystem CI on
✅ analogjs, astro, histoire, ladle, laravel, marko, previewjs, quasar, qwik, rakkas, remix, sveltekit, unocss, vike, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-pages, vite-plugin-react-swc, vite-plugin-svelte, vite-plugin-vue, vite-setup-catalogue, vitepress, vitest |
The Nuxt fail seems like a fluke since it's a dev fixture test, but I reran it again. I haven't seen downstream patching this in the past, so I figured it should be safe (but still, it's on them). |
📝 Ran ecosystem CI on
✅ analogjs, astro, histoire, ladle, laravel, marko, previewjs, quasar, qwik, rakkas, remix, sveltekit, unocss, vike, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-pages, vite-plugin-react-swc, vite-plugin-svelte, vite-plugin-vue, vite-setup-catalogue, vitepress, vitest |
I guess it's failing because the base commit was a bit old. |
/ecosystem-ci run |
📝 Ran ecosystem CI on ✅ analogjs, astro, histoire, ladle, laravel, marko, nuxt, previewjs, quasar, qwik, rakkas, remix, sveltekit, unocss, vike, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-pages, vite-plugin-react-swc, vite-plugin-svelte, vite-plugin-vue, vite-setup-catalogue, vitepress, vitest |
Thanks for resolving it Sapphi, the fail had me defeated 😄 Since it passes on ecosystem-ci, I'll go ahead and merge this then. |
Thanks for carrying this through! |
Co-authored-by: bluwy <bjornlu.dev@gmail.com> Co-authored-by: 翠 / green <green@sapphi.red> Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Description
This reduces size of injected
__vite__mapDeps
code by roughly a factor of 2 (not counting the dependency list) using few minification tricks.The main ideas are:
function
with arrow function, which is shorter (Especially when braces can be ommited)Note that it also removes the lazy initialization of the dependency list array. I honestly don't see the benefit of doing it, but if it's desirable to keep it, there's another version of the function that keeps the behaviour unchanged (except for renaming the internal function object property, which is also optional, though):
This version uses optional parameters to:
const|let
keyword[edit]
I found a comment on original PR that explains why the lazy initialization is there. https://github.com/vitejs/vite/pull/14550/files#r1350449734
I might have to re-add it, but let's see if there's a demand for merging this in the first place. I tested this locally on my project and patched it in GitHub UI, so I haven't seen the impact on tests, yet.
Additional context
This optimization was first added here: #14550
cc @gajus who contributed the original implemetation.
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).