fix: reduce idle CPU usage on macOS (tray title dedup, pause hidden-w…#2186
fix: reduce idle CPU usage on macOS (tray title dedup, pause hidden-w…#2186Code-newWorld wants to merge 1 commit into
Conversation
…indow polling) On newer macOS versions (especially with TUN enabled), FlClash keeps a constant 40-50% CPU load in the background. Four independent per-second hot paths cause this: - Tray.updateTrayTitle called trayManager.setTitle every second even when the value was unchanged or the tray title was disabled. Each setTitle triggers a full NSStatusItem redraw on recent macOS. Now the last title is cached and the native call is skipped when unchanged. - trayTitleState subscribed to per-second traffic updates even with showTrayTitle off. It now returns a constant state in that case. - The 1s runtime/traffic poll timer now skips its two core IPC round-trips while the window is hidden and the tray title is off (nothing consumes those values). Resumes automatically on show. - getTraffic/getTotalTraffic invocations no longer emit two log entries per second each; other methods keep logging as before. - Request push messages from the core (one per connection under TUN) are no longer JSON-parsed while the window is hidden. No behavior change while the window is visible. Co-authored-by: Cursor <cursoragent@cursor.com>
|
I tested the tray-title part of this PR on a real multi-display macOS setup and can confirm the root cause and the effectiveness of the deduplication. Environment
Before / afterOfficial build before the fix:
Local build with tray-title deduplication plus the current tray_manager self-drawn-title fix:
A native harness that changed the tray title every second stayed at 0.1%-0.5% CPU. It had only 3 incidental Validation used Flutter 3.41.9: Two implementation suggestions
The title deduplication alone addresses the disabled-title case from #1644. The hidden-window polling and request-parsing changes touch broader behavior, so splitting them from the minimal tray fix may make review and regression analysis easier. |
|
Thanks for the thorough multi-display validation — really helpful. I've addressed your implementation notes:
Agreed on splitting. I've opened a minimal tray-title-only PR here: #2201 The hidden-window polling / request-parsing / silent-IPC changes can follow in a separate PR. |
…indow polling)
On newer macOS versions (especially with TUN enabled), FlClash keeps a constant 40-50% CPU load in the background. Four independent per-second hot paths cause this:
No behavior change while the window is visible.