-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look good to me!
Also saw the reduction in epoll
s 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_WAIT
polling behavior by moving the poll after the firstread
call returns.Fixes #521.