diff --git a/crates/engine/tree/src/tree/payload_processor/prewarm.rs b/crates/engine/tree/src/tree/payload_processor/prewarm.rs index de8a88a167b..7fad35309f5 100644 --- a/crates/engine/tree/src/tree/payload_processor/prewarm.rs +++ b/crates/engine/tree/src/tree/payload_processor/prewarm.rs @@ -147,9 +147,6 @@ where let (done_tx, done_rx) = mpsc::channel(); let mut executing = 0usize; - // Initialize worker handles container - let mut handles = Vec::with_capacity(max_concurrency); - // When transaction_count_hint is 0, it means the count is unknown. In this case, spawn // max workers to handle potentially many transactions in parallel rather // than bottlenecking on a single worker. @@ -159,6 +156,9 @@ where transaction_count_hint.min(max_concurrency) }; + // Initialize worker handles container + let mut handles = Vec::with_capacity(workers_needed); + // Only spawn initial workers as needed for i in 0..workers_needed { handles.push(ctx.spawn_worker(i, &executor, actions_tx.clone(), done_tx.clone()));