-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Clear way to set FPS limit #1109
Comments
I'm also interested in this, mainly because my applications don't require high frame rates and should be CPU efficient. Should it be up to the user to limit the FPS or will egui implement such a feature? |
UPD: I was able to fix vsync issue by updating macOS to 12.1 and it seems to be not related to |
I oppose the request to this feature, at least for Also it would be kind of weird if a library which is not at all time-aware starts having a blocking wait function (which is what "enforcing an fps limit" essentially boils down to). On a side note, using just const MAX_FPS: f64 = 60;
loop{
// egui code
std::thread::sleep(Duration::from_sec(1.0/MAX_FPS));
} Will result in jitter for the actual frame time. Rather it makes sense to wait only time left for the current frame, something like this (untested, just off my head) const MAX_FPS: f64 = 60;
let frame_time = Duration::from_secs(1.0/MAX_FPS);
let mut next_frame = Instant::now();
loop{
// egui code
next_frame += frame_time;
std::thread::sleep(next_frame - Instant::now());
} |
@wucke13 Beware using Instant for this, it tries to prevent subtraction from ever overflowing, and to accomplish this mutex locks in old versions. Newer code is lockless but will still create cache line contention if you have multiple threads calling |
For most people, As @wucke13 points out, you can always do this sleeping yourself in order to enforce a maximum FPS. Beware though that As for turning off vsync: why would you want to do that? I guess it can give you lower latency, but is it really noticeable? Now: if vsync is broken for more people, then perhaps it makes sense for |
Without knowing much about the technical details would the approaches of the |
The tricks |
@emilk Just for clarification: the maximum framerate is determined by the backend, i.e. 60fps when using |
BTW: is there an internal frame count that can be queried? |
Ye spinning is more CPU intensive. |
It should be determined by your display refresh rate, which often is 60Hz. If you want something lower you need to add |
I would like to revive this issue, because I'd really like to set a higher FPS limit than my monitor refresh rate. I am convinced this would improve the general perception of egui desktop apps by a lot! The lag and rubberbanding when turning on vsync on a 60Hz monitor just feels so sluggish (equally bad for glow and wgpu, slightly better in the browser). Maybe I am especially sensitive to input lag, but it can't be just me. I usually turn off vsync because of that, but that's a bad solution since it burns unnecessarily many CPU cycles and it lead to weird crashes on windows in the past (not on linux though!). Setting a limit of something like 120 or 180FPS would be a game changer! |
I am also encountering this, similarly to @vkahl, I would like to disable vsync where possible since I am using egui to render things similar to the fractal clock example, using egui primitives to render interesting graphics in the background of my UI, making them run at a high fps is paramount to making it look good when a monitor supports it. You should have the option to control the fps cap (or if there is one) as well as controlling if vsync is enabled. |
What if the Display Refresh rate is higher then 60hz? Like for example 120hz. |
I've created a simple app that renders long scrollable images grid with some animations and I'm really excited by performance of this library: on my laptop I got about 1500 FPS using glow backend. But there is one thing bothering me: CPU & GPU usage go up to 90% when I run my app, so I want to set FPS limit to save energy and get rid of cooler noise. For now I'm using
std::thread::sleep
inupdate
function, but this solution doesn't seems clear.Describe the solution you'd like
Since FPS limiting is not backend-dependent, we can add
fps_limit(&self) -> Option<u32>
function toApp
trait.Describe alternatives you've considered
Also, we can add
set_fps_limit(&self, limit: u32)
toFrame
, so it should be able to call it fromApp::setup
.The text was updated successfully, but these errors were encountered: