Skip to content
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

fix(resolve): separate package cache per environment #18319

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

hi-ogawa
Copy link
Collaborator

@hi-ogawa hi-ogawa commented Oct 10, 2024

Description

Alternative approach #18302 (comment)

This PR separates PackageCache per environment using environment.config proxy. I replaced config.packageCache with environment.config.packageCache through the code base (seems straight-forward except watchPackageDataPlugin).

Copy link

stackblitz bot commented Oct 10, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@hi-ogawa hi-ogawa marked this pull request as ready for review October 10, 2024 06:04
@@ -64,6 +65,7 @@ export class PartialEnvironment {
this.name = name
this._topLevelConfig = topLevelConfig
this._options = options
const packageCache: PackageCache = new Map()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is going to far. The PackageCache has two mixed caches:
a. The path -> PackageData cache
b. the resolved cache in each PackageData (the getResolvedCache/setResolvedCache pair)

We still need (a) to be per-config and not per-environment. This cache doesn't depend on environment-specific options. We need to make only (b) per-environment.

What I was thinking is that PackageCache will remain as-is, the cache from (b) is removed from PackageData. And a new ResolvedCache is created per-environment that will expose resolvedCache.get(packageData, key). This cache is passed to the resolve plugin that is the only place where it is used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC making (b) per-environment is not enough. It also needs to be separated whether it's a resolve for require or import. Otherwise, #16631 would be still broken.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing something. I would expect the PackageData (without the Resolved Cache part) would be the same for both in that case 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Splitting entire PackageData seems redundant. Let me iterate a bit more.

Should we go with #18302 for now? I can follow up separately with your idea.

Copy link
Collaborator Author

@hi-ogawa hi-ogawa Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC making (b) per-environment is not enough. It also needs to be separated whether it's a resolve for require or import. Otherwise, #16631 would be still broken.

For this, I was thinking we still need to expand isRequire as a cache key, which we aren't doing. But, for other flags conditions, mainFields, ..., we can assume those are static per environment, so we don't need to include it as cache key, which was the heavy part of #18302

@hi-ogawa hi-ogawa marked this pull request as draft October 10, 2024 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants