From 78d5f71fed3456f9c19c77e1d5b2c22970ba7cc4 Mon Sep 17 00:00:00 2001 From: whoisdomi Date: Tue, 5 May 2026 17:09:57 -0500 Subject: [PATCH] Efficiency batch 2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit D2 — update() in starpilot_onroad.cc now only fires when at least one overlay (showBlindspot, showSignal, showSteering, showFPS) is active. ~30–60 wasted repaints/sec eliminated when all overlays are off. E4 — Holiday theme check reordered so current_holiday_theme != "stock" (cheapest) is first. Default is stock, so the rest of the chain never evaluates on a normal non-holiday drive. E7 — paintSteeringTorqueBorder no longer rebuilds the QLinearGradient and computes lighter(120)/setAlpha/5 setColorAt calls every frame. The gradient is now built once in resizeEvent and reused. The per-frame work is now just the two geometry calculations and fillRect. E5/E6/E8 — Audited clean: all remaining params_memory.put calls are event-driven (button presses, random events), no hot-path logging exists in the UI code, and all QTimers are event-driven or single-shot offroad dialogs. --- starpilot/controls/lib/starpilot_events.py | 2 +- starpilot/ui/qt/onroad/starpilot_onroad.cc | 24 ++++++++++++---------- starpilot/ui/qt/onroad/starpilot_onroad.h | 1 + 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/starpilot/controls/lib/starpilot_events.py b/starpilot/controls/lib/starpilot_events.py index 37c3e0980..c748ba5f5 100644 --- a/starpilot/controls/lib/starpilot_events.py +++ b/starpilot/controls/lib/starpilot_events.py @@ -75,7 +75,7 @@ class StarPilotEvents: else: self.stopped_for_light = False - if "holidayActive" not in self.played_events and self.startup_seen and alerts_empty and len(self.events) == 0 and starpilot_toggles.current_holiday_theme != "stock": + if starpilot_toggles.current_holiday_theme != "stock" and "holidayActive" not in self.played_events and self.startup_seen and alerts_empty and len(self.events) == 0: self.events.add(StarPilotEventName.holidayActive) if self.starpilot_planner.tracking_lead and sm["carState"].standstill and sm["carState"].gearShifter not in NON_DRIVING_GEARS: diff --git a/starpilot/ui/qt/onroad/starpilot_onroad.cc b/starpilot/ui/qt/onroad/starpilot_onroad.cc index f8eff29ed..745ca155b 100644 --- a/starpilot/ui/qt/onroad/starpilot_onroad.cc +++ b/starpilot/ui/qt/onroad/starpilot_onroad.cc @@ -10,6 +10,15 @@ StarPilotOnroadWindow::StarPilotOnroadWindow(QWidget *parent) : QWidget(parent) void StarPilotOnroadWindow::resizeEvent(QResizeEvent *event) { rect = QWidget::rect(); marginRegion = QRegion(rect) - QRegion(rect.marginsRemoved(QMargins(UI_BORDER_SIZE, UI_BORDER_SIZE, UI_BORDER_SIZE, UI_BORDER_SIZE))); + + steeringGradient = QLinearGradient(rect.topLeft(), rect.bottomLeft()); + QColor bottomGreen = bg_colors[STATUS_ENGAGED].lighter(120); + bottomGreen.setAlpha(bg_colors[STATUS_ENGAGED].alpha()); + steeringGradient.setColorAt(0.0, bg_colors[STATUS_TRAFFIC_MODE_ENABLED]); + steeringGradient.setColorAt(0.25, bg_colors[STATUS_EXPERIMENTAL_MODE_ENABLED]); + steeringGradient.setColorAt(0.5, bg_colors[STATUS_CEM_DISABLED]); + steeringGradient.setColorAt(0.75, bg_colors[STATUS_ENGAGED]); + steeringGradient.setColorAt(1.0, bottomGreen); } void StarPilotOnroadWindow::updateState(const UIState &s, const StarPilotUIState &fs) { @@ -86,7 +95,9 @@ void StarPilotOnroadWindow::updateState(const UIState &s, const StarPilotUIState .arg(qRound(avgFPS)); } - update(); + if (showBlindspot || showSignal || showSteering || showFPS) { + update(); + } } void StarPilotOnroadWindow::paintEvent(QPaintEvent *event) { @@ -125,20 +136,11 @@ void StarPilotOnroadWindow::paintFPS(QPainter &p) { void StarPilotOnroadWindow::paintSteeringTorqueBorder(QPainter &p) { p.save(); - QLinearGradient gradient(rect.topLeft(), rect.bottomLeft()); - QColor bottomGreen = bg_colors[STATUS_ENGAGED].lighter(120); - bottomGreen.setAlpha(bg_colors[STATUS_ENGAGED].alpha()); - gradient.setColorAt(0.0, bg_colors[STATUS_TRAFFIC_MODE_ENABLED]); - gradient.setColorAt(0.25, bg_colors[STATUS_EXPERIMENTAL_MODE_ENABLED]); - gradient.setColorAt(0.5, bg_colors[STATUS_CEM_DISABLED]); - gradient.setColorAt(0.75, bg_colors[STATUS_ENGAGED]); - gradient.setColorAt(1.0, bottomGreen); - int visibleHeight = rect.height() * smoothedSteer; int xPos = (torque < 0) ? rect.x() : (rect.x() + rect.width() - UI_BORDER_SIZE); int yPos = rect.y() + rect.height() - visibleHeight; - p.fillRect(QRect(xPos, yPos, UI_BORDER_SIZE, visibleHeight), gradient); + p.fillRect(QRect(xPos, yPos, UI_BORDER_SIZE, visibleHeight), steeringGradient); p.restore(); } diff --git a/starpilot/ui/qt/onroad/starpilot_onroad.h b/starpilot/ui/qt/onroad/starpilot_onroad.h index 166073368..541f09d89 100644 --- a/starpilot/ui/qt/onroad/starpilot_onroad.h +++ b/starpilot/ui/qt/onroad/starpilot_onroad.h @@ -42,6 +42,7 @@ private: QColor rightBorderColor; QRect rect; + QLinearGradient steeringGradient; QRegion marginRegion;