Skip to content

Commit

Permalink
improve insert into map initially
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed May 18, 2021
1 parent 2175fc0 commit d548e22
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions runtime/src/accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,13 +1172,23 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
reclaims: &mut SlotList<T>,
w_account_maps: &mut ReadWriteLockMapType<T>,
) {
let new_entry = Self::new_entry();
let (mut w_account_entry, _is_new) =
self.insert_new_entry_if_missing_with_lock(pubkey, w_account_maps, new_entry);
let mut is_newly_inserted = false;
let account_entry = w_account_maps.entry(*pubkey).or_insert_with(|| {
is_newly_inserted = true;
// this value is equivalent to what update() below would have created
Arc::new(AccountMapEntryInner {
ref_count: AtomicU64::new(if account_info.is_cached() { 0 } else { 1 }),
slot_list: RwLock::new(vec![(slot, account_info.clone())]),
})
});
if account_info.is_zero_lamport() {
self.zero_lamport_pubkeys.insert(*pubkey);
}
w_account_entry.update(slot, account_info, reclaims);
if !is_newly_inserted {
let mut w_account_entry =
WriteAccountMapEntry::from_account_map_entry(account_entry.clone());
w_account_entry.update(slot, account_info, reclaims);
}
}

// Updates the given pubkey at the given slot with the new account information.
Expand Down

0 comments on commit d548e22

Please sign in to comment.