Skip to content

Commit 6729cc6

Browse files
committed
refactor(engine): adjust prefetch and state update batch sizes
Increase the maximum number of targets for prefetch batching from 500 to 512 and decrease the maximum for state updates from 128 to 64. These changes aim to optimize the batching logic and improve overall performance in handling proof requests and state updates.
1 parent 8528e3a commit 6729cc6

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

crates/engine/tree/src/tree/payload_processor/multiproof.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use tracing::{debug, error, instrument, trace};
2929
/// Maximum number of targets to batch together for prefetch batching.
3030
/// Prefetches are just proof requests (no state merging), so we allow a higher cap than state
3131
/// updates
32-
const PREFETCH_MAX_BATCH_TARGETS: usize = 500;
32+
const PREFETCH_MAX_BATCH_TARGETS: usize = 512;
3333

3434
/// Maximum number of prefetch messages to batch together.
3535
/// Prevents excessive batching even with small messages.
@@ -38,7 +38,7 @@ const PREFETCH_MAX_BATCH_MESSAGES: usize = 16;
3838
/// Maximum number of targets to batch together for state updates.
3939
/// Lower than prefetch because state updates require additional processing (hashing, state
4040
/// partitioning) before dispatch.
41-
const STATE_UPDATE_MAX_BATCH_TARGETS: usize = 128;
41+
const STATE_UPDATE_MAX_BATCH_TARGETS: usize = 64;
4242

4343
/// The default max targets, for limiting the number of account and storage proof targets to be
4444
/// fetched by a single worker. If exceeded, chunking is forced regardless of worker availability.
@@ -215,8 +215,8 @@ fn can_batch_state_update(
215215
}
216216

217217
match (batch_source, next_source) {
218-
(StateChangeSource::PreBlock(_), StateChangeSource::PreBlock(_)) |
219-
(StateChangeSource::PostBlock(_), StateChangeSource::PostBlock(_)) => {
218+
(StateChangeSource::PreBlock(_), StateChangeSource::PreBlock(_))
219+
| (StateChangeSource::PostBlock(_), StateChangeSource::PostBlock(_)) => {
220220
batch_update == next_update
221221
}
222222
_ => true,
@@ -271,13 +271,13 @@ fn dispatch_with_chunking<T, I>(
271271
where
272272
I: IntoIterator<Item = T>,
273273
{
274-
let should_chunk = chunking_len > max_targets_for_chunking ||
275-
available_account_workers > 1 ||
276-
available_storage_workers > 1;
274+
let should_chunk = chunking_len > max_targets_for_chunking
275+
|| available_account_workers > 1
276+
|| available_storage_workers > 1;
277277

278-
if should_chunk &&
279-
let Some(chunk_size) = chunk_size &&
280-
chunking_len > chunk_size
278+
if should_chunk
279+
&& let Some(chunk_size) = chunk_size
280+
&& chunking_len > chunk_size
281281
{
282282
let mut dispatched = 0usize;
283283
for chunk in chunker(items, chunk_size) {
@@ -1134,12 +1134,12 @@ impl MultiProofTask {
11341134
accumulated_targets.push(targets);
11351135

11361136
// Fast-path dispatch if the first message already fills the batch.
1137-
if accumulated_count < PREFETCH_MAX_BATCH_TARGETS &&
1138-
accumulated_targets.len() < PREFETCH_MAX_BATCH_MESSAGES
1137+
if accumulated_count < PREFETCH_MAX_BATCH_TARGETS
1138+
&& accumulated_targets.len() < PREFETCH_MAX_BATCH_MESSAGES
11391139
{
11401140
loop {
1141-
if accumulated_count >= PREFETCH_MAX_BATCH_TARGETS ||
1142-
accumulated_targets.len() >= PREFETCH_MAX_BATCH_MESSAGES
1141+
if accumulated_count >= PREFETCH_MAX_BATCH_TARGETS
1142+
|| accumulated_targets.len() >= PREFETCH_MAX_BATCH_MESSAGES
11431143
{
11441144
break;
11451145
}
@@ -1205,7 +1205,7 @@ impl MultiProofTask {
12051205
// Accumulate messages including the first one
12061206
let mut accumulated_targets = estimate_evm_state_targets(&update);
12071207
// Preallocate modestly; state updates are heavier per message, but we can see small
1208-
// bursts.
1208+
// bursts.
12091209
let mut accumulated_updates: Vec<(StateChangeSource, EvmState)> =
12101210
Vec::with_capacity(16);
12111211
accumulated_updates.push((source, update));
@@ -1572,8 +1572,8 @@ fn get_proof_targets(
15721572
.storage
15731573
.keys()
15741574
.filter(|slot| {
1575-
!fetched.is_some_and(|f| f.contains(*slot)) ||
1576-
storage_added_removed_keys.is_some_and(|k| k.is_removed(slot))
1575+
!fetched.is_some_and(|f| f.contains(*slot))
1576+
|| storage_added_removed_keys.is_some_and(|k| k.is_removed(slot))
15771577
})
15781578
.peekable();
15791579

@@ -2249,8 +2249,8 @@ mod tests {
22492249
}
22502250
match task.rx.try_recv() {
22512251
Ok(MultiProofMessage::StateUpdate(next_source, next_update)) => {
2252-
if let Some((batch_source, batch_update)) = accumulated_updates.first() &&
2253-
!can_batch_state_update(
2252+
if let Some((batch_source, batch_update)) = accumulated_updates.first()
2253+
&& !can_batch_state_update(
22542254
*batch_source,
22552255
batch_update,
22562256
next_source,
@@ -2268,8 +2268,8 @@ mod tests {
22682268
Some(MultiProofMessage::StateUpdate(next_source, next_update));
22692269
break;
22702270
}
2271-
if accumulated_targets + next_estimate > STATE_UPDATE_MAX_BATCH_TARGETS &&
2272-
!accumulated_updates.is_empty()
2271+
if accumulated_targets + next_estimate > STATE_UPDATE_MAX_BATCH_TARGETS
2272+
&& !accumulated_updates.is_empty()
22732273
{
22742274
pending_msg =
22752275
Some(MultiProofMessage::StateUpdate(next_source, next_update));
@@ -2371,8 +2371,8 @@ mod tests {
23712371
}
23722372
match task.rx.try_recv() {
23732373
Ok(MultiProofMessage::StateUpdate(next_source, next_update)) => {
2374-
if let Some((batch_source, batch_update)) = accumulated_updates.first() &&
2375-
!can_batch_state_update(
2374+
if let Some((batch_source, batch_update)) = accumulated_updates.first()
2375+
&& !can_batch_state_update(
23762376
*batch_source,
23772377
batch_update,
23782378
next_source,
@@ -2390,8 +2390,8 @@ mod tests {
23902390
Some(MultiProofMessage::StateUpdate(next_source, next_update));
23912391
break;
23922392
}
2393-
if accumulated_targets + next_estimate > STATE_UPDATE_MAX_BATCH_TARGETS &&
2394-
!accumulated_updates.is_empty()
2393+
if accumulated_targets + next_estimate > STATE_UPDATE_MAX_BATCH_TARGETS
2394+
&& !accumulated_updates.is_empty()
23952395
{
23962396
pending_msg =
23972397
Some(MultiProofMessage::StateUpdate(next_source, next_update));

0 commit comments

Comments
 (0)