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/module_loader.rs | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'cli/module_loader.rs') diff --git a/cli/module_loader.rs b/cli/module_loader.rs index f79576108..9a2c511ff 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -224,7 +224,7 @@ impl ModuleLoadPreparer { ) -> Result<(), AnyError> { let lib = self.options.ts_type_lib_window(); - let specifiers = self.collect_specifiers(files); + let specifiers = self.collect_specifiers(files)?; self .prepare_module_load( specifiers, @@ -235,28 +235,30 @@ impl ModuleLoadPreparer { .await } - fn collect_specifiers(&self, files: &[String]) -> Vec { - let excludes = match self.options.resolve_check_options() { - Ok(o) => o.exclude, - Err(_) => vec![], - }; - files - .iter() - .filter_map(|file| { - let file_url = - resolve_url_or_path(file, self.options.initial_cwd()).ok()?; - if file_url.scheme() != "file" { - return Some(file_url); - } - // ignore local files that match any of files listed in `exclude` option - let file_path = file_url.to_file_path().ok()?; - if excludes.iter().any(|e| file_path.starts_with(e)) { - None - } else { - Some(file_url) - } - }) - .collect::>() + fn collect_specifiers( + &self, + files: &[String], + ) -> Result, AnyError> { + let excludes = self.options.resolve_config_excludes()?; + Ok( + files + .iter() + .filter_map(|file| { + let file_url = + resolve_url_or_path(file, self.options.initial_cwd()).ok()?; + if file_url.scheme() != "file" { + return Some(file_url); + } + // ignore local files that match any of files listed in `exclude` option + let file_path = file_url.to_file_path().ok()?; + if excludes.matches_path(&file_path) { + None + } else { + Some(file_url) + } + }) + .collect::>(), + ) } } -- cgit v1.2.3