Skip to content

Commit ecd49ae

Browse files
authored
perf: only chunk if more > 1 available (#19427)
1 parent af9b04c commit ecd49ae

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -764,10 +764,11 @@ impl MultiProofTask {
764764
// Process proof targets in chunks.
765765
let mut chunks = 0;
766766

767-
// Only chunk if account or storage workers are available to take advantage of parallelism.
768-
let should_chunk =
769-
self.multiproof_manager.proof_worker_handle.has_available_account_workers() ||
770-
self.multiproof_manager.proof_worker_handle.has_available_storage_workers();
767+
// Only chunk if multiple account or storage workers are available to take advantage of
768+
// parallelism.
769+
let should_chunk = self.multiproof_manager.proof_worker_handle.available_account_workers() >
770+
1 ||
771+
self.multiproof_manager.proof_worker_handle.available_storage_workers() > 1;
771772

772773
let mut dispatch = |proof_targets| {
773774
self.multiproof_manager.dispatch(
@@ -904,10 +905,11 @@ impl MultiProofTask {
904905

905906
let mut spawned_proof_targets = MultiProofTargets::default();
906907

907-
// Only chunk if account or storage workers are available to take advantage of parallelism.
908-
let should_chunk =
909-
self.multiproof_manager.proof_worker_handle.has_available_account_workers() ||
910-
self.multiproof_manager.proof_worker_handle.has_available_storage_workers();
908+
// Only chunk if multiple account or storage workers are available to take advantage of
909+
// parallelism.
910+
let should_chunk = self.multiproof_manager.proof_worker_handle.available_account_workers() >
911+
1 ||
912+
self.multiproof_manager.proof_worker_handle.available_storage_workers() > 1;
911913

912914
let mut dispatch = |hashed_state_update| {
913915
let proof_targets = get_proof_targets(

crates/trie/parallel/src/proof_task.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ impl ProofWorkerHandle {
206206
}
207207
}
208208

209-
/// Returns true if there are available storage workers to process tasks.
210-
pub fn has_available_storage_workers(&self) -> bool {
211-
self.storage_available_workers.load(Ordering::Relaxed) > 0
209+
/// Returns how many storage workers are currently available/idle.
210+
pub fn available_storage_workers(&self) -> usize {
211+
self.storage_available_workers.load(Ordering::Relaxed)
212212
}
213213

214-
/// Returns true if there are available account workers to process tasks.
215-
pub fn has_available_account_workers(&self) -> bool {
216-
self.account_available_workers.load(Ordering::Relaxed) > 0
214+
/// Returns how many account workers are currently available/idle.
215+
pub fn available_account_workers(&self) -> usize {
216+
self.account_available_workers.load(Ordering::Relaxed)
217217
}
218218

219219
/// Returns the number of pending storage tasks in the queue.
@@ -240,16 +240,14 @@ impl ProofWorkerHandle {
240240
///
241241
/// This is calculated as total workers minus available workers.
242242
pub fn active_storage_workers(&self) -> usize {
243-
self.storage_worker_count
244-
.saturating_sub(self.storage_available_workers.load(Ordering::Relaxed))
243+
self.storage_worker_count.saturating_sub(self.available_storage_workers())
245244
}
246245

247246
/// Returns the number of account workers currently processing tasks.
248247
///
249248
/// This is calculated as total workers minus available workers.
250249
pub fn active_account_workers(&self) -> usize {
251-
self.account_worker_count
252-
.saturating_sub(self.account_available_workers.load(Ordering::Relaxed))
250+
self.account_worker_count.saturating_sub(self.available_account_workers())
253251
}
254252

255253
/// Dispatch a storage proof computation to storage worker pool

0 commit comments

Comments
 (0)