-
-
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 package cache usage #12512
Conversation
and separate cache for optimizer
Run & review this pull request in StackBlitz Codeflow. |
// use separate package cache for optimizer as it caches paths around node_modules | ||
// and it's unlikely for the core Vite process to traverse into node_modules again | ||
const packageCache: PackageCache = new Map() |
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.
Good idea! It would still traverse for excluded deps but that is completely orthogonal to the paths cached here.
and split cache for optimizer esm and cjs resolvers
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
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.
Awesome PR 🔥
The same failures in vite-ecosystem-ci are in main
Description
This PR implements a smarter package caching algorithm.
Why and how
When we're given
/User/foo/bar/node_modules/my-lib/deep/deep/deep/file.js
, andfile.js
wants to getmy-dep/package.json
. When we found a match, we use/User/.../file.js
as the cache key for thePackageData
.However, we also know that if
/User/foo/bar/node_modules/my-lib/deep/another-file.js
happens to want to getmy-dep/package.json
too, it would get the samePackageData
too, because we had traversed the same directories to get there.This PR implements this, where the directories traversed while handling
/User/foo/bar/node_modules/my-lib/deep/deep/deep/file.js
are also cached, so thatanother-file
can fast-path to thePackageData
.Additional context
This is a huge change. I've broken up to multiple commits so it's easier to follow along, though it seems to be too many commits. Or you can review the diff directly too 💪
It looks like
packageCache
is used for two cases before, this PR preserves this oddness since it's easier to work with it, for now.More logs and notes on perf at https://gist.github.com/bluwy/53d11b29394c7e9e399f777fae099efc
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).