diff --git a/selfdrive/ui/layouts/settings/starpilot/main_panel.py b/selfdrive/ui/layouts/settings/starpilot/main_panel.py index 03759d7fa..b234871cb 100644 --- a/selfdrive/ui/layouts/settings/starpilot/main_panel.py +++ b/selfdrive/ui/layouts/settings/starpilot/main_panel.py @@ -7,7 +7,7 @@ from openpilot.system.ui.widgets import Widget from openpilot.system.ui.lib.multilang import tr, tr_noop from openpilot.system.ui.lib.application import MousePos, gui_app, FontWeight -from openpilot.selfdrive.ui.layouts.settings.starpilot.panel import StarPilotPanelType, StarPilotPanelInfo, SettingsParamsWrapper +from openpilot.selfdrive.ui.layouts.settings.starpilot.panel import StarPilotPanelType, StarPilotPanelInfo, FrameCachedParams from openpilot.selfdrive.ui.layouts.settings.starpilot.sounds import StarPilotSoundsLayout from openpilot.selfdrive.ui.layouts.settings.starpilot.driving_model import StarPilotDrivingModelLayout from openpilot.selfdrive.ui.layouts.settings.starpilot.longitudinal import StarPilotLongitudinalLayout @@ -55,7 +55,7 @@ class StarPilotLayout(Widget): def __init__(self): super().__init__() - self._params = SettingsParamsWrapper() + self._params = FrameCachedParams() self._current_panel = StarPilotPanelType.MAIN self._current_category_idx: int | None = None diff --git a/selfdrive/ui/layouts/settings/starpilot/panel.py b/selfdrive/ui/layouts/settings/starpilot/panel.py index 4804b4b6e..6a7728ea8 100644 --- a/selfdrive/ui/layouts/settings/starpilot/panel.py +++ b/selfdrive/ui/layouts/settings/starpilot/panel.py @@ -16,23 +16,48 @@ from openpilot.selfdrive.ui.layouts.settings.starpilot.sectioned_panel import Se import time -class SettingsParamsWrapper: +class FrameCachedParams: def __init__(self): self._params = ui_state.params + self._cache = {} + self._last_frame_time = 0.0 + + def _check_clear_cache(self): + now = time.monotonic() + if now != self._last_frame_time: + self._cache.clear() + self._last_frame_time = now def get(self, key, **kwargs): - return self._params.get(key, **kwargs) + self._check_clear_cache() + cache_key = (key, "get", tuple(kwargs.items())) + if cache_key not in self._cache: + self._cache[cache_key] = self._params.get(key, **kwargs) + return self._cache[cache_key] def get_bool(self, key, **kwargs): - return self._params.get_bool(key, **kwargs) + self._check_clear_cache() + cache_key = (key, "get_bool", tuple(kwargs.items())) + if cache_key not in self._cache: + self._cache[cache_key] = self._params.get_bool(key, **kwargs) + return self._cache[cache_key] def get_int(self, key, **kwargs): - return self._params.get_int(key, **kwargs) + self._check_clear_cache() + cache_key = (key, "get_int", tuple(kwargs.items())) + if cache_key not in self._cache: + self._cache[cache_key] = self._params.get_int(key, **kwargs) + return self._cache[cache_key] def get_float(self, key, **kwargs): - return self._params.get_float(key, **kwargs) + self._check_clear_cache() + cache_key = (key, "get_float", tuple(kwargs.items())) + if cache_key not in self._cache: + self._cache[cache_key] = self._params.get_float(key, **kwargs) + return self._cache[cache_key] def _notify_changed(self): + self._cache.clear() update_starpilot_toggles() def put(self, key, val, **kwargs): @@ -83,7 +108,7 @@ class StarPilotPanel(Widget): def __init__(self): super().__init__() self._params_memory = ui_state.params_memory - self._params = SettingsParamsWrapper() + self._params = FrameCachedParams() self._navigate_callback: Callable | None = None self._back_callback: Callable | None = None self._current_sub_panel = ""