From 576a7277cbea967c5784750f2851099b3c7a9732 Mon Sep 17 00:00:00 2001 From: Daria Sukhonina Date: Thu, 12 Mar 2026 13:25:40 +0300 Subject: [PATCH] Take first task group for further execution --- compiler/rustc_data_structures/src/sync/parallel.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_data_structures/src/sync/parallel.rs b/compiler/rustc_data_structures/src/sync/parallel.rs index b112ecc2fbad1..966c34f7e1525 100644 --- a/compiler/rustc_data_structures/src/sync/parallel.rs +++ b/compiler/rustc_data_structures/src/sync/parallel.rs @@ -145,7 +145,9 @@ fn par_slice( const MAX_GROUP_COUNT: usize = 128; let group_size = items.len().div_ceil(MAX_GROUP_COUNT); - let groups = items.chunks_mut(group_size); + let mut groups = items.chunks_mut(group_size); + + let Some(first_group) = groups.next() else { return }; // Reverse the order of the later functions since Rayon executes them in reverse // order when using a single thread. This ensures the execution order matches @@ -159,6 +161,11 @@ fn par_slice( } }); } + + // Run the first function without spawning to avoid overwhelming stealing. + for i in first_group.iter_mut() { + guard.run(|| for_each(i)); + } }); }