diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-05-29 14:59:35 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-29 14:59:35 -0400 |
commit | 814ac9a75d343435ac7c8c2ff6dad8ab89eb8a4c (patch) | |
tree | e05c48575caa6ffdf48eb579b517876adb2e658a /cli/module_loader.rs | |
parent | 94f040ac2867706d261e2fe1ec8bc2c4263eb6ab (diff) |
perf: avoid building module graph if dynamic specifier already in graph (#24035)
Diffstat (limited to 'cli/module_loader.rs')
-rw-r--r-- | cli/module_loader.rs | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/cli/module_loader.rs b/cli/module_loader.rs index 91227802a..e5f45ea3c 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -171,7 +171,7 @@ impl ModuleLoadPreparer { ) .await?; - self.module_graph_builder.graph_roots_valid(graph, roots)?; + self.graph_roots_valid(graph, roots)?; // write the lockfile if there is one if let Some(lockfile) = &self.lockfile { @@ -205,6 +205,14 @@ impl ModuleLoadPreparer { Ok(()) } + + pub fn graph_roots_valid( + &self, + graph: &ModuleGraph, + roots: &[ModuleSpecifier], + ) -> Result<(), AnyError> { + self.module_graph_builder.graph_roots_valid(graph, roots) + } } struct SharedCliModuleLoaderState { @@ -806,8 +814,26 @@ impl<TGraphContainer: ModuleGraphContainer> ModuleLoader let inner = self.0.clone(); async move { - let graph_container = inner.graph_container.clone(); - let module_load_preparer = inner.shared.module_load_preparer.clone(); + let graph_container = &inner.graph_container; + let module_load_preparer = &inner.shared.module_load_preparer; + + if is_dynamic { + // When the specifier is already in the graph then it means it + // was previously loaded, so we can skip that and only check if + // this part of the graph is valid. + // + // This doesn't acquire a graph update permit because that will + // clone the graph which is a bit slow. + let graph = graph_container.graph(); + if !graph.roots.is_empty() && graph.get(&specifier).is_some() { + log::debug!("Skipping prepare module load."); + // roots are already validated so we can skip those + if !graph.roots.contains(&specifier) { + module_load_preparer.graph_roots_valid(&graph, &[specifier])?; + } + return Ok(()); + } + } let root_permissions = if is_dynamic { inner.dynamic_permissions.clone() |