Skip to content

fix(ui): pace repaint work and bound runtime workers#1372

Open
maybeknott wants to merge 3 commits into
therealaleph:mainfrom
maybeknott:fix/ui-repaint-pacing
Open

fix(ui): pace repaint work and bound runtime workers#1372
maybeknott wants to merge 3 commits into
therealaleph:mainfrom
maybeknott:fix/ui-repaint-pacing

Conversation

@maybeknott
Copy link
Copy Markdown

@maybeknott maybeknott commented May 23, 2026

This reduces idle desktop UI work and bounds the background runtime used by the desktop control surface.

The UI now derives repaint cadence from visible activity instead of requesting continuous redraws. Running proxy sessions, proxy start/stop transitions, certificate operations, active download/update/test/SNI probe states, and fresh transient messages keep the window on an active repaint interval. Idle windows use a slower interval so unchanged controls do not continuously consume CPU/GPU time.

Stats polling follows the same activity model. Active UI states continue to receive frequent snapshots, while idle states avoid unnecessary background polling. The transient status/message lifetimes are named constants shared by the activity detector and rendering path so repaint decisions and visible message expiry stay aligned.

The desktop background runtime is built with an explicit multi-thread Tokio runtime. Worker allocation is hardware-aware and clamped to a small bounded range, with blocking threads capped separately. Startup logs include the selected worker count so runtime sizing can be diagnosed without instrumenting the scheduler.

Validation:

  • git diff --check upstream/main..HEAD
  • cargo test repaint --features ui --bin mhrv-rs-ui
  • cargo test desktop_runtime_worker_count --features ui --bin mhrv-rs-ui

The desktop UI scheduled a repaint every 500 ms and sent stats-poll commands on the same update cadence regardless of whether the proxy was running, a transient message was visible, or any background operation was in flight. That kept the immediate-mode interface waking regularly even when the app was stopped and the window contained only static state.

Add a small activity predicate over UI state and use it to select the repaint cadence. Running proxy sessions, proxy startup/shutdown windows, certificate operations, downloads, update checks, SNI probes, and fresh transient status lines keep the existing 500 ms cadence. Fully idle UI state falls back to a slower two-second repaint request while still allowing egui to repaint immediately for user input.

Gate stats polling on the same active-state predicate so stopped or fully idle windows do not enqueue redundant PollStats commands into the background thread. The visible text, controls, command handlers, proxy lifecycle, and persisted configuration remain unchanged.

Add focused unit tests for the activity predicate covering idle state, running proxy state, in-flight SNI probes, and expired transient status timestamps.
@maybeknott maybeknott changed the title Wfix(ui): pace desktop repaint work by visible activity fix(ui): pace desktop repaint work by visible activity May 23, 2026
@github-actions github-actions Bot added the type: fix fix: PR — auto-applied by release-drafter label May 23, 2026
Replace the desktop UI background runtime's implicit Tokio defaults with an explicit multi-thread runtime builder. The UI now sizes its async worker pool from available_parallelism(), clamps long-lived worker threads to a small 2..=4 range, names worker threads as mhrv-ui-worker, and bounds the blocking pool separately at 32 threads.

This keeps proxy lifecycle tasks, stats polling, certificate operations, tests, scans, and update/download work on the same command paths while making the scheduler shape predictable on both low-core machines and high-core desktops. Small devices avoid a single-worker UI runtime, and large desktops avoid creating an oversized worker pool for a UI-owned background coordinator.

Log the selected runtime shape at UI startup so support reports can distinguish runtime sizing from proxy transport behavior. Add focused unit coverage for the worker-count policy across low-core, midrange, and high-core inputs.
Rename the desktop runtime sizing tests into their own module so they do not collide with the repaint pacing tests in the same binary test namespace.

This keeps the repaint activity checks and runtime worker-count checks independently addressable while allowing the UI test binary to compile with the ui feature enabled.
@maybeknott maybeknott changed the title fix(ui): pace desktop repaint work by visible activity fix(ui): pace repaint work and bound runtime workers May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix fix: PR — auto-applied by release-drafter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant