From ff5da1f3770872595369ff8de54d742e7a4fdad5 Mon Sep 17 00:00:00 2001 From: "Guillem L. Jara" <4lon3ly0@tutanota.com> Date: Fri, 31 Oct 2025 16:13:11 +0100 Subject: [PATCH] perf(uucore): fix bottleneck on hot loop Fixes #9099 by replacing a sleep() on a spin loop waiting on a process with a yield to the OS' scheduler. --- src/uucore/src/lib/features/process.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/uucore/src/lib/features/process.rs b/src/uucore/src/lib/features/process.rs index 55e8c36482b..a9fd0b2e780 100644 --- a/src/uucore/src/lib/features/process.rs +++ b/src/uucore/src/lib/features/process.rs @@ -141,10 +141,11 @@ impl ChildExt for Child { break; } - // XXX: this is kinda gross, but it's cleaner than starting a thread just to wait - // (which was the previous solution). We might want to use a different duration - // here as well - thread::sleep(Duration::from_millis(100)); + // Yield back to the OS' scheduler; this is better than just arbitrarily + // waiting and the usually preferred solution, spinning with + // [`std::hint::spin_loop()`], because the operations here are all + // OS-related and orders of magnitude slower than single CPU operations. + thread::yield_now(); } Ok(None)