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

perf: module graph url shortcuts #12635

Merged
merged 17 commits into from Mar 30, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/vite/src/node/server/moduleGraph.ts
Expand Up @@ -72,6 +72,13 @@ export class ModuleGraph {
rawUrl: string,
ssr?: boolean,
): Promise<ModuleNode | undefined> {
// Quick path, if we already have a module for this rawUrl (even without extension)
const cleanedUrl = removeImportQuery(removeTimestampQuery(rawUrl))
const mod = this.urlToModuleMap.get(cleanedUrl)
bluwy marked this conversation as resolved.
Show resolved Hide resolved
if (mod) {
return mod
}

const [url] = await this.resolveUrl(rawUrl, ssr)
return this.urlToModuleMap.get(url)
}
Expand Down Expand Up @@ -189,8 +196,15 @@ export class ModuleGraph {
ssr?: boolean,
setIsSelfAccepting = true,
): Promise<ModuleNode> {
// Quick path, if we already have a module for this rawUrl (even without extension)
const cleanedUrl = removeImportQuery(removeTimestampQuery(rawUrl))
let mod = this.urlToModuleMap.get(cleanedUrl)
if (mod) {
return mod
}

const [url, resolvedId, meta] = await this.resolveUrl(rawUrl, ssr)
let mod = this.idToModuleMap.get(resolvedId)
mod = this.idToModuleMap.get(resolvedId)
if (!mod) {
mod = new ModuleNode(url, setIsSelfAccepting)
if (meta) mod.meta = meta
Expand All @@ -210,6 +224,11 @@ export class ModuleGraph {
else if (!this.urlToModuleMap.has(url)) {
this.urlToModuleMap.set(url, mod)
}
// Also register the clean url to the module, so that we can short-circuit
// resolving the same url twice
if (!this.urlToModuleMap.has(cleanedUrl)) {
this.urlToModuleMap.set(cleanedUrl, mod)
}
return mod
}

Expand Down