Skip to content

fix: improve unfocused window frame pacing - #3493

Open
mvanhorn wants to merge 1 commit into
hajimehoshi:mainfrom
mvanhorn:fix/3397-fps-of-unfocused-window-is-56-not-60
Open

fix: improve unfocused window frame pacing#3493
mvanhorn wants to merge 1 commit into
hajimehoshi:mainfrom
mvanhorn:fix/3397-fps-of-unfocused-window-is-56-not-60

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

What issue is this addressing?

In internal/ui/ui_glfw.go, extract the unfocused sleep-budget calculation used by glfwBackend.updateGame and reduce its target interval from 1/60 second to the maintainer-suggested 1/120 second, continuing to subtract time already spent rendering the frame. Keep the existing focus detection, buffer swap, and time.Sleep wiring intact, and skip sleeping when frame work has already consumed the shorter interval. Add a desktop-scoped unit test in internal/ui/ui_glfw_test.go for the duration calculation so boundary behavior is deterministic without relying on wall-clock timing or a live X server.

Closes #3397

What type of issue is this addressing?

What this PR does | solves

Comment thread internal/ui/ui_glfw.go
time.Sleep(d)
u.unfocusedSleepOverhead = time.Since(t) - d
if u.unfocusedSleepOverhead < 0 {
u.unfocusedSleepOverhead = 0

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use max function

Comment thread internal/ui/ui_glfw.go
if elapsed+sleepOverhead >= wait {
return 0
}
return wait - elapsed - sleepOverhead

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max(wait - elapsed - sleepOverhead, 0)

Comment thread internal/ui/ui_glfw.go
if d := unfocusedSleepDuration(t2.Sub(t1), u.unfocusedSleepOverhead); d > 0 {
t := time.Now()
time.Sleep(d)
u.unfocusedSleepOverhead = time.Since(t) - d

@hajimehoshi hajimehoshi Jul 28, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt this overhead really matters. Actually how much is unfocusedSleepOverhead on average? Does this really fix the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FPS of unfocused window is ~56 not ~60

2 participants