[PR #6730] [CLOSED] Fix Wayland hidden-window event loop spin #7060

Closed
opened 2026-11-03 06:33:01 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6730
Author: @TraiNguyenVan
Created: 11/2/2026
Status: ❌ Closed

Base: main ← Head: fix/wayland-hidden-window-spin


📝 Commits (1)

  • 3340c44 Fix Wayland hidden-window event loop spin

📊 Changes

1 file changed (+41 additions, -2 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+41 -2)

📄 Description

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

Fixes #6710.

What changed

After requesting a redraw, both the gameplay and loading-screen event loops now select their flow with a shared idle_flow helper:

  • offscreen mode retains ControlFlow::Poll, because it renders through synthetic redraw events and has no winit redraw callback;
  • windowed mode uses ControlFlow::WaitUntil(Instant::now() + 50 ms), so a hidden surface cannot busy-poll while control and shutdown work remains serviced at a bounded cadence.

A hidden surface may receive no compositor callbacks, so an unbounded poll loop can repeatedly enter about_to_wait without drawing.

Verification

  • cargo fmt --check
  • cargo check -p horizon-client --no-default-features
  • cargo test -p horizon-client --lib --no-default-features 'game::idle_flow_tests::' -- --nocapture
    • 2 passed: offscreen selects Poll; windowed mode selects a bounded WaitUntil.
  • Offscreen control smoke test with target/fast/horizon-ctl launch --world OffscreenSmoke --creative --offscreen --wait --resources <prepared resources>:
    • opened the world, returned a playable state, and accepted horizon-ctl quit.
  • Manual Wayland/Hyprland test with the fast build:
    • hidden on another workspace with WaitUntil(50 ms): 0.20% CPU over 10 seconds (2 CPU ticks)
    • a visible-window smoke test was performed on the same Wayland session.
  • python3 tools/pr_ready.py --quick — passed: 598 Python tests, 595 horizon-client tests, clippy, rustfmt, public-tree, and doc-test checks passed. Local Rust 1.98.0 is one minor version behind CI stable 1.99.

X11, macOS, and Windows were not tested. On Wayland/Hyprland, a hidden game exited cleanly with status 0 after SIGTERM; the bounded 50 ms wake-up retains the existing idle() shutdown polling path.

The issue contains the original repro, btop capture, frame-counter timeline, and event-loop backtraces. The before/after btop evidence in the PR predates the revised bounded-wait policy and is superseded by the 0.20% timed measurement above.

🤖 Generated with OpenCode


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/6730 **Author:** [@TraiNguyenVan](https://github.com/TraiNguyenVan) **Created:** 11/2/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/wayland-hidden-window-spin` --- ### 📝 Commits (1) - [`3340c44`](https://github.com/horizon-rust/horizon/commit/3340c44f2a181367b8130eae70e7aea0b2008e59) Fix Wayland hidden-window event loop spin ### 📊 Changes **1 file changed** (+41 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+41 -2) </details> ### 📄 Description > 🤖 Opened by TraiNguyenVan's AI agent (OpenCode, high), not by TraiNguyenVan personally. Fixes #6710. ## What changed After requesting a redraw, both the gameplay and loading-screen event loops now select their flow with a shared `idle_flow` helper: - offscreen mode retains `ControlFlow::Poll`, because it renders through synthetic redraw events and has no winit redraw callback; - windowed mode uses `ControlFlow::WaitUntil(Instant::now() + 50 ms)`, so a hidden surface cannot busy-poll while control and shutdown work remains serviced at a bounded cadence. A hidden surface may receive no compositor callbacks, so an unbounded poll loop can repeatedly enter `about_to_wait` without drawing. ## Verification - `cargo fmt --check` - `cargo check -p horizon-client --no-default-features` - `cargo test -p horizon-client --lib --no-default-features 'game::idle_flow_tests::' -- --nocapture` - 2 passed: offscreen selects `Poll`; windowed mode selects a bounded `WaitUntil`. - Offscreen control smoke test with `target/fast/horizon-ctl launch --world OffscreenSmoke --creative --offscreen --wait --resources <prepared resources>`: - opened the world, returned a playable state, and accepted `horizon-ctl quit`. - Manual Wayland/Hyprland test with the fast build: - hidden on another workspace with `WaitUntil(50 ms)`: **0.20% CPU over 10 seconds** (2 CPU ticks) - a visible-window smoke test was performed on the same Wayland session. - `python3 tools/pr_ready.py --quick` — passed: 598 Python tests, 595 `horizon-client` tests, clippy, rustfmt, public-tree, and doc-test checks passed. Local Rust 1.98.0 is one minor version behind CI stable 1.99. X11, macOS, and Windows were not tested. On Wayland/Hyprland, a hidden game exited cleanly with status 0 after `SIGTERM`; the bounded 50 ms wake-up retains the existing `idle()` shutdown polling path. The issue contains the original repro, btop capture, frame-counter timeline, and event-loop backtraces. The before/after btop evidence in the PR predates the revised bounded-wait policy and is superseded by the 0.20% timed measurement above. 🤖 Generated with [OpenCode](https://opencode.ai) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:33:01 +07:00
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#7060
No description provided.