Skip to content

Commit

Permalink
wip: lattic hash
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoranYi committed Mar 26, 2024
1 parent 7c8a287 commit b4f698a
Show file tree
Hide file tree
Showing 15 changed files with 1,263 additions and 67 deletions.
32 changes: 31 additions & 1 deletion accounts-db/benches/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use {
solana_accounts_db::{
accounts::{AccountAddressFilter, Accounts},
accounts_db::{
test_utils::create_test_accounts, AccountShrinkThreshold, AccountsDb,
test_utils::create_test_accounts, AccountShrinkThreshold, AccountsDb, LTHashCacheMap,
VerifyAccountsHashAndLamportsConfig, ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS,
},
accounts_index::{AccountSecondaryIndexes, ScanConfig},
Expand All @@ -26,6 +26,7 @@ use {
},
std::{
collections::{HashMap, HashSet},
hint::black_box,
path::PathBuf,
sync::{Arc, RwLock},
thread::Builder,
Expand Down Expand Up @@ -341,3 +342,32 @@ fn bench_load_largest_accounts(b: &mut Bencher) {
)
});
}

/// Bench for computing lattice hash
/// test test_accounts_lt_hash ... bench: 5,420,262 ns/iter (+/- 60,676) -- seq
/// test test_accounts_lt_hash ... bench: 2,857,909 ns/iter (+/- 30,022) -- par_chunks (500)
/// test test_accounts_lt_hash ... bench: 2,476,487 ns/iter (+/- 55,287) -- par_chunks (250)
/// test test_accounts_lt_hash ... bench: 2,415,198 ns/iter (+/- 64,917) -- enum cache value
/// test test_accounts_lt_hash ... bench: 1,783,466 ns/iter (+/- 210,289) -- boxing AccountLTHash
/// test test_accounts_lt_hash ... bench: 1,631,536 ns/iter (+/- 310,180) -- boxing AccountSharedData
#[bench]
fn test_accounts_lt_hash(bencher: &mut Bencher) {
solana_logger::setup();
let accounts_db = new_accounts_db(vec![PathBuf::from("accounts_lt_hash")]);
let accounts = Accounts::new(Arc::new(accounts_db));
let mut pubkeys: Vec<Pubkey> = vec![];
create_test_accounts(&accounts, &mut pubkeys, 1_000, 0);

let mut ancestor = Ancestors::default();
ancestor.insert(0, 1);

bencher.iter(|| {
black_box(accounts.accounts_db.accumulate_accounts_lt_hash(
0,
&ancestor,
&RwLock::new(Some(AccountLTHash::default())),
&LTHashCacheMap::default(),
&LTHashCacheMap::default(),
))
});
}
1 change: 1 addition & 0 deletions accounts-db/src/accounts_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ pub type CachedAccount = Arc<CachedAccountInner>;
pub struct CachedAccountInner {
pub account: AccountSharedData,
hash: SeqLock<Option<AccountHash>>,
// TODO: add lt_hash
pubkey: Pubkey,
}

Expand Down
Loading

0 comments on commit b4f698a

Please sign in to comment.