diff --git a/accounts-db/src/read_only_accounts_cache.rs b/accounts-db/src/read_only_accounts_cache.rs index 79581ee55edc41..57185b1c744561 100644 --- a/accounts-db/src/read_only_accounts_cache.rs +++ b/accounts-db/src/read_only_accounts_cache.rs @@ -31,6 +31,11 @@ use { const CACHE_ENTRY_SIZE: usize = std::mem::size_of::() + 2 * std::mem::size_of::(); +/// Number of cache shards. This number is close to the number of accounts +/// in cache observed on mainnet beta validators, therefore it should result +/// in each accout having its own shard and reduced amount of locks. +const SHARDS: usize = 65536; + type ReadOnlyCacheKey = Pubkey; #[derive(Debug)] @@ -98,7 +103,7 @@ impl ReadOnlyAccountsCache { ) -> Self { assert!(max_data_size_lo <= max_data_size_hi); assert!(evict_sample_size > 0); - let cache = Arc::new(DashMap::default()); + let cache = Arc::new(DashMap::with_shard_amount(SHARDS)); let data_size = Arc::new(AtomicUsize::default()); let stats = Arc::new(AtomicReadOnlyCacheStats::default()); let evictor_exit_flag = Arc::new(AtomicBool::new(false));