perf(uucore): fix bottleneck on hot loop#9101
Conversation
Fixes uutils#9099 by replacing a sleep() on a spin loop waiting on a process with a yield to the OS' scheduler.
|
Ty @depesz for the bug report and the pointer on the culprit! |
|
GNU testsuite comparison: |
|
I don't think those CI fails are because of the changes on this PR :) |
|
This fix will cause to 100% CPU Thread usage during wait which is definately not good. |
|
In my opinion Sleep(1) //1ms would be great option, because you reduce waiting time to around 1ms and do not create unnecessary 100%CPU load. If you want even greater response then there is usleep() function (in unix) |
Can't say I can reproduce this. Ideally Screen.Recording.2025-10-31.172505.mp4 |
|
Just remembered that OS timers exist. On POSIX there's setitimer(2), we could just set that up with a signal handler, which if executes, handles the code path for failure; if it does not, it's because the process finished first and therefore also timeout (even so, we should probably disarm the timer just in case). I think this is quite preferable to the However, this is more work than I can handle at the moment; I can take it up from here on Wednesday after my exams are over, though. The |
|
Superseded by #9123. |
Fixes #9099 by replacing a sleep() on a spin loop waiting on a process with a yield to the OS' scheduler.