From e212e1fc35ddae63f457f0f2a2e95154e008941f Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 8 Jan 2024 12:18:42 -0500 Subject: perf: skip expanding exclude globs (#21817) We were calling `expand_glob` on our excludes, which is very expensive and unnecessary because we can pattern match while traversing instead. 1. Doesn't expand "exclude" globs. Instead pattern matches while walking the directory. 2. Splits up the "include" into base paths and applicable file patterns. This causes less pattern matching to occur because we're only pattern matching on patterns that might match and not ones in completely unrelated directories. --- cli/graph_util.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'cli/graph_util.rs') diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 524799860..b4f4b939a 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -16,6 +16,8 @@ use crate::resolver::SloppyImportsResolver; use crate::tools::check; use crate::tools::check::TypeChecker; use crate::util::file_watcher::WatcherCommunicator; +use crate::util::fs::canonicalize_path; +use crate::util::path::specifier_to_file_path; use crate::util::sync::TaskQueue; use crate::util::sync::TaskQueuePermit; @@ -677,7 +679,7 @@ impl ModuleGraphContainer { pub fn has_graph_root_local_dependent_changed( graph: &ModuleGraph, root: &ModuleSpecifier, - changed_specifiers: &HashSet, + canonicalized_changed_paths: &HashSet, ) -> bool { let roots = vec![root.clone()]; let mut dependent_specifiers = graph.walk( @@ -689,11 +691,15 @@ pub fn has_graph_root_local_dependent_changed( }, ); while let Some((s, _)) = dependent_specifiers.next() { - if s.scheme() != "file" { + if let Ok(path) = specifier_to_file_path(s) { + if let Ok(path) = canonicalize_path(&path) { + if canonicalized_changed_paths.contains(&path) { + return true; + } + } + } else { // skip walking this remote module's dependencies dependent_specifiers.skip_previous_dependencies(); - } else if changed_specifiers.contains(s) { - return true; } } false -- cgit v1.2.3