mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
perf: avoid building module graph if dynamic specifier already in graph (#24035)
This commit is contained in:
parent
94f040ac28
commit
814ac9a75d
7 changed files with 43 additions and 3 deletions
|
@ -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()
|
||||
|
|
8
tests/specs/run/dynamic_already_prepared/__test__.jsonc
Normal file
8
tests/specs/run/dynamic_already_prepared/__test__.jsonc
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"tests": {
|
||||
"skips_prepare_module_load": {
|
||||
"args": "run -A --log-level=debug main.ts",
|
||||
"output": "main.out"
|
||||
}
|
||||
}
|
||||
}
|
1
tests/specs/run/dynamic_already_prepared/dynamic.ts
Normal file
1
tests/specs/run/dynamic_already_prepared/dynamic.ts
Normal file
|
@ -0,0 +1 @@
|
|||
console.log(1);
|
1
tests/specs/run/dynamic_already_prepared/dynamic2.ts
Normal file
1
tests/specs/run/dynamic_already_prepared/dynamic2.ts
Normal file
|
@ -0,0 +1 @@
|
|||
await import("./dynamic3.ts");
|
1
tests/specs/run/dynamic_already_prepared/dynamic3.ts
Normal file
1
tests/specs/run/dynamic_already_prepared/dynamic3.ts
Normal file
|
@ -0,0 +1 @@
|
|||
await import("./dynamic.ts");
|
1
tests/specs/run/dynamic_already_prepared/main.out
Normal file
1
tests/specs/run/dynamic_already_prepared/main.out
Normal file
|
@ -0,0 +1 @@
|
|||
[WILDCARD]Prepared module load.[WILDCARD]Skipping prepare module load.[WILDCARD]Skipping prepare module load.[WILDCARD]Skipping prepare module load.[WILDCARD]
|
2
tests/specs/run/dynamic_already_prepared/main.ts
Normal file
2
tests/specs/run/dynamic_already_prepared/main.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
await import("./dynamic.ts");
|
||||
await import("./dynamic2.ts");
|
Loading…
Reference in a new issue