accounts-db: Use PubkeyHasher in SlotCache#7307
Conversation
6f95cc9 to
153050d
Compare
`SlotCache` used pubkeys as keys, yet it used the AHash hasher. To imporove performance of lookups, use `PubkeyHasher`.
153050d to
91a1a47
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7307 +/- ##
=======================================
Coverage 83.2% 83.2%
=======================================
Files 797 797
Lines 361114 361114
=======================================
+ Hits 300736 300761 +25
+ Misses 60378 60353 -25 🚀 New features to boost your workflow:
|
Ooh, can you share perf results from this change? |
Well, I can definitely say that pubkey hasher is in general faster: #[test]
fn test_hashmapz() {
let pubkeys1: Vec<_> = (0..1_000_000).map(|_| Pubkey::new_unique()).collect();
let pubkeys2 = pubkeys1.clone();
let mut ahash_map: HashMap<Pubkey, (), ahash::RandomState> =
HashMap::with_capacity_and_hasher(1_000_000, ahash::RandomState::new());
let mut pubkeyh_map: HashMap<Pubkey, (), PubkeyHasherBuilder> =
HashMap::with_capacity_and_hasher(1_000_000, PubkeyHasherBuilder::default());
let (_, ahash_measure) = measure_us!(for pubkey in pubkeys1 {
ahash_map.insert(pubkey, ());
});
let (_, pubkeyh_measure) = measure_us!(for pubkey in pubkeys2 {
pubkeyh_map.insert(pubkey, ());
});
println!("ahash: {ahash_measure}");
println!("pubkey hasher: {pubkeyh_measure}");
}I ran it dozens of times and the results are similar and pubkey hasher always outperforms ahash about ~15%. Honestly I didn't catch it with profiler. I rather just thought of it when working on #6900 (where I do profiles, but the hashing itself is not the biggest bottleneck) and I started questioning the necessity of AHash in maps with pubkeys that are not really DDOS-able. The change of hasher probably contributes a tiny bit to the overall improvement. |
Problem
SlotCacheused pubkeys as keys, yet it used the AHash hasher.Summary of Changes
To imporove performance of lookups, use
PubkeyHasher.Fixes #