openpilot
openpilot copied to clipboard
system/ui: performance optimizations for WiFi Manager with cached network data
This PR fixes the FPS issue where the UI could not reach 60 FPS due to inefficient network list retrieval. Previously, _run_coroutine_sync was called at 60Hz to fetch network lists, causing the UI thread to block while waiting for the asyncio thread to respond.
Now, by implementing an event-based approach with callbacks, the network list is only updated when actual changes occur. This significantly improves performance:
- CPU usage reduced from ~55% to ~15% during UI rendering on my laptop
- Frame rate consistently reaches 60 FPS instead of stuttering
Key improvements:
- Event-based updates: Added a new
networks_updatedcallback to notify the UI when network data changes - Cached network information: Store network data locally in the
WifiManagerUI - Embedded network status: Added
is_savedfield toNetworkInfoclass to avoid repeated checks
These changes maintain the same functionality while significantly reducing CPU load and making the UI more responsive.
_run_coroutine_sync is preserved in the codebase as it remains valuable for other direct DBus operations and for future advanced network UI widgets that need synchronous access.