From 394603727e85ca12483ff06abe3af7aa7bd5e248 Mon Sep 17 00:00:00 2001 From: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Sat, 5 Jul 2025 14:58:34 -0700 Subject: [PATCH] Bug: Param Store Cache (#1025) * cache * Clear every 10 iterations, which means 100hz * 10 * Revert "Clear every 10 iterations, which means 100hz * 10" This reverts commit 4eda3079e6cfc83008b8df0d41094ce52237faf7. * Apply suggestion from @devtekve * Apply suggestion from @devtekve --------- Co-authored-by: DevTekVE --- sunnypilot/selfdrive/controls/lib/param_store.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sunnypilot/selfdrive/controls/lib/param_store.py b/sunnypilot/selfdrive/controls/lib/param_store.py index b2701bc01..5ec2a1c8c 100644 --- a/sunnypilot/selfdrive/controls/lib/param_store.py +++ b/sunnypilot/selfdrive/controls/lib/param_store.py @@ -22,14 +22,16 @@ class ParamStore: self.keys = universal_params + brand_params self.values = {} + self.cached_params_list: list[capnp.lib.capnp._DynamicStructBuilder] | None = None def update(self, params: Params) -> None: + old_values = dict(self.values) self.values = {k: params.get(k, encoding='utf8') or "0" for k in self.keys} + if old_values != self.values: + self.cached_params_list = None def publish(self) -> list[capnp.lib.capnp._DynamicStructBuilder]: - params_list: list[capnp.lib.capnp._DynamicStructBuilder] = [] - - for k in self.keys: - params_list.append(custom.CarControlSP.Param(key=k, value=self.values[k])) - - return params_list + if self.cached_params_list is None: + # TODO-SP: Why are we doing a list instead of a dictionary here? + self.cached_params_list = [custom.CarControlSP.Param(key=k, value=self.values[k]) for k in self.keys] + return self.cached_params_list