diff --git a/Cargo.lock b/Cargo.lock index de96ae8a07..d2ff4a6248 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3986,6 +3986,15 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "fixed-cache" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e0b787b8055e984fefc8a6a0709fc800d374dcb2794017799c0f245c75322d4" +dependencies = [ + "equivalent", +] + [[package]] name = "fixed-hash" version = "0.8.0" @@ -8243,6 +8252,7 @@ dependencies = [ "dashmap 6.1.0", "derive_more", "eyre", + "fixed-cache", "futures", "metrics", "metrics-util", diff --git a/crates/engine/tree/Cargo.toml b/crates/engine/tree/Cargo.toml index e877c83536..1f353ffce0 100644 --- a/crates/engine/tree/Cargo.toml +++ b/crates/engine/tree/Cargo.toml @@ -54,6 +54,7 @@ tokio = { workspace = true, features = ["rt", "rt-multi-thread", "sync", "macros mini-moka = { workspace = true, features = ["sync"] } moka = { workspace = true, features = ["sync"] } smallvec.workspace = true +fixed-cache = "0.1.1" # metrics metrics.workspace = true diff --git a/crates/engine/tree/src/tree/precompile_cache.rs b/crates/engine/tree/src/tree/precompile_cache.rs index 89ee7b8324..2f7cac6f95 100644 --- a/crates/engine/tree/src/tree/precompile_cache.rs +++ b/crates/engine/tree/src/tree/precompile_cache.rs @@ -31,7 +31,7 @@ where /// Cache for precompiles, for each input stores the result. #[derive(Debug, Clone)] pub struct PrecompileCache( - moka::sync::Cache, alloy_primitives::map::DefaultHashBuilder>, + Arc, alloy_primitives::map::DefaultHashBuilder>>, ) where S: Eq + Hash + std::fmt::Debug + Send + Sync + Clone + 'static; @@ -41,11 +41,7 @@ where S: Eq + Hash + std::fmt::Debug + Send + Sync + Clone + 'static, { fn default() -> Self { - Self( - moka::sync::CacheBuilder::new(MAX_CACHE_SIZE as u64) - .initial_capacity(MAX_CACHE_SIZE as usize) - .build_with_hasher(Default::default()), - ) + Self(Arc::new(fixed_cache::Cache::new(MAX_CACHE_SIZE as usize, Default::default()))) } } @@ -60,7 +56,7 @@ where /// Inserts the given key and value into the cache, returning the new cache size. fn insert(&self, input: Bytes, value: CacheEntry) -> usize { self.0.insert(input, value); - self.0.entry_count() as usize + MAX_CACHE_SIZE as usize } }