perf: avoid duplicate module resolution in dev transform requests - #23408
Open
dmchoi77 wants to merge 1 commit into
Open
perf: avoid duplicate module resolution in dev transform requests#23408dmchoi77 wants to merge 1 commit into
dmchoi77 wants to merge 1 commit into
Conversation
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.
Summary
Avoid resolving the same URL twice in the development server's cache-miss transform path.
transformRequestnow receives both the module lookup result and the resolved result from a single module graph operation, so it can reuse the resolver result instead of invokingresolveIdagain.Background
Before this change, the uncached transform request flow was:
moduleGraph.getModuleByUrl(url)resolves the URL and looks up the module graph.transformRequestcallspluginContainer.resolveId()for the same URL again.The first resolved result is already available during the module lookup, but it is discarded instead of being returned to the caller. This duplicate work can accumulate across a large module graph, especially when resolver hooks are expensive or many resolver plugins are configured.
Changes
EnvironmentModuleGraph._getModuleByUrlAndResolved().transformRequest._ensureEntryFromUrl()and_resolveUrl()to reuse a resolvednullresult explicitly.metapreservation and duplicate resolver avoidance.Related Prior Work
This change is related to #13085, but addresses a different stage of the transform request flow.
loadAndTransform()could produce a different resolver result. It passed the already computedresolvedresult to_ensureEntryFromUrl().transformRequestmodule lookup path. The new_getModuleByUrlAndResolved()helper returns both the module lookup result and the resolved result, allowing the secondresolveId()call for the same URL to be skipped.Verification
pnpm exec vitest run packages/vite/src/node/server/__tests__/moduleGraph.spec.ts packages/vite/src/node/__tests__/dev.spec.ts