From eca0ceb04cc43e9defcbdb75065614440f10b079 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Wed, 7 Jul 2021 15:36:05 -0500 Subject: [PATCH] eliminate unnecessary copies in accounts index generation (#18466) --- runtime/src/accounts_db.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 57b84daa75..841bf0a612 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -5982,21 +5982,22 @@ impl AccountsDb { } let mut stored_sizes_and_counts = HashMap::new(); - for account_entry in self - .accounts_index - .account_maps - .iter() - .map(|i| i.read().unwrap().values().cloned().collect::>()) - .flatten() - { - for (_slot, account_entry) in account_entry.slot_list.read().unwrap().iter() { - let storage_entry_meta = stored_sizes_and_counts - .entry(account_entry.store_id) - .or_insert((0, 0)); - storage_entry_meta.0 += account_entry.stored_size; - storage_entry_meta.1 += 1; - } - } + self.accounts_index.account_maps.iter().for_each(|i| { + i.read().unwrap().values().for_each(|entry| { + entry + .slot_list + .read() + .unwrap() + .iter() + .for_each(|(_slot, account_entry)| { + let storage_entry_meta = stored_sizes_and_counts + .entry(account_entry.store_id) + .or_insert((0, 0)); + storage_entry_meta.0 += account_entry.stored_size; + storage_entry_meta.1 += 1; + }) + }) + }); for slot_stores in self.storage.0.iter() { for (id, store) in slot_stores.value().read().unwrap().iter() { // Should be default at this point