Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a bench for hash_account() #47

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions accounts-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ name = "solana_accounts_db"

[dev-dependencies]
assert_matches = { workspace = true }
criterion = { workspace = true }
jeffwashington marked this conversation as resolved.
Show resolved Hide resolved
ed25519-dalek = { workspace = true }
libsecp256k1 = { workspace = true }
memoffset = { workspace = true }
Expand All @@ -89,3 +90,7 @@ rustc_version = { workspace = true }

[features]
dev-context-only-utils = []

[[bench]]
name = "bench_hashing"
harness = false
43 changes: 43 additions & 0 deletions accounts-db/benches/bench_hashing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use {
criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput},
solana_accounts_db::accounts_db::AccountsDb,
solana_sdk::{account::AccountSharedData, pubkey::Pubkey},
};

const KB: usize = 1024;
const MB: usize = KB * KB;

const DATA_SIZES: [usize; 6] = [
0, // the smallest account
165, // the size of an spl token account
200, // the size of a stake account
Comment on lines +12 to +13
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since accounts in this size range make up ~90% of all accounts on mnb, we should optimize hashing for them. In order to quantify any improvements, we gotta benchmark it!

KB, // a medium sized account
MB, // a large sized account
10 * MB, // the largest account
];

/// The number of bytes of *non account data* that are also hashed as
/// part of computing an account's hash.
///
/// Ensure this constant stays in sync with the value of `META_SIZE` in
/// AccountsDb::hash_account_data().
const META_SIZE: usize = 81;

fn bench_hash_account(c: &mut Criterion) {
let lamports = 123_456_789;
let owner = Pubkey::default();
let address = Pubkey::default();

let mut group = c.benchmark_group("hash_account");
for data_size in DATA_SIZES {
let num_bytes = META_SIZE.checked_add(data_size).unwrap();
group.throughput(Throughput::Bytes(num_bytes as u64));
let account = AccountSharedData::new(lamports, data_size, &owner);
group.bench_function(BenchmarkId::new("data_size", data_size), |b| {
b.iter(|| AccountsDb::hash_account(&account, &address));
});
}
}

criterion_group!(benches, bench_hash_account,);
criterion_main!(benches);
Loading