Skip to content

Commit

Permalink
Add candidates by sorted keys, decreasing number of lock acquires
Browse files Browse the repository at this point in the history
This is a minor optimization of how new cleaning candidates are
created in the candidates list.  The candidate bin lock is acquired
only once for each bin because the pubkeys are sorted by bins, and
previously unlocked bin is reused until pubkeys from a new bin start
being added to the candidates list.
  • Loading branch information
dmakarov committed Sep 24, 2024
1 parent 651530a commit d4b1fef
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3079,11 +3079,34 @@ impl AccountsDb {
) {
let uncleaned_slots = self.collect_uncleaned_slots_up_to_slot(max_slot_inclusive);
for uncleaned_slot in uncleaned_slots.into_iter() {
if let Some((_removed_slot, removed_pubkeys)) =
if let Some((_removed_slot, mut removed_pubkeys)) =
self.uncleaned_pubkeys.remove(&uncleaned_slot)
{
for removed_pubkey in removed_pubkeys {
self.insert_pubkey(candidates, removed_pubkey);
// Sort all keys by bin index so that we can insert
// them in `candidates` more efficiently.
removed_pubkeys.sort_by(|a, b| {
self.accounts_index
.bin_calculator
.bin_from_pubkey(a)
.cmp(&self.accounts_index.bin_calculator.bin_from_pubkey(b))
});
if let Some(first_removed_pubkey) = removed_pubkeys.first() {
let mut prev_bin = self
.accounts_index
.bin_calculator
.bin_from_pubkey(first_removed_pubkey);
let mut candidates_bin = candidates[prev_bin].write().unwrap();
for removed_pubkey in removed_pubkeys {
let curr_bin = self
.accounts_index
.bin_calculator
.bin_from_pubkey(&removed_pubkey);
if curr_bin != prev_bin {
candidates_bin = candidates[curr_bin].write().unwrap();
prev_bin = curr_bin;
}
candidates_bin.insert(removed_pubkey, CleaningInfo::default());
}
}
}
}
Expand Down

0 comments on commit d4b1fef

Please sign in to comment.