Reducing CPU usage for mostly idle non-game applications by parking the main thread #18965
evanrelf
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
This is something that Bevy supports if you're using winit by setting the |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm toying with the idea of using Bevy for my terminal-based text editor. I noticed in my experiments that Bevy pegs at least one of my CPU cores (i.e. >100% utilization) even if there's no work to do. This happens even with
App::new().add_plugins(MinimalPlugins).run()
.Based on previous work on this text editor project, I know that the program is idle most of the time, and only does work in response to a limited number of external inputs that I know and control. So I thought... maybe this is crazy, but... what if I just park the main thread, stopping Bevy from spinning pointlessly, until I know I have work to do? If I receive inputs from the outside world on a separate thread, I can have it wait for stimulus, and then feed Bevy that input + unpark the main thread.
This is working really well for my extremely early experiments! Thought I would share in case someone else would benefit, or someone has feedback on how I could improve this / achieve this differently / think better of this 🙂
https://github.com/evanrelf/indigo/blob/d01c3cc12e099c942070eefac68dd6a032e8d4a2/crates/indigo-bevy/src/park.rs
Some other info:
ratatui
crate.Beta Was this translation helpful? Give feedback.
All reactions