Improve load_largest_accounts more (#15785)

* Add load_largest_accounts bench

* Check lamports before address filter

* Use BinaryHeap, add Accounts test

* Use pubkey reference in the min-heap

Also, flatten code with early returns

Co-authored-by: Greg Fitzgerald <greg@solana.com>
This commit is contained in:
Tyera Eulberg
2021-03-10 11:22:02 -07:00
committed by GitHub
parent 369e13b111
commit 9c1198c0c7
2 changed files with 184 additions and 30 deletions

View File

@ -7,7 +7,7 @@ use dashmap::DashMap;
use rand::Rng;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use solana_runtime::{
accounts::{create_test_accounts, Accounts},
accounts::{create_test_accounts, AccountAddressFilter, Accounts},
bank::*,
};
use solana_sdk::{
@ -360,3 +360,25 @@ fn bench_dashmap_iter(bencher: &mut Bencher) {
);
});
}
#[bench]
fn bench_load_largest_accounts(b: &mut Bencher) {
let accounts =
Accounts::new_with_config(Vec::new(), &ClusterType::Development, HashSet::new(), false);
let mut rng = rand::thread_rng();
for _ in 0..10_000 {
let lamports = rng.gen();
let pubkey = Pubkey::new_unique();
let account = AccountSharedData::new(lamports, 0, &Pubkey::default());
accounts.store_slow_uncached(0, &pubkey, &account);
}
let ancestors = vec![(0, 0)].into_iter().collect();
b.iter(|| {
accounts.load_largest_accounts(
&ancestors,
20,
&HashSet::new(),
AccountAddressFilter::Exclude,
)
});
}