perf: eliminate idle CPU waste (socket events + adaptive FPS)#580
Open
lucletoffe wants to merge 2 commits intoStreamController:mainfrom
Open
perf: eliminate idle CPU waste (socket events + adaptive FPS)#580lucletoffe wants to merge 2 commits intoStreamController:mainfrom
lucletoffe wants to merge 2 commits intoStreamController:mainfrom
Conversation
…hanges Replace the 200ms polling loop that spawns 'hyprctl activewindow -j' (via flatpak-spawn + xdg-dbus-proxy when running in Flatpak) with a direct connection to Hyprland's socket2 IPC event stream. The old approach spawns ~5 processes/second even when no window changes occur, causing 10-30% CPU usage on the flatpak-session-helper and xdg-dbus-proxy (see StreamController#433 and StreamController#457). The new approach uses a blocking Unix socket read with zero CPU when idle. Changes: - Listen for 'activewindow>>' events on Hyprland's .socket2.sock - Auto-detect socket path via HYPRLAND_INSTANCE_SIGNATURE env var - Fallback to legacy polling if socket is unavailable - Add --filesystem=xdg-run/hypr:ro to Flatpak manifest for socket access - Reconnect automatically if the socket is closed (e.g. compositor restart) Fixes StreamController#433 (partially — eliminates the subprocess-spawning component) Fixes StreamController#457 (eliminates the flatpak-spawn/xdg-dbus-proxy tight loop)
The MediaPlayerThread runs at 30 FPS unconditionally, iterating over all keys/dials every ~33ms even when there is no video background, no key videos, and no scrolling labels. On a 15-key Stream Deck MK.2, this burns ~20% CPU in pure Python overhead for no visible benefit. Add dynamic FPS: detect whether any animated content (video, scroll labels) or pending image tasks exist. When idle, throttle to 2 FPS (500ms sleep). Immediately return to 30 FPS when animation starts or tasks are queued. This preserves full responsiveness for video/animation while reducing idle CPU from ~20% to ~1%.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
StreamController idles at 20-30% CPU on Hyprland systems, caused by two independent tight loops:
1. Window grabber polling (Hyprland)
The Hyprland integration polls
hyprctl activewindow -jevery 200ms. Inside Flatpak, each poll spawnsflatpak-spawn → hyprctl, causing sustained CPU onflatpak-session-helperandxdg-dbus-proxy.2. Media player thread at 30 FPS unconditionally
MediaPlayerThreadruns at 30 FPS even when there is no video background, no key videos, and no scrolling labels. On a 15-key Stream Deck, this iterates all keys 30x/sec in pure Python for zero visual benefit.Solution
Commit 1: Hyprland IPC socket events
Replace polling with a direct connection to Hyprland's
socket2IPC event stream. Listen foractivewindow>>events with a blocking socket read — zero CPU when idle.HYPRLAND_INSTANCE_SIGNATURE--filesystem=xdg-run/hypr:roto Flatpak manifestCommit 2: Adaptive media player FPS
Detect whether any animated content exists (video, scroll labels, pending image tasks). When idle, throttle from 30 FPS to 2 FPS. Return to 30 FPS instantly when animation starts.
Results (measured on Stream Deck MK.2, Hyprland, Flatpak)
flatpak-spawnprocesses/secFixes #433
Fixes #457