refactor generate_index zero lamports (#19769)
This commit is contained in:
committed by
GitHub
parent
595bba95b4
commit
cba834808a
@ -1587,48 +1587,47 @@ impl<T: IsCached> AccountsIndex<T> {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|pubkey_bin| (pubkey_bin, Vec::with_capacity(expected_items_per_bin)))
|
.map(|pubkey_bin| (pubkey_bin, Vec::with_capacity(expected_items_per_bin)))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
items.for_each(|(pubkey, account_info)| {
|
let mut dirty_pubkeys = items
|
||||||
|
.filter_map(|(pubkey, account_info)| {
|
||||||
let bin = self.bin_calculator.bin_from_pubkey(&pubkey);
|
let bin = self.bin_calculator.bin_from_pubkey(&pubkey);
|
||||||
// this value is equivalent to what update() below would have created if we inserted a new item
|
// this value is equivalent to what update() below would have created if we inserted a new item
|
||||||
let is_zero_lamport = account_info.is_zero_lamport();
|
let is_zero_lamport = account_info.is_zero_lamport();
|
||||||
|
let result = if is_zero_lamport { Some(pubkey) } else { None };
|
||||||
|
|
||||||
let info = WriteAccountMapEntry::new_entry_after_update(slot, account_info);
|
let info = WriteAccountMapEntry::new_entry_after_update(slot, account_info);
|
||||||
binned[bin].1.push((pubkey, info, is_zero_lamport));
|
binned[bin].1.push((pubkey, info));
|
||||||
});
|
result
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
binned.retain(|x| !x.1.is_empty());
|
binned.retain(|x| !x.1.is_empty());
|
||||||
|
|
||||||
let insertion_time = AtomicU64::new(0);
|
let insertion_time = AtomicU64::new(0);
|
||||||
|
|
||||||
let dirty_pubkeys = binned
|
binned.into_iter().for_each(|(pubkey_bin, items)| {
|
||||||
.into_iter()
|
|
||||||
.map(|(pubkey_bin, items)| {
|
|
||||||
let mut _reclaims = SlotList::new();
|
let mut _reclaims = SlotList::new();
|
||||||
|
|
||||||
// big enough so not likely to re-allocate, small enough to not over-allocate by too much
|
// big enough so not likely to re-allocate, small enough to not over-allocate by too much
|
||||||
// this assumes 10% of keys are duplicates. This vector will be flattened below.
|
// this assumes 10% of keys are duplicates. This vector will be flattened below.
|
||||||
let mut dirty_pubkeys = Vec::with_capacity(items.len() / 10);
|
|
||||||
let mut w_account_maps = self.account_maps[pubkey_bin].write().unwrap();
|
let mut w_account_maps = self.account_maps[pubkey_bin].write().unwrap();
|
||||||
let mut insert_time = Measure::start("insert_into_primary_index");
|
let mut insert_time = Measure::start("insert_into_primary_index");
|
||||||
items
|
items.into_iter().for_each(|(pubkey, new_item)| {
|
||||||
.into_iter()
|
|
||||||
.for_each(|(pubkey, new_item, is_zero_lamport)| {
|
|
||||||
let already_exists = self.insert_new_entry_if_missing_with_lock(
|
let already_exists = self.insert_new_entry_if_missing_with_lock(
|
||||||
pubkey,
|
pubkey,
|
||||||
&mut w_account_maps,
|
&mut w_account_maps,
|
||||||
new_item,
|
new_item,
|
||||||
);
|
);
|
||||||
if let Some((mut w_account_entry, account_info, pubkey)) = already_exists {
|
if let Some((mut w_account_entry, account_info, pubkey)) = already_exists {
|
||||||
|
let is_zero_lamport = account_info.is_zero_lamport();
|
||||||
w_account_entry.update(slot, account_info, &mut _reclaims);
|
w_account_entry.update(slot, account_info, &mut _reclaims);
|
||||||
|
if !is_zero_lamport {
|
||||||
|
// zero lamports were already added to dirty_pubkeys above
|
||||||
dirty_pubkeys.push(pubkey);
|
dirty_pubkeys.push(pubkey);
|
||||||
} else if is_zero_lamport {
|
}
|
||||||
dirty_pubkeys.push(pubkey);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
insert_time.stop();
|
insert_time.stop();
|
||||||
insertion_time.fetch_add(insert_time.as_us(), Ordering::Relaxed);
|
insertion_time.fetch_add(insert_time.as_us(), Ordering::Relaxed);
|
||||||
dirty_pubkeys
|
});
|
||||||
})
|
|
||||||
.flatten()
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
(dirty_pubkeys, insertion_time.load(Ordering::Relaxed))
|
(dirty_pubkeys, insertion_time.load(Ordering::Relaxed))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user