diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-08-08 11:41:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-08 09:41:30 +0000 |
commit | 6fce23c54ec619168eee096fc7bf801d0cec0cb6 (patch) | |
tree | 211d715cf75817a09c63e6dad943d6623eef67f1 /cli/cache | |
parent | 93d479252b5a18e6e782c74b808240bd3ef036bd (diff) |
perf: skip saving to emit cache after first failure (#24896)
Diffstat (limited to 'cli/cache')
-rw-r--r-- | cli/cache/emit.rs | 22 | ||||
-rw-r--r-- | cli/cache/mod.rs | 4 |
2 files changed, 17 insertions, 9 deletions
diff --git a/cli/cache/emit.rs b/cli/cache/emit.rs index 1d903fbba..fcec9e84b 100644 --- a/cli/cache/emit.rs +++ b/cli/cache/emit.rs @@ -6,6 +6,7 @@ use deno_ast::ModuleSpecifier; use deno_core::anyhow::anyhow; use deno_core::error::AnyError; use deno_core::serde_json; +use deno_core::unsync::sync::AtomicFlag; use serde::Deserialize; use serde::Serialize; @@ -19,10 +20,10 @@ struct EmitMetadata { } /// The cache that stores previously emitted files. -#[derive(Clone)] pub struct EmitCache { disk_cache: DiskCache, cli_version: &'static str, + emit_failed_flag: AtomicFlag, } impl EmitCache { @@ -30,6 +31,7 @@ impl EmitCache { Self { disk_cache, cli_version: crate::version::deno(), + emit_failed_flag: Default::default(), } } @@ -87,12 +89,10 @@ impl EmitCache { code: &[u8], ) { if let Err(err) = self.set_emit_code_result(specifier, source_hash, code) { - // should never error here, but if it ever does don't fail - if cfg!(debug_assertions) { - panic!("Error saving emit data ({specifier}): {err}"); - } else { - log::debug!("Error saving emit data({}): {}", specifier, err); - } + // might error in cases such as a readonly file system + log::debug!("Error saving emit data ({}): {}", specifier, err); + // assume the cache can't be written to and disable caching to it + self.emit_failed_flag.raise(); } } @@ -102,6 +102,11 @@ impl EmitCache { source_hash: u64, code: &[u8], ) -> Result<(), AnyError> { + if self.emit_failed_flag.is_raised() { + log::debug!("Skipped emit cache save of {}", specifier); + return Ok(()); + } + let meta_filename = self .get_meta_filename(specifier) .ok_or_else(|| anyhow!("Could not get meta filename."))?; @@ -161,6 +166,7 @@ mod test { let cache = EmitCache { disk_cache: disk_cache.clone(), cli_version: "1.0.0", + emit_failed_flag: Default::default(), }; let to_string = |bytes: Vec<u8>| -> String { String::from_utf8(bytes).unwrap() }; @@ -192,6 +198,7 @@ mod test { let cache = EmitCache { disk_cache: disk_cache.clone(), cli_version: "2.0.0", + emit_failed_flag: Default::default(), }; assert_eq!(cache.get_emit_code(&specifier1, 10), None); cache.set_emit_code(&specifier1, 5, emit_code1.as_bytes()); @@ -200,6 +207,7 @@ mod test { let cache = EmitCache { disk_cache, cli_version: "2.0.0", + emit_failed_flag: Default::default(), }; assert_eq!( cache.get_emit_code(&specifier1, 5).map(to_string), diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index 3430f74f7..772d2359d 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -106,7 +106,7 @@ pub use deno_cache_dir::HttpCache; /// A "wrapper" for the FileFetcher and DiskCache for the Deno CLI that provides /// a concise interface to the DENO_DIR when building module graphs. pub struct FetchCacher { - emit_cache: EmitCache, + emit_cache: Arc<EmitCache>, file_fetcher: Arc<FileFetcher>, file_header_overrides: HashMap<ModuleSpecifier, HashMap<String, String>>, global_http_cache: Arc<GlobalHttpCache>, @@ -118,7 +118,7 @@ pub struct FetchCacher { impl FetchCacher { pub fn new( - emit_cache: EmitCache, + emit_cache: Arc<EmitCache>, file_fetcher: Arc<FileFetcher>, file_header_overrides: HashMap<ModuleSpecifier, HashMap<String, String>>, global_http_cache: Arc<GlobalHttpCache>, |