Skip to content

Commit 1641f06

Browse files
Use multi_get for preprocessed_blocks. (#4788)
## Motivation The function `block_hashes` has emerged as a limiting factor for the running of the system. An iteration of `get` operations is ripe for optimization. ## Proposal We use a `multi_get`. Since what is downloaded is just a hash, there is no risk of memory problems. ## Test Plan The CI. ## Release Plan This kind of acceleration can be backported to TestNet Conway easily. ## Links None.
1 parent 3f12f83 commit 1641f06

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

linera-chain/src/chain.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,10 +1116,17 @@ where
11161116
Vec::new()
11171117
};
11181118
// Everything after (including) next_height in preprocessed_blocks if we have it.
1119-
for height in start.max(next_height).0..=end.0 {
1120-
if let Some(hash) = self.preprocessed_blocks.get(&BlockHeight(height)).await? {
1121-
hashes.push(hash);
1122-
}
1119+
let block_heights = (start.max(next_height).0..=end.0)
1120+
.map(BlockHeight)
1121+
.collect::<Vec<_>>();
1122+
for hash in self
1123+
.preprocessed_blocks
1124+
.multi_get(&block_heights)
1125+
.await?
1126+
.into_iter()
1127+
.flatten()
1128+
{
1129+
hashes.push(hash);
11231130
}
11241131
Ok(hashes)
11251132
}

0 commit comments

Comments
 (0)