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(moduleGraph): resolve dep urls in parallel #12619

Merged
merged 3 commits into from Mar 29, 2023
Merged
Changes from 1 commit
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
38 changes: 27 additions & 11 deletions packages/vite/src/node/server/moduleGraph.ts
Expand Up @@ -150,15 +150,24 @@ export class ModuleGraph {
const prevImports = mod.importedModules
const nextImports = (mod.importedModules = new Set())
let noLongerImported: Set<ModuleNode> | undefined
let resolvePromises = []
// update import graph
for (const imported of importedModules) {
const dep =
typeof imported === 'string'
? await this.ensureEntryFromUrl(imported, ssr)
: imported
dep.importers.add(mod)
nextImports.add(dep)
if (typeof imported === 'string') {
resolvePromises.push(
this.ensureEntryFromUrl(imported, ssr).then((dep) => {
dep.importers.add(mod)
nextImports.add(dep)
}),
)
} else {
imported.importers.add(mod)
nextImports.add(imported)
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 it would be a good idea to keep the nextImports in the same order as before, at least to help with debugging and to make the runs more stable.

We could await for the result of Promise.all and then add that to nextImports in order.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

}
}

resolvePromises.length && (await Promise.all(resolvePromises))
bluwy marked this conversation as resolved.
Show resolved Hide resolved
sun0day marked this conversation as resolved.
Show resolved Hide resolved

// remove the importer from deps that were imported but no longer are.
prevImports.forEach((dep) => {
if (!nextImports.has(dep)) {
Expand All @@ -169,15 +178,22 @@ export class ModuleGraph {
}
}
})

// update accepted hmr deps
const deps = (mod.acceptedHmrDeps = new Set())
resolvePromises = []
for (const accepted of acceptedModules) {
const dep =
typeof accepted === 'string'
? await this.ensureEntryFromUrl(accepted, ssr)
: accepted
deps.add(dep)
if (typeof accepted === 'string') {
resolvePromises.push(
this.ensureEntryFromUrl(accepted, ssr).then((dep) => deps.add(dep)),
)
} else {
deps.add(accepted)
}
}

resolvePromises.length && (await Promise.all(resolvePromises))
sun0day marked this conversation as resolved.
Show resolved Hide resolved

// update accepted hmr exports
mod.acceptedHmrExports = acceptedExports
mod.importedBindings = importedBindings
Expand Down