From 1938a8db4efca2a2d45f3f5658a23b0033d631af Mon Sep 17 00:00:00 2001 From: edwloef Date: Sun, 9 Aug 2026 08:58:31 +0200 Subject: [PATCH] don't allocate empty streams in `Task::batch` --- runtime/src/task.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/runtime/src/task.rs b/runtime/src/task.rs index 5575bcf26b..bb7008556b 100644 --- a/runtime/src/task.rs +++ b/runtime/src/task.rs @@ -96,11 +96,14 @@ impl Task { where T: 'static, { + let mut last_stream = None; let mut select_all = stream::SelectAll::new(); let mut units = 0; for task in tasks.into_iter() { - if let Some(stream) = task.stream { + if let Some(stream) = task.stream + && let Some(stream) = last_stream.replace(stream) + { select_all.push(stream); } @@ -108,7 +111,12 @@ impl Task { } Self { - stream: Some(boxed_stream(select_all)), + stream: if select_all.is_empty() { + last_stream + } else { + select_all.extend(last_stream); + Some(boxed_stream(select_all)) + }, units, } }