Skip to content

Commit

Permalink
combine sort into get_unique_accounts_from_storages (#28450)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington authored Oct 18, 2022
1 parent b583ec7 commit d52e28a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
18 changes: 6 additions & 12 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pub const ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS: AccountsDbConfig = AccountsDbConfig
pub type BinnedHashData = Vec<Vec<CalculateHashIntermediate>>;

pub struct GetUniqueAccountsResult<'a> {
pub stored_accounts: HashMap<Pubkey, FoundStoredAccount<'a>>,
pub stored_accounts: Vec<(Pubkey, FoundStoredAccount<'a>)>,
pub original_bytes: u64,
store_ids: Vec<AppendVecId>,
}
Expand Down Expand Up @@ -3608,6 +3608,11 @@ impl AccountsDb {
store.append_vec_id()
})
.collect();

// sort by pubkey to keep account index lookups close
let mut stored_accounts = stored_accounts.into_iter().collect::<Vec<_>>();
stored_accounts.sort_unstable_by(|a, b| a.0.cmp(&b.0));

GetUniqueAccountsResult {
stored_accounts,
original_bytes,
Expand All @@ -3626,10 +3631,6 @@ impl AccountsDb {
store_ids,
} = self.get_unique_accounts_from_storages(stores);

// sort by pubkey to keep account index lookups close
let mut stored_accounts = stored_accounts.into_iter().collect::<Vec<_>>();
stored_accounts.sort_unstable_by(|a, b| a.0.cmp(&b.0));

let mut index_read_elapsed = Measure::start("index_read_elapsed");
let alive_total_collect = AtomicUsize::new(0);

Expand Down Expand Up @@ -4280,13 +4281,6 @@ impl AccountsDb {
store_ids: _,
} = self.get_unique_accounts_from_storages(old_storages.iter());

// sort by pubkey to keep account index lookups close
let stored_accounts = {
let mut stored_accounts = stored_accounts.into_iter().collect::<Vec<_>>();
stored_accounts.sort_unstable_by(|a, b| a.0.cmp(&b.0));
stored_accounts
};

let mut index_read_elapsed = Measure::start("index_read_elapsed");
let alive_total_collect = AtomicUsize::new(0);

Expand Down
2 changes: 0 additions & 2 deletions runtime/src/snapshot_minimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,6 @@ impl<'a> SnapshotMinimizer<'a> {
} = self
.accounts_db()
.get_unique_accounts_from_storages(storages.iter());
let mut stored_accounts = stored_accounts.into_iter().collect::<Vec<_>>();
stored_accounts.sort_unstable_by(|a, b| a.0.cmp(&b.0));

let keep_accounts_collect = Mutex::new(Vec::with_capacity(stored_accounts.len()));
let purge_pubkeys_collect = Mutex::new(Vec::with_capacity(stored_accounts.len()));
Expand Down

0 comments on commit d52e28a

Please sign in to comment.