Since into_event_stream is just a call to AsyncFd::new, I think it might be a Tokio issue, not sure.
If tokio is working as intended, I will close this issue(which is pretty bad news, I will switch to blocking mode with a channel);if not, I will report it upstream.
This is an issue for me, I want to optimize CPU usage as much as possible, and ideally pause event fetching when it's unnecessary.
Step to reproduce
- Compile the following code and run it with
env time -v ./target/debug/examples/async-evdev
use evdev::Device;
use std::time::Duration;
use tokio::task;
use tokio::time::sleep;
#[tokio::main]
async fn main() {
let path = "/dev/input/by-id/<your-mouse>";
let device = Device::open(path).unwrap();
let event_stream = device.into_event_stream();
sleep(Duration::from_secs(1000)).await;
}
- move your mouse very fast about 3s.
- Ctrl-C terminal the program.
Expected result
CPU usage is zero.
Actual result
2% CPU usage
❯ env time -v ./target/debug/examples/async-evdev
^CCommand terminated by signal 2
Command being timed: "./target/debug/examples/async-evdev"
User time (seconds): 0.20
System time (seconds): 0.18
Percent of CPU this job got: 2%
Addition context
The CPU usage is even higher than manually fetching. The following code consumes 0~1% CPU
use evdev::Device;
fn main() {
let path = "/dev/input/by-id/<your-mouse>";
let mut device = Device::open(path).unwrap();
loop {
let result = device.fetch_events();
}
}
Profile from async code.
Tokio is polling in background.

Since
into_event_streamis just a call toAsyncFd::new, I think it might be a Tokio issue, not sure.If tokio is working as intended, I will close this issue(which is pretty bad news, I will switch to blocking mode with a channel);if not, I will report it upstream.
This is an issue for me, I want to optimize CPU usage as much as possible, and ideally pause event fetching when it's unnecessary.
Step to reproduce
env time -v ./target/debug/examples/async-evdevExpected result
CPU usage is zero.
Actual result
2% CPU usage
Addition context
The CPU usage is even higher than manually fetching. The following code consumes 0~1% CPU
Profile from async code.
Tokio is polling in background.