Skip to content

Commit ff5da1f

Browse files
committed
perf(uucore): fix bottleneck on hot loop
Fixes uutils#9099 by replacing a sleep() on a spin loop waiting on a process with a yield to the OS' scheduler.
1 parent 8f7afa7 commit ff5da1f

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/uucore/src/lib/features/process.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,11 @@ impl ChildExt for Child {
141141
break;
142142
}
143143

144-
// XXX: this is kinda gross, but it's cleaner than starting a thread just to wait
145-
// (which was the previous solution). We might want to use a different duration
146-
// here as well
147-
thread::sleep(Duration::from_millis(100));
144+
// Yield back to the OS' scheduler; this is better than just arbitrarily
145+
// waiting and the usually preferred solution, spinning with
146+
// [`std::hint::spin_loop()`], because the operations here are all
147+
// OS-related and orders of magnitude slower than single CPU operations.
148+
thread::yield_now();
148149
}
149150

150151
Ok(None)

0 commit comments

Comments
 (0)