eliminate flatten and sort in hash calculation (#17802)

* eliminate flatten and sort in hash calculation

* reduce critical section time

* remove now no-longer necessary test code

* conflict with reset bins to 0 pr
This commit is contained in:
Jeff Washington (jwash) 2021-06-21 15:32:03 -05:00 committed by GitHub
parent 58e115275a
commit bf97627021
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 295 additions and 485 deletions

View File

@ -4613,7 +4613,7 @@ impl AccountsDb {
}
/// Scan through all the account storage in parallel
fn scan_account_storage_no_bank<F, B>(
fn scan_account_storage_no_bank<F, F2, B, C>(
accounts_cache_and_ancestors: Option<(
&AccountsCache,
&Ancestors,
@ -4621,10 +4621,13 @@ impl AccountsDb {
)>,
snapshot_storages: &SortedStorages,
scan_func: F,
) -> Vec<B>
after_func: F2,
) -> Vec<C>
where
F: Fn(LoadedAccount, &mut B, Slot) + Send + Sync,
F2: Fn(B) -> C + Send + Sync,
B: Send + Default,
C: Send + Default,
{
// Without chunks, we end up with 1 output vec for each outer snapshot storage.
// This results in too many vectors to be efficient.
@ -4669,7 +4672,7 @@ impl AccountsDb {
}
}
}
retval
after_func(retval)
})
.collect()
}
@ -4847,6 +4850,7 @@ impl AccountsDb {
}
accum[pubkey_to_bin_index].push(source_item);
},
Self::sort_slot_storage_scan,
);
if check_hash && mismatch_found.load(Ordering::Relaxed) > 0 {
@ -4863,6 +4867,19 @@ impl AccountsDb {
Ok(result)
}
fn sort_slot_storage_scan(
accum: Vec<Vec<CalculateHashIntermediate>>,
) -> Vec<Vec<CalculateHashIntermediate>> {
accum
.into_par_iter()
.map(|mut items| {
// sort_by vs unstable because slot and write_version are already in order
items.sort_by(AccountsHash::compare_two_hash_entries);
items
})
.collect()
}
// modeled after get_accounts_delta_hash
// intended to be faster than calculate_accounts_hash
pub fn calculate_accounts_hash_without_index(
@ -4915,6 +4932,7 @@ impl AccountsDb {
&mut stats,
pass == num_scan_passes - 1,
previous_pass,
bins_per_pass,
);
previous_pass = for_next_pass;
final_result = (hash, lamports);
@ -6643,6 +6661,7 @@ pub mod tests {
assert_eq!(slot_expected, slot);
accum.push(expected);
},
|a| a,
);
assert_eq!(calls.load(Ordering::Relaxed), 1);
assert_eq!(result, vec![vec![expected]]);

File diff suppressed because it is too large Load Diff