diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index babb55cd00..dc243594af 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -2471,7 +2471,7 @@ impl AccountsDb { unrefed_pubkeys: &mut Vec<&'a Pubkey>, ) -> usize where - I: Iterator)>, + I: Iterator)>, { let mut alive_total = 0; @@ -2544,6 +2544,10 @@ impl AccountsDb { num_stores += 1; } + // sort by pubkey to keep account index lookups close + let mut stored_accounts = stored_accounts.into_iter().collect::>(); + 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);