Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

gpui: Throttle framerate to 30 for unfocused windows (#52970)

Lukas Wirth72eb84254059
diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs
index 5d39998700f..5778d6ac737 100644
--- a/crates/gpui/src/window.rs
+++ b/crates/gpui/src/window.rs
@@ -1211,18 +1211,31 @@ impl Window {
.update(&mut cx, |_, _, cx| cx.thermal_state())
.log_err();
- if thermal_state == Some(ThermalState::Serious)
- || thermal_state == Some(ThermalState::Critical)
+ // Throttle frame rate based on conditions:
+ // - Thermal pressure (Serious/Critical): cap to ~60fps
+ // - Inactive window (not focused): cap to ~30fps to save energy
+ let min_frame_interval = if !request_frame_options.force_render
+ && !request_frame_options.require_presentation
+ && next_frame_callbacks.borrow().is_empty()
{
- let now = Instant::now();
- let last_frame_time = last_frame_time.replace(Some(now));
+ None
+ } else if !active.get() {
+ Some(Duration::from_micros(33333))
+ } else if let Some(ThermalState::Critical | ThermalState::Serious) = thermal_state {
+ Some(Duration::from_micros(16667))
+ } else {
+ None
+ };
- if let Some(last_frame) = last_frame_time
- && now.duration_since(last_frame) < Duration::from_micros(16667)
+ let now = Instant::now();
+ if let Some(min_interval) = min_frame_interval {
+ if let Some(last_frame) = last_frame_time.get()
+ && now.duration_since(last_frame) < min_interval
{
return;
}
}
+ last_frame_time.set(Some(now));
let next_frame_callbacks = next_frame_callbacks.take();
if !next_frame_callbacks.is_empty() {