diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-05-24 10:15:46 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-24 10:15:46 -0400 |
commit | b21004b1d16ad7b67c7b1cd235abf792bf9d9777 (patch) | |
tree | 2a89a04d2d87d8e30a34beb97cbccf320dbef0ac /cli/cache | |
parent | 92a8d09e498712aec2ba0e54a1ad85194ebd83af (diff) |
fix: use hash of in-memory bytes only for code cache (#23966)
* https://github.com/denoland/deno_core/pull/752
* https://github.com/denoland/deno_core/pull/753
Did benchmarking on this and it's slightly faster (couple ms) or equal
to in performance as main.
Closes #23904
Diffstat (limited to 'cli/cache')
-rw-r--r-- | cli/cache/code_cache.rs | 31 | ||||
-rw-r--r-- | cli/cache/module_info.rs | 17 |
2 files changed, 15 insertions, 33 deletions
diff --git a/cli/cache/code_cache.rs b/cli/cache/code_cache.rs index 5e44c366e..8d96bf3a1 100644 --- a/cli/cache/code_cache.rs +++ b/cli/cache/code_cache.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use deno_ast::ModuleSpecifier; use deno_core::error::AnyError; use deno_runtime::code_cache; use deno_runtime::deno_webstorage::rusqlite::params; @@ -21,7 +22,6 @@ pub static CODE_CACHE_DB: CacheDBConfiguration = CacheDBConfiguration { on_failure: CacheFailure::Blackhole, }; -#[derive(Clone)] pub struct CodeCache { inner: CodeCacheInner, } @@ -52,28 +52,28 @@ impl CodeCache { pub fn get_sync( &self, - specifier: &str, + specifier: &ModuleSpecifier, code_cache_type: code_cache::CodeCacheType, - source_hash: &str, + source_hash: u64, ) -> Option<Vec<u8>> { Self::ensure_ok(self.inner.get_sync( - specifier, + specifier.as_str(), code_cache_type, - source_hash, + &source_hash.to_string(), )) } pub fn set_sync( &self, - specifier: &str, + specifier: &ModuleSpecifier, code_cache_type: code_cache::CodeCacheType, - source_hash: &str, + source_hash: u64, data: &[u8], ) { Self::ensure_ok(self.inner.set_sync( - specifier, + specifier.as_str(), code_cache_type, - source_hash, + &source_hash.to_string(), data, )); } @@ -82,25 +82,24 @@ impl CodeCache { impl code_cache::CodeCache for CodeCache { fn get_sync( &self, - specifier: &str, + specifier: &ModuleSpecifier, code_cache_type: code_cache::CodeCacheType, - source_hash: &str, + source_hash: u64, ) -> Option<Vec<u8>> { self.get_sync(specifier, code_cache_type, source_hash) } fn set_sync( &self, - specifier: &str, + specifier: ModuleSpecifier, code_cache_type: code_cache::CodeCacheType, - source_hash: &str, + source_hash: u64, data: &[u8], ) { - self.set_sync(specifier, code_cache_type, source_hash, data); + self.set_sync(&specifier, code_cache_type, source_hash, data); } } -#[derive(Clone)] struct CodeCacheInner { conn: CacheDB, } @@ -135,7 +134,7 @@ impl CodeCacheInner { &self, specifier: &str, code_cache_type: code_cache::CodeCacheType, - source_hash: &str, + source_hash: &str, // use string because sqlite doesn't have a u64 type data: &[u8], ) -> Result<(), AnyError> { let sql = " diff --git a/cli/cache/module_info.rs b/cli/cache/module_info.rs index 2e9274160..0e7a97678 100644 --- a/cli/cache/module_info.rs +++ b/cli/cache/module_info.rs @@ -87,23 +87,6 @@ impl ModuleInfoCache { } } - pub fn get_module_source_hash( - &self, - specifier: &ModuleSpecifier, - media_type: MediaType, - ) -> Result<Option<ModuleInfoCacheSourceHash>, AnyError> { - let query = "SELECT source_hash FROM moduleinfocache WHERE specifier=?1 AND media_type=?2"; - let res = self.conn.query_row( - query, - params![specifier.as_str(), serialize_media_type(media_type)], - |row| { - let source_hash: String = row.get(0)?; - Ok(ModuleInfoCacheSourceHash(source_hash)) - }, - )?; - Ok(res) - } - pub fn get_module_info( &self, specifier: &ModuleSpecifier, |