Repository navigation
Avoid consuming CPU when waiting for input. - #651
Conversation
When reading input, start by calling `event::read`, which efficiently blocks until input arrives, rather than polling for input every 100 milliseconds. This preserves the existing `POLL_WAIT` polling behavior by moving the poll after the first `read` call returns. Fixes nushell#521.
Codecov Report
@@ Coverage Diff @@
## main #651 +/- ##
=======================================
Coverage 49.17% 49.17%
=======================================
Files 42 42
Lines 7921 7920 -1
=======================================
Hits 3895 3895
+ Misses 4026 4025 -1
|
|
I'm excited to see this. Thanks! Is there some way that once can confirm this is working? I've never see excess CPU so I'm not sure of the procedure exactly. |
|
On Linux, for example, build the basic example, install |
|
Another way to see this on Linux is the |
sholderbach
left a comment
There was a problem hiding this comment.
The changes look good to me!
Also saw the reduction in epolls via strace.
I like how the change removes one layer of the loop making things a bit more readable. And having the wait condition directly between the reading and processing of the events makes intuitive sense.


When reading input, start by calling
event::read, which efficiently blocks until input arrives, rather than polling for input every 100 milliseconds.This preserves the existing
POLL_WAITpolling behavior by moving the poll after the firstreadcall returns.Fixes #521.