From b4b64096c8ee3644db0248ae428aca73a7db6b0e Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 16 Jan 2026 17:08:30 +0100 Subject: [PATCH] perf(cli): use available_parallelism as default for re-execute (#21010) --- crates/cli/commands/src/re_execute.rs | 16 ++++++++++------ docs/vocs/docs/pages/cli/op-reth/re-execute.mdx | 4 +--- docs/vocs/docs/pages/cli/reth/re-execute.mdx | 4 +--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/cli/commands/src/re_execute.rs b/crates/cli/commands/src/re_execute.rs index 8223ca0120..41b6afdbc3 100644 --- a/crates/cli/commands/src/re_execute.rs +++ b/crates/cli/commands/src/re_execute.rs @@ -42,9 +42,9 @@ pub struct Command { #[arg(long)] to: Option, - /// Number of tasks to run in parallel - #[arg(long, default_value = "10")] - num_tasks: u64, + /// Number of tasks to run in parallel. Defaults to the number of available CPUs. + #[arg(long)] + num_tasks: Option, /// Continues with execution when an invalid block is encountered and collects these blocks. #[arg(long)] @@ -84,12 +84,16 @@ impl } }; + let num_tasks = self.num_tasks.unwrap_or_else(|| { + std::thread::available_parallelism().map(|n| n.get() as u64).unwrap_or(10) + }); + let total_blocks = max_block - min_block; let total_gas = calculate_gas_used_from_headers( &provider_factory.static_file_provider(), min_block..=max_block, )?; - let blocks_per_task = total_blocks / self.num_tasks; + let blocks_per_task = total_blocks / num_tasks; let db_at = { let provider_factory = provider_factory.clone(); @@ -107,10 +111,10 @@ impl let _guard = cancellation.drop_guard(); let mut tasks = JoinSet::new(); - for i in 0..self.num_tasks { + for i in 0..num_tasks { let start_block = min_block + i * blocks_per_task; let end_block = - if i == self.num_tasks - 1 { max_block } else { start_block + blocks_per_task }; + if i == num_tasks - 1 { max_block } else { start_block + blocks_per_task }; // Spawn thread executing blocks let provider_factory = provider_factory.clone(); diff --git a/docs/vocs/docs/pages/cli/op-reth/re-execute.mdx b/docs/vocs/docs/pages/cli/op-reth/re-execute.mdx index e0759212e3..247f8ead68 100644 --- a/docs/vocs/docs/pages/cli/op-reth/re-execute.mdx +++ b/docs/vocs/docs/pages/cli/op-reth/re-execute.mdx @@ -138,9 +138,7 @@ Static Files: The height to end at. Defaults to the latest block --num-tasks - Number of tasks to run in parallel - - [default: 10] + Number of tasks to run in parallel. Defaults to the number of available CPUs --skip-invalid-blocks Continues with execution when an invalid block is encountered and collects these blocks diff --git a/docs/vocs/docs/pages/cli/reth/re-execute.mdx b/docs/vocs/docs/pages/cli/reth/re-execute.mdx index 6cbacf37e4..238f07c565 100644 --- a/docs/vocs/docs/pages/cli/reth/re-execute.mdx +++ b/docs/vocs/docs/pages/cli/reth/re-execute.mdx @@ -138,9 +138,7 @@ Static Files: The height to end at. Defaults to the latest block --num-tasks - Number of tasks to run in parallel - - [default: 10] + Number of tasks to run in parallel. Defaults to the number of available CPUs --skip-invalid-blocks Continues with execution when an invalid block is encountered and collects these blocks