Skip to content

Fix Windows high CPU usage during idle repaints#69

Merged
kissetfall merged 4 commits into
ergohaven:mainfrom
IgorArkhipov:igor/windows-high-cpu-lifecycle-fix
Jul 17, 2026
Merged

Fix Windows high CPU usage during idle repaints#69
kissetfall merged 4 commits into
ergohaven:mainfrom
IgorArkhipov:igor/windows-high-cpu-lifecycle-fix

Conversation

@IgorArkhipov

@IgorArkhipov IgorArkhipov commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

EN

Summary

This PR targets the Windows high-CPU behavior tracked in #59.

The eframe/egui 0.34.3 lifecycle update fixed the hidden/minimized event-loop spin. Testing of the previous artifact confirmed low CPU in every USB, minimized, and tray-hidden scenario. One case remained: Bluetooth keyboard selected while the Entropy window was visible in the foreground.

That result matched a separate Bluetooth-only 16 ms idle repaint cadence. A visible eframe window rendered continuously at roughly 60 FPS; minimized and tray-hidden windows skipped UI rendering, explaining why those Bluetooth modes were already normal.

Windows now uses the normal 250 ms visible-idle cadence for Bluetooth too. Pending work still schedules faster repaints when needed. Non-Windows Bluetooth behavior is unchanged. A target-independent regression test covers both Windows and non-Windows policy.

PR #64 remains useful diagnostic evidence: suppressing unnecessary updates removed the load. This implementation uses the upstream eframe lifecycle fix plus bounded idle repaint scheduling rather than copying PR #64's one-frame workaround.

Runtime status

Scenario Initial worker artifact Lifecycle artifact 8298499259 Current artifact 8314186932
USB, foreground Normal Normal Normal, confirmed
USB, minimized Normal Normal Normal, confirmed
USB, hidden to tray 100% of one CPU core Normal Normal, confirmed
Bluetooth, foreground Normal High CPU Normal, confirmed
Bluetooth, minimized Normal Normal Normal, confirmed
Bluetooth, hidden to tray 100% of one CPU core Normal Normal, confirmed

Current Windows test build: entropy-windows

Windows runtime validation is complete: zero CPU load was reported across foreground, minimized, and tray states for both USB and Bluetooth. Restoring from tray and closing the application also work as expected.

Verification

  • rebased onto current main; overlapping device-connect, layer-write, picker, and lifecycle behavior preserved
  • cargo test --all-targets: 196 passed
  • cargo check --all-targets
  • cargo clippy --all-targets: passes with existing warning baseline
  • touched-file rustfmt --check
  • git diff --check
  • prior macOS lifecycle smoke: Glow launch, Phenom connection, 0.1% CPU while minimized, restore, and clean close
  • GitHub Actions run 29341072827: Windows, Ubuntu, macOS ARM, and macOS Intel passed
  • Final Windows runtime validation: zero CPU load in all USB/Bluetooth foreground, minimized, and tray states; restore and close work
  • local Windows target compilation remains unavailable on this macOS host because ring requires MSVC C headers

References

Fixes #59
Related: #64

RU

Кратко

Этот PR исправляет высокую загрузку CPU в Windows из #59.

Обновление жизненного цикла до eframe/egui 0.34.3 устранило активный цикл для скрытого и свернутого окна. Проверка предыдущего artifact подтвердила нормальную загрузку CPU для всех USB-сценариев, а также для свернутого и скрытого в трей окна. Остался один случай: клавиатура подключена по Bluetooth, а окно Entropy находится на переднем плане.

Результат совпал с отдельным Bluetooth-интервалом idle repaint в 16 мс. Видимое окно eframe постоянно отрисовывалось примерно с частотой 60 FPS; свернутое и скрытое в трей окно UI не отрисовывало, поэтому в этих Bluetooth-режимах загрузка уже была нормальной.

Теперь в Windows для Bluetooth также используется обычный idle-интервал видимого окна в 250 мс. Незавершенные фоновые операции по-прежнему запрашивают более быстрый repaint при необходимости. Поведение Bluetooth в других ОС не изменено. Регрессионный тест проверяет политику Windows и других ОС независимо от host-системы.

PR #64 остается полезным диагностическим примером: устранение лишних обновлений убирало нагрузку. Эта реализация использует upstream-исправление жизненного цикла eframe и ограниченный idle repaint, а не копирует workaround PR #64 с одним update frame.

Статус проверки

Сценарий Первый artifact с worker Lifecycle artifact 8298499259 Текущий artifact 8314186932
USB, обычное окно Нормально Нормально Нормально, подтверждено
USB, свернуто Нормально Нормально Нормально, подтверждено
USB, скрыто в трей 100% одного ядра CPU Нормально Нормально, подтверждено
Bluetooth, обычное окно Нормально Высокая загрузка CPU Нормально, подтверждено
Bluetooth, свернуто Нормально Нормально Нормально, подтверждено
Bluetooth, скрыто в трей 100% одного ядра CPU Нормально Нормально, подтверждено

Текущая тестовая сборка для Windows: entropy-windows

Проверка в Windows завершена: нулевая загрузка CPU подтверждена для обычного, свернутого и скрытого в трей окна при USB- и Bluetooth-подключении. Восстановление из трея и закрытие приложения также работают корректно.

Проверка

  • rebase на актуальный main; сохранено пересекающееся поведение device connect, layer write, picker и lifecycle
  • cargo test --all-targets: 196 тестов проходит
  • cargo check --all-targets
  • cargo clippy --all-targets: проходит с существующим baseline предупреждений
  • rustfmt --check для затронутых файлов
  • git diff --check
  • предыдущий lifecycle smoke test в macOS: запуск с Glow, подключение Phenom, 0.1% CPU в свернутом состоянии, восстановление и корректное закрытие
  • GitHub Actions run 29341072827: Windows, Ubuntu, macOS ARM и macOS Intel прошли
  • Финальная проверка в Windows: нулевая загрузка CPU во всех режимах USB/Bluetooth; восстановление и закрытие работают
  • локальная компиляция Windows target на этом macOS host по-прежнему невозможна без MSVC C headers, требуемых ring

Ссылки

Связано с #59
Связано с #64

Move Windows repaint delays off eframe event loop so hidden and Bluetooth windows remain in ControlFlow::Wait. Preserve connect, update, tray, shutdown, and non-Windows repaint behavior with regression tests.
Upgrade to eframe and egui 0.34.3 for upstream hidden-window repaint throttling. Run lifecycle and background work in App::logic while App::ui handles visible rendering, and keep Glow to avoid an unrelated renderer change.
@IgorArkhipov
IgorArkhipov force-pushed the igor/windows-high-cpu-lifecycle-fix branch from 89b3fd6 to dd2726d Compare July 14, 2026 14:29
@IgorArkhipov
IgorArkhipov marked this pull request as ready for review July 14, 2026 14:54
@kissetfall
kissetfall merged commit 00694d6 into ergohaven:main Jul 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

High CPU usage when minimized to the system tray

2 participants