Repository navigation
Back off idle background work in the GPUI app - #17
Merged
Merged
Conversation
The native app polled at a fixed rate whether or not anyone was looking at it. Three changes cut that without delaying anything a user can see: - HID readers (openmouse-hid): an opt-in idle backoff. After two quiet seconds a reader adds a 100 ms wait, outside the device lock, so five open interfaces drop from about 650 wakeups a second to about 130. Every request marks activity and unparks the readers first, so replies are still read at the normal cadence. Off unless a host calls set_idle_backoff; only the GPUI app does, so the Tauri app behaves exactly as before. - Wallpaper watcher: only runs its checks while the Dynamic theme is selected (each check spawns osascript on macOS). Switching to Dynamic already resamples on its own. - Window activity: a shared flag set from the main window's activation events. While the window is not active the game process scan goes from 2 s to 10 s, the install scan from 10 s to 60 s and the wallpaper check from 2 s to 30 s. They slow rather than stop, so a game launching behind the window still applies its profile, and regaining focus wakes them immediately.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Autofix is active · Waiting for CI/review
Comment |
|
Autofix was enabled. Check current status in the Coding task. |
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.
What
The native app polled at a fixed rate whether or not anyone was looking at it. This cuts that without delaying anything a user can see.
1. HID reader idle backoff (
crates/openmouse-hid)Held-open interfaces keep a reader thread each, looping on a 10 ms read plus a 5 ms gap (about 66 wakeups/s per interface) for the life of the process.
set_idle_backoff(bool). After 2 s with no report and no request, a reader adds a 100 mspark_timeoutafter its usual gap, outside the device lock.with_open_group, which marks activity and unparks the readers before writing, so replies are still read at the normal cadence. Only an unsolicited report arriving while idle can be delayed (at most 100 ms; the OS queues it).HidService::start(GPUI) turns it on, so the Tauri app's reader behavior is unchanged.2. Wallpaper watcher only runs for Dynamic (
gpui/src/theme.rs)Each check spawns
osascripton macOS. It now skips the check unless the theme is Dynamic (re-checking the theme every 30 s). Switching to Dynamic already resamples on its own inAppView::set_theme.3. Window-activity flag (
gpui/src/activity.rs)A shared flag set from the main window's activation events (the game overlay is not observed). While the window is not active:
They slow rather than stop, so a game launching behind the window still applies its profile (up to about 10 s later), and regaining focus wakes them immediately. A window launched minimized at login is marked inactive explicitly.
Measurements
Linux sandbox, release build, mirroring the reader loop shape with
poll(2)on a pipe (no HID device available):Process scan cost is about 1 ms per tick with ~100 processes and about 7 ms with ~500. Install scan is under 2 ms per tick on a warm cache. The macOS
osascriptcost was not measured.Testing
cargo testincrates/openmouse-hidandgpuipass (new unit tests for the idle rule and the activity waiters).cargo check --all-targetsforgpuipasses on Linux.