diff --git a/runtime/src/in_mem_accounts_index.rs b/runtime/src/in_mem_accounts_index.rs index b2f5897448..93511de994 100644 --- a/runtime/src/in_mem_accounts_index.rs +++ b/runtime/src/in_mem_accounts_index.rs @@ -36,20 +36,6 @@ impl InMemAccountsIndex { Arc::new(BucketMapHolder::new()) } - fn entry(&mut self, pubkey: Pubkey) -> Entry> { - let m = Measure::start("entry"); - let result = self.map.entry(pubkey); - let stats = &self.storage.stats; - let (count, time) = if matches!(result, Entry::Occupied(_)) { - (&stats.entries_from_mem, &stats.entry_mem_us) - } else { - (&stats.entries_missing, &stats.entry_missing_us) - }; - Self::update_time_stat(time, m); - Self::update_stat(count, 1); - result - } - pub fn items(&self, range: &Option<&R>) -> Vec<(K, AccountMapEntry)> where R: RangeBounds + std::fmt::Debug, @@ -86,7 +72,18 @@ impl InMemAccountsIndex { // If the slot list for pubkey exists in the index and is empty, remove the index entry for pubkey and return true. // Return false otherwise. pub fn remove_if_slot_list_empty(&mut self, pubkey: Pubkey) -> bool { - if let Entry::Occupied(index_entry) = self.entry(pubkey) { + let m = Measure::start("entry"); + let entry = self.map.entry(pubkey); + let stats = &self.storage.stats; + let (count, time) = if matches!(entry, Entry::Occupied(_)) { + (&stats.entries_from_mem, &stats.entry_mem_us) + } else { + (&stats.entries_missing, &stats.entry_missing_us) + }; + Self::update_time_stat(time, m); + Self::update_stat(count, 1); + + if let Entry::Occupied(index_entry) = entry { if index_entry.get().slot_list.read().unwrap().is_empty() { index_entry.remove(); self.stats().insert_or_delete(false, self.bin); @@ -103,7 +100,17 @@ impl InMemAccountsIndex { reclaims: &mut SlotList, previous_slot_entry_was_cached: bool, ) { - match self.entry(*pubkey) { + let m = Measure::start("entry"); + let entry = self.map.entry(*pubkey); + let stats = &self.storage.stats; + let (count, time) = if matches!(entry, Entry::Occupied(_)) { + (&stats.entries_from_mem, &stats.entry_mem_us) + } else { + (&stats.entries_missing, &stats.entry_missing_us) + }; + Self::update_time_stat(time, m); + Self::update_stat(count, 1); + match entry { Entry::Occupied(mut occupied) => { let current = occupied.get_mut(); Self::lock_and_update_slot_list( @@ -215,7 +222,17 @@ impl InMemAccountsIndex { pubkey: Pubkey, new_entry: AccountMapEntry, ) -> Option<(WriteAccountMapEntry, T, Pubkey)> { - let result = match self.entry(pubkey) { + let m = Measure::start("entry"); + let entry = self.map.entry(pubkey); + let stats = &self.storage.stats; + let (count, time) = if matches!(entry, Entry::Occupied(_)) { + (&stats.entries_from_mem, &stats.entry_mem_us) + } else { + (&stats.entries_missing, &stats.entry_missing_us) + }; + Self::update_time_stat(time, m); + Self::update_stat(count, 1); + let result = match entry { Entry::Occupied(account_entry) => { Some(( WriteAccountMapEntry::from_account_map_entry(account_entry.get().clone()),