Skip to content

perf(ui): reduce unnecessary UI-thread work#147

Open
Neutron-0 wants to merge 1 commit into
theantipopau:mainfrom
Neutron-0:perf/ui-thread-optimizations
Open

perf(ui): reduce unnecessary UI-thread work#147
Neutron-0 wants to merge 1 commit into
theantipopau:mainfrom
Neutron-0:perf/ui-thread-optimizations

Conversation

@Neutron-0

Copy link
Copy Markdown

This PR reduces unnecessary UI-thread work identified while investigating Issue #133.

Summary

This PR reduces unnecessary UI‑thread work while preserving existing behavior. It addresses performance concerns raised in GitHub issue #133 by tightening log handling, pausing the dashboard uptime timer when inactive, and avoiding redundant tray‑icon refreshes.

Changes

  • Log buffering – Introduced a StringBuilder in MainViewModel and rebuilt the buffer only when the log line queue exceeds the UI limit.
  • Dashboard uptime timer – Timer start is now deferred; SetUptimeTimerEnabled starts the timer when telemetry projection is enabled and stops it when disabled.
  • Tray icon caching – Added cached fields for all displayed metrics, implemented early‑return when values are unchanged, and updated caches after a UI refresh.
  • Allocation reduction – Fewer string allocations and dispatcher posts across the UI.
  • Code cleanup – Removed a duplicate cache‑update block in TrayIconService.

Behavior

No functional changes are intended. All UI elements continue to display the same information; only the amount of work performed on the UI thread is reduced.

Testing

  • dotnet build OmenCore.sln succeeds with 0 warnings and 0 errors.
  • All existing unit tests (OmenCoreApp.Tests) pass.
  • Manual verification confirms:
    • Log view updates correctly after appending and after buffer reload.
    • Dashboard uptime counter updates only when the dashboard is visible.
    • Tray tooltip, menu, and badge updates occur only when a displayed value actually changes.

Expected Impact

  • Lower CPU usage on the UI thread during idle periods.
  • Fewer allocations and garbage‑collection pressure.
  • Reduced dispatcher activity leading to smoother UI responsiveness, especially when the app is monitoring continuously.

Related to #133

- Optimize log buffering by using a StringBuilder to avoid per‑line string allocations and rebuild only when the queue exceeds MaxUiLogLines.\n- Defer the dashboard uptime timer start and stop it when telemetry projection is disabled, eliminating unnecessary timer ticks while the dashboard is hidden.\n- Add cached fields and change‑detection logic in TrayIconService to skip UI updates when displayed values have not changed, removing redundant string interpolation and dispatcher work.\n- Remove duplicate cache‑update block to keep the code concise and avoid potential hidden bugs.
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.

1 participant