[GH-ISSUE #6710] [Wayland] Hidden window pins a CPU core and stops drawing #2189

Open
opened 2026-11-02 15:52:52 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @TraiNguyenVan on GitHub (Nov 2, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6710

Originally assigned to: @TraiNguyenVan on GitHub.

🤖 Filed by TraiNguyenVan's AI agent (OpenCode, high), not by TraiNguyenVan personally.

Summary

On Wayland, moving Horizon to another workspace makes horizon-client consume an entire logical CPU (about 100% of one core) while it stops drawing frames. The main menu is enough to reproduce it; no world needs to be loaded.

Returning the game to the displayed workspace makes it recover, but the CPU takes several seconds to settle back down.

Horizon title screen

Reproduction

  1. Start Horizon and leave it at the title screen.
  2. Switch to another Hyprland workspace (or move the Horizon window to one).
  3. Watch horizon-client in btop, top, or another process monitor.
  4. Switch back.

Expected: background/occluded Horizon should wait or throttle without spinning a CPU core.
Actual: the main thread uses ~100% of one logical CPU while the game produces no frames.

Evidence

Controlled shown → hidden → shown measurement

This is an isolated Horizon v0.2.97 launch. The script sampled the process CPU once per second and read Horizon's frame counter through horizon-ctl status.

  • While the window was shown: 4–5% of one core and +31 frames/s.
  • After moving it to workspace 9: 99–104% of one core; ~43–48% was kernel time; the frame counter became +0.
  • After returning it to the visible workspace: drawing resumed at ~60 fps and CPU gradually returned to 7–9%.

Controlled CPU and frame-counter timeline

btop capture during the hidden-window spin

The process list is filtered to horizon-client. btop is configured to show per-core process CPU; it records 95.4% for the one Horizon process while its window is off-screen. The same capture shows an otherwise modest system load and GPU activity.

btop: Horizon at 95.4% of one core

The game is alive but cannot render

While hidden:

  • Two horizon-ctl status calls five seconds apart both reported frames: 9556; uptime advanced from 310.2 to 315.2 seconds.
  • horizon-ctl screenshot timed out, waiting for a next frame.
  • The DRM render-time counter did not change over four seconds.
  • top -H showed the main thread at 98.9%, with the other game threads idle.

I also ran a separate isolated copy under gdb and interrupted it twice while its window was off-screen. Both backtraces stopped in the Wayland event loop:

#0 polling::Poller::wait_impl
#1 calloop::sys::Poll::poll
#2 winit::platform_impl::linux::wayland::event_loop::EventLoop::loop_dispatch
#3 winit::platform_impl::linux::wayland::event_loop::EventLoop::pump_events
#4 horizon_client::game::run_loading
#5 horizon_client::game::run

Control socket, thread, GPU, and backtrace evidence

Environment

Component Value
Horizon launcher v0.2.97 / Minecraft 26.3
Session Wayland / Hyprland 0.56.2
Display 1920×1080 @ 60 Hz; VSync enabled
CPU 11th Gen Intel Core i5-1135G7 (8 logical CPUs)
GPU Intel Iris Xe (Tiger Lake GT2)
Graphics stack Vulkan, Mesa 26.2.5 / vulkan-intel 26.2.5
OS Omarchy, kernel 7.2.8-9-omarchy

Likely code path

Game::idle requests a redraw and then selects ControlFlow::Poll in crates/horizon-client/src/game.rs (also in the loading-screen loop). On Wayland, redraw delivery is frame-callback-driven. A surface on a non-visible workspace does not receive callbacks, but ControlFlow::Poll keeps the event loop immediately polling rather than blocking.

The observed backtraces are consistent with a zero-timeout Wayland/calloop polling loop. The frame counter freezing and the screenshot timeout confirm that this is not useful game or GPU work.

A minimal mitigation may be to use Wait/WaitUntil when a redraw cannot be delivered instead of continuous Poll; a complete fix should also keep the relevant background simulation behavior correct.

Evidence files: public gist.

🤖 Generated with OpenCode

Originally created by @TraiNguyenVan on GitHub (Nov 2, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6710 Originally assigned to: @TraiNguyenVan on GitHub. > 🤖 Filed by TraiNguyenVan's AI agent (OpenCode, high), not by TraiNguyenVan personally. ## Summary On Wayland, moving Horizon to another workspace makes `horizon-client` consume an entire logical CPU (about **100% of one core**) while it stops drawing frames. The main menu is enough to reproduce it; no world needs to be loaded. Returning the game to the displayed workspace makes it recover, but the CPU takes several seconds to settle back down. ![Horizon title screen](https://gist.githubusercontent.com/TraiNguyenVan/bf9718e249bafdafa64b8c88b5af2df6/raw/04-game.svg) ## Reproduction 1. Start Horizon and leave it at the title screen. 2. Switch to another Hyprland workspace (or move the Horizon window to one). 3. Watch `horizon-client` in `btop`, `top`, or another process monitor. 4. Switch back. **Expected:** background/occluded Horizon should wait or throttle without spinning a CPU core. **Actual:** the main thread uses ~100% of one logical CPU while the game produces no frames. ## Evidence ### Controlled shown → hidden → shown measurement This is an isolated Horizon v0.2.97 launch. The script sampled the process CPU once per second and read Horizon's frame counter through `horizon-ctl status`. - While the window was shown: **4–5%** of one core and **+31 frames/s**. - After moving it to workspace 9: **99–104%** of one core; **~43–48%** was kernel time; the frame counter became **+0**. - After returning it to the visible workspace: drawing resumed at ~60 fps and CPU gradually returned to 7–9%. ![Controlled CPU and frame-counter timeline](https://gist.githubusercontent.com/TraiNguyenVan/bf9718e249bafdafa64b8c88b5af2df6/raw/01-timeline.svg) ### btop capture during the hidden-window spin The process list is filtered to `horizon-client`. `btop` is configured to show per-core process CPU; it records **95.4%** for the one Horizon process while its window is off-screen. The same capture shows an otherwise modest system load and GPU activity. ![btop: Horizon at 95.4% of one core](https://gist.githubusercontent.com/TraiNguyenVan/bf9718e249bafdafa64b8c88b5af2df6/raw/02-btop.svg) ### The game is alive but cannot render While hidden: - Two `horizon-ctl status` calls five seconds apart both reported `frames: 9556`; uptime advanced from 310.2 to 315.2 seconds. - `horizon-ctl screenshot` timed out, waiting for a next frame. - The DRM render-time counter did not change over four seconds. - `top -H` showed the main thread at **98.9%**, with the other game threads idle. I also ran a separate isolated copy under gdb and interrupted it twice while its window was off-screen. Both backtraces stopped in the Wayland event loop: ```text #0 polling::Poller::wait_impl #1 calloop::sys::Poll::poll #2 winit::platform_impl::linux::wayland::event_loop::EventLoop::loop_dispatch #3 winit::platform_impl::linux::wayland::event_loop::EventLoop::pump_events #4 horizon_client::game::run_loading #5 horizon_client::game::run ``` ![Control socket, thread, GPU, and backtrace evidence](https://gist.githubusercontent.com/TraiNguyenVan/bf9718e249bafdafa64b8c88b5af2df6/raw/03-console.svg) ## Environment | Component | Value | | --- | --- | | Horizon | launcher v0.2.97 / Minecraft 26.3 | | Session | Wayland / Hyprland 0.56.2 | | Display | 1920×1080 @ 60 Hz; VSync enabled | | CPU | 11th Gen Intel Core i5-1135G7 (8 logical CPUs) | | GPU | Intel Iris Xe (Tiger Lake GT2) | | Graphics stack | Vulkan, Mesa 26.2.5 / `vulkan-intel` 26.2.5 | | OS | Omarchy, kernel 7.2.8-9-omarchy | ## Likely code path `Game::idle` requests a redraw and then selects `ControlFlow::Poll` in `crates/horizon-client/src/game.rs` (also in the loading-screen loop). On Wayland, redraw delivery is frame-callback-driven. A surface on a non-visible workspace does not receive callbacks, but `ControlFlow::Poll` keeps the event loop immediately polling rather than blocking. The observed backtraces are consistent with a zero-timeout Wayland/calloop polling loop. The frame counter freezing and the screenshot timeout confirm that this is not useful game or GPU work. A minimal mitigation may be to use `Wait`/`WaitUntil` when a redraw cannot be delivered instead of continuous `Poll`; a complete fix should also keep the relevant background simulation behavior correct. Evidence files: [public gist](https://gist.github.com/TraiNguyenVan/bf9718e249bafdafa64b8c88b5af2df6). 🤖 Generated with [OpenCode](https://opencode.ai)
Author
Owner

@MSedgeMC commented on GitHub (Nov 2, 2026):

The spin is in the event loop's frame pacing, and it is platform-agnostic on the way in.

Game::idle (winit's about_to_wait) ends every pass with

if let Some(w) = &self.window { w.request_redraw(); }
event_loop.set_control_flow(ControlFlow::Poll);

So each pass requests a redraw and asks for another pass immediately. That is correct while the compositor keeps answering with RedrawRequested, because the renderer paces the frame. A hidden Wayland window gets no RedrawRequested at all, so the loop keeps spinning through about_to_wait with nothing to draw — one core pinned, and since no frame is ever submitted the window also stops updating, which is the pair of symptoms in the report.

The renderer already knows the difference at present time: gfx/compositor.rs::present reports whether a frame was submitted, and gfx.rs treats wgpu's CurrentSurfaceTexture::Occluded as "no frame". The event loop just never hears about it.

A fix in the shape of the existing code: remember the last present outcome on the game, and end idle with ControlFlow::WaitUntil(now + 16 ms) (or ControlFlow::Wait) when the previous frame was not submitted, instead of Poll plus an unconditional request_redraw. The window becoming visible again delivers a resize/occlusion event, which wakes the loop and restarts the frame pacing.

Verified as a reading of the code only — I have no Wayland session here to watch the core.

<!-- gh-comment-id:6567545444 --> @MSedgeMC commented on GitHub (Nov 2, 2026): The spin is in the event loop's frame pacing, and it is platform-agnostic on the way in. `Game::idle` (winit's `about_to_wait`) ends every pass with ```rust if let Some(w) = &self.window { w.request_redraw(); } event_loop.set_control_flow(ControlFlow::Poll); ``` So each pass requests a redraw and asks for another pass immediately. That is correct while the compositor keeps answering with `RedrawRequested`, because the renderer paces the frame. A hidden Wayland window gets no `RedrawRequested` at all, so the loop keeps spinning through `about_to_wait` with nothing to draw — one core pinned, and since no frame is ever submitted the window also stops updating, which is the pair of symptoms in the report. The renderer already knows the difference at present time: `gfx/compositor.rs::present` reports whether a frame was submitted, and `gfx.rs` treats wgpu's `CurrentSurfaceTexture::Occluded` as "no frame". The event loop just never hears about it. A fix in the shape of the existing code: remember the last `present` outcome on the game, and end `idle` with `ControlFlow::WaitUntil(now + 16 ms)` (or `ControlFlow::Wait`) when the previous frame was not submitted, instead of `Poll` plus an unconditional `request_redraw`. The window becoming visible again delivers a resize/occlusion event, which wakes the loop and restarts the frame pacing. Verified as a reading of the code only — I have no Wayland session here to watch the core.
Author
Owner

@TraiNguyenVan commented on GitHub (Nov 2, 2026):

/claim

<!-- gh-comment-id:6567756698 --> @TraiNguyenVan commented on GitHub (Nov 2, 2026): /claim
Author
Owner

@TraiNguyenVan commented on GitHub (Nov 2, 2026):

🤖 Agent: Implemented and locally verified the minimal event-loop mitigation on this machine. Both the gameplay and loading-screen about_to_wait paths now use ControlFlow::Wait instead of Poll after requesting a redraw.

A fast-profile build of the branch was run under the same Wayland/Hyprland setup used in the report: with the test window moved to another workspace it used 0.0% CPU over 5 seconds; after moving it back, rendering resumed and it used 12.3% CPU over 3 seconds. The focused headless-loop unit tests also pass.

<!-- gh-comment-id:6567998577 --> @TraiNguyenVan commented on GitHub (Nov 2, 2026): 🤖 Agent: Implemented and locally verified the minimal event-loop mitigation on this machine. Both the gameplay and loading-screen `about_to_wait` paths now use `ControlFlow::Wait` instead of `Poll` after requesting a redraw. A fast-profile build of the branch was run under the same Wayland/Hyprland setup used in the report: with the test window moved to another workspace it used **0.0% CPU over 5 seconds**; after moving it back, rendering resumed and it used **12.3% CPU over 3 seconds**. The focused headless-loop unit tests also pass.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#2189
No description provided.