summaryrefslogtreecommitdiff
path: root/cli/cache
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-05-28 16:23:11 -0400
committerGitHub <noreply@github.com>2024-05-28 16:23:11 -0400
commit57617af16a4280aa3bc54292f18763942d67d460 (patch)
treef6246576cc8715c6cea1dc3ebe15720bde5bb512 /cli/cache
parent3e8f29ae4123abaddd9544a87e16448219fdd5f7 (diff)
perf: parse source files in parallel (#23858)
Diffstat (limited to 'cli/cache')
-rw-r--r--cli/cache/module_info.rs22
1 files changed, 15 insertions, 7 deletions
diff --git a/cli/cache/module_info.rs b/cli/cache/module_info.rs
index e34b8d2bb..959f84451 100644
--- a/cli/cache/module_info.rs
+++ b/cli/cache/module_info.rs
@@ -7,7 +7,6 @@ use deno_ast::ModuleSpecifier;
use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_graph::ModuleInfo;
-use deno_graph::ModuleParser;
use deno_graph::ParserModuleAnalyzer;
use deno_runtime::deno_webstorage::rusqlite::params;
@@ -15,6 +14,7 @@ use super::cache_db::CacheDB;
use super::cache_db::CacheDBConfiguration;
use super::cache_db::CacheFailure;
use super::FastInsecureHasher;
+use super::ParsedSourceCache;
const SELECT_MODULE_INFO: &str = "
SELECT
@@ -136,18 +136,18 @@ impl ModuleInfoCache {
pub fn as_module_analyzer<'a>(
&'a self,
- parser: &'a dyn ModuleParser,
+ parsed_source_cache: &'a Arc<ParsedSourceCache>,
) -> ModuleInfoCacheModuleAnalyzer<'a> {
ModuleInfoCacheModuleAnalyzer {
module_info_cache: self,
- parser,
+ parsed_source_cache,
}
}
}
pub struct ModuleInfoCacheModuleAnalyzer<'a> {
module_info_cache: &'a ModuleInfoCache,
- parser: &'a dyn ModuleParser,
+ parsed_source_cache: &'a Arc<ParsedSourceCache>,
}
#[async_trait::async_trait(?Send)]
@@ -177,9 +177,17 @@ impl<'a> deno_graph::ModuleAnalyzer for ModuleInfoCacheModuleAnalyzer<'a> {
}
// otherwise, get the module info from the parsed source cache
- // todo(23858): take advantage of this being async
- let analyzer = ParserModuleAnalyzer::new(self.parser);
- let module_info = analyzer.analyze(specifier, source, media_type).await?;
+ let module_info = deno_core::unsync::spawn_blocking({
+ let cache = self.parsed_source_cache.clone();
+ let specifier = specifier.clone();
+ move || {
+ let parser = cache.as_capturing_parser();
+ let analyzer = ParserModuleAnalyzer::new(&parser);
+ analyzer.analyze_sync(&specifier, source, media_type)
+ }
+ })
+ .await
+ .unwrap()?;
// then attempt to cache it
if let Err(err) = self.module_info_cache.set_module_info(