Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit b9b28d8

Browse files
rework to keep all slot storages together
1 parent f235f5a commit b9b28d8

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

runtime/src/accounts_db.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4103,7 +4103,7 @@ impl AccountsDb {
41034103

41044104
/// Scan through all the account storage in parallel
41054105
fn scan_account_storage_no_bank<F, B>(
4106-
snapshot_storages: &[&Arc<AccountStorageEntry>],
4106+
snapshot_storages: &[&Vec<Arc<AccountStorageEntry>>],
41074107
scan_func: F,
41084108
) -> Vec<B>
41094109
where
@@ -4115,18 +4115,20 @@ impl AccountsDb {
41154115
const MAX_ITEMS_PER_CHUNK: usize = 5_000;
41164116
snapshot_storages
41174117
.par_chunks(MAX_ITEMS_PER_CHUNK)
4118-
.map(|storages: &[&Arc<AccountStorageEntry>]| {
4118+
.map(|storages: &[&Vec<Arc<AccountStorageEntry>>]| {
41194119
let mut retval = B::default();
41204120

4121-
for storage in storages {
4122-
let accounts = storage.accounts.accounts(0);
4123-
accounts.into_iter().for_each(|stored_account| {
4124-
scan_func(
4125-
LoadedAccount::Stored(stored_account),
4126-
&mut retval,
4127-
storage.slot(),
4128-
)
4129-
});
4121+
for sub_storages in storages {
4122+
for storage in *sub_storages {
4123+
let accounts = storage.accounts.accounts(0);
4124+
accounts.into_iter().for_each(|stored_account| {
4125+
scan_func(
4126+
LoadedAccount::Stored(stored_account),
4127+
&mut retval,
4128+
storage.slot(),
4129+
)
4130+
});
4131+
}
41304132
}
41314133
retval
41324134
})
@@ -4179,7 +4181,7 @@ impl AccountsDb {
41794181
}
41804182

41814183
fn scan_snapshot_stores(
4182-
storage: &[&Arc<AccountStorageEntry>],
4184+
storage: &[&Vec<Arc<AccountStorageEntry>>],
41834185
mut stats: &mut crate::accounts_hash::HashStats,
41844186
bins: usize,
41854187
bin_range: &Range<usize>,
@@ -4228,13 +4230,17 @@ impl AccountsDb {
42284230
result
42294231
}
42304232

4231-
fn sort_storages(storages: &[SnapshotStorage]) -> Vec<&Arc<AccountStorageEntry>> {
4233+
fn sort_storages(storages: &[SnapshotStorage]) -> Vec<&Vec<Arc<AccountStorageEntry>>> {
42324234
let mut m1 = Measure::start("");
42334235
let mut result = storages
42344236
.iter()
4235-
.flatten()
4236-
.map(|item| (item.slot(), item))
4237-
.collect::<Vec<(Slot, &Arc<AccountStorageEntry>)>>();
4237+
.map(|item| {
4238+
(
4239+
item.first().map(|item| item.slot()).unwrap_or_default(),
4240+
item,
4241+
)
4242+
})
4243+
.collect::<Vec<_>>();
42384244
m1.stop();
42394245
error!("storage_sort_us: {}", m1.as_us());
42404246
result.par_sort_unstable_by(|a, b| a.0.cmp(&b.0));
@@ -5661,7 +5667,7 @@ pub mod tests {
56615667
ancestors
56625668
}
56635669

5664-
fn empty_storages<'a>() -> Vec<&'a Arc<AccountStorageEntry>> {
5670+
fn empty_storages<'a>() -> Vec<&'a Vec<Arc<AccountStorageEntry>>> {
56655671
vec![]
56665672
}
56675673

@@ -5792,8 +5798,8 @@ pub mod tests {
57925798
(storages, raw_expected)
57935799
}
57945800

5795-
fn get_storage_refs(input: &[SnapshotStorage]) -> Vec<&Arc<AccountStorageEntry>> {
5796-
input.iter().map(|inner| inner.iter()).flatten().collect()
5801+
fn get_storage_refs(input: &[SnapshotStorage]) -> Vec<&Vec<Arc<AccountStorageEntry>>> {
5802+
input.iter().collect()
57975803
}
57985804

57995805
#[test]

0 commit comments

Comments
 (0)