-
-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Description
Please describe your feature request
I use wluma with an IIO sensor on the River compositor. In this scenario, wluma will use several sleep loops:
- https://github.com/maximbaz/wluma/blob/ea4c8c6ae689655950ccbc1c2c214f5c0e4562ee/src/als/controller.rs#L35
- https://github.com/maximbaz/wluma/blob/ea4c8c6ae689655950ccbc1c2c214f5c0e4562ee/src/brightness/controller.rs#L75
I think this is a concern for battery usage. I have observed up to 10% CPU usage when moving around my system whereas it's almost 0 without wluma running. I think there is lots of room for improvement, and I think most of these will come down to avoiding sleep loops and generally avoiding computations where possible. Here are some suggestions:
- I think we should replace the current architecture of multiple worker threads with one event loop-based one. This would ease load on the OS scheduler. This could be implemented low-level with an OS API such as poll or epoll (see the respective man pages), or a Rust event loop library like tokio or smol. This would move the load to one thread, avoiding scheduling and synchronization overhead.
- Regarding the ALS controller, we should be able to convert at least the IIO backend to be evented. Instead of reading from sysfs periodically, we could instead monitor it using using inotify to get notified of brightness changes (I believe we should get events here;
iio-sensor-proxydoes it somehow, anyways). - Regarding the brightness controller, the loop only seems to do anything meaningful when we either have a new value on the
prediction_rxchannel or are in an ongoing transition. This would seem easy enough to convert to a system that blocks entirely when neither is the case. If we were to use tokio, we couldtokio::spawna worker for the transition (which isn't a real thread) and otherwise block on the channel to avoid a sleep loop. - Regarding periodic screen captures, I think it would be useful to have an opt-in "energy-saver" mode, which could work by not constantly polling the screen but instead only doing so on certain events emitted by the compositor such as:
- Workspace switches (unfortunately, every compositor has it's own protocol here)
- Various changes to the toplevel, which can be detected on wlroots with
wlr-foreign-toplevel-management-unstable-v1(see the events described there) - The process receiving a
SIGUSR1signal for scripting.
I think all of this should be doable entirely without sleep loops. Please let me know if you have any questions, I'm also open to help with implementing this. Cheers!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels