openpilot icon indicating copy to clipboard operation
openpilot copied to clipboard

system/ui: performance optimizations for WiFi Manager with cached network data

Open deanlee opened this issue 6 months ago • 0 comments
trafficstars

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:

  1. Event-based updates: Added a new networks_updated callback to notify the UI when network data changes
  2. Cached network information: Store network data locally in the WifiManagerUI
  3. Embedded network status: Added is_saved field to NetworkInfo class 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.

deanlee avatar May 10 '25 14:05 deanlee