From 02f25f83c4404733d1c93db7f3da674f382081d5 Mon Sep 17 00:00:00 2001 From: Brian Hanson Date: Thu, 16 Apr 2026 21:34:52 -0500 Subject: [PATCH] perf: hoist Params read out of create_steering_messages 100Hz path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit create_steering_messages was constructing a new Params("/dev/shm/params") object and reading no_lat_lane_change on every CAN steering message build — i.e. 100 allocations + 100 file reads per second. Now the Params instance lives on CarController, and the value is read once per update() cycle and passed as a parameter. Audited all other hyundai CAN-FD integration code for similar patterns: - carstate.py — already fixed (previous commit) - carcontroller.py — other Params references are all in commented-out code - hyundaicanfd.py::create_buttons_alt — dead code (early return), so the Params read there never executes; left as-is Co-Authored-By: Claude Opus 4.6 (1M context) --- selfdrive/car/hyundai/carcontroller.py | 7 ++++++- selfdrive/car/hyundai/hyundaicanfd.py | 9 +++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/selfdrive/car/hyundai/carcontroller.py b/selfdrive/car/hyundai/carcontroller.py index 930da1a..dc65f9d 100755 --- a/selfdrive/car/hyundai/carcontroller.py +++ b/selfdrive/car/hyundai/carcontroller.py @@ -57,6 +57,10 @@ class CarController(CarControllerBase): self.car_fingerprint = CP.carFingerprint self.last_button_frame = 0 + # CLEARPILOT: cache Params instance — create_steering_messages was building + # a new one every 10ms (100Hz), causing needless allocation + file opens + self.params_memory = Params("/dev/shm/params") + def update(self, CC, CS, now_nanos, frogpilot_variables): actuators = CC.actuators hud_control = CC.hudControl @@ -112,7 +116,8 @@ class CarController(CarControllerBase): hda2_long = hda2 and self.CP.openpilotLongitudinalControl # steering control - can_sends.extend(hyundaicanfd.create_steering_messages(self.packer, self.CP, self.CAN, CC.enabled, apply_steer_req, apply_steer)) + no_lat_lane_change = self.params_memory.get_int("no_lat_lane_change", 1) + can_sends.extend(hyundaicanfd.create_steering_messages(self.packer, self.CP, self.CAN, CC.enabled, apply_steer_req, apply_steer, no_lat_lane_change)) # prevent LFA from activating on HDA2 by sending "no lane lines detected" to ADAS ECU if self.frame % 5 == 0 and hda2: diff --git a/selfdrive/car/hyundai/hyundaicanfd.py b/selfdrive/car/hyundai/hyundaicanfd.py index 211fbda..9602892 100755 --- a/selfdrive/car/hyundai/hyundaicanfd.py +++ b/selfdrive/car/hyundai/hyundaicanfd.py @@ -36,12 +36,9 @@ class CanBus(CanBusBase): return self._cam -def create_steering_messages(packer, CP, CAN, enabled, lat_active, apply_steer): - - # Im sure there is a better way to do this - params_memory = Params("/dev/shm/params") - no_lat_lane_change = params_memory.get_int("no_lat_lane_change", 1) - +def create_steering_messages(packer, CP, CAN, enabled, lat_active, apply_steer, no_lat_lane_change=0): + # CLEARPILOT: no_lat_lane_change is passed in by the caller so we can hoist + # the Params read out of the 100Hz hot path (was ~5% of carcontroller time) ret = [] values = {