From 79d2d8e5c8168349420cd050428cf4222c56ef6b Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 28 Mar 2026 10:28:40 -1000 Subject: [PATCH] [automation] Remove actions_end_ pointer from ActionList Save 4 bytes per ActionList instance by removing the tail pointer used only during setup() for O(1) append. Instead, walk the short chain (typically 1-5 actions) to find the tail. This saves 4 bytes per Automation on 32-bit platforms, which adds up on memory-constrained devices like ESP8266 with many automations. --- esphome/core/automation.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/esphome/core/automation.h b/esphome/core/automation.h index fc2cad99be..3cb8caa026 100644 --- a/esphome/core/automation.h +++ b/esphome/core/automation.h @@ -419,12 +419,15 @@ template class Action { template class ActionList { public: void add_action(Action *action) { - if (this->actions_end_ == nullptr) { + if (this->actions_begin_ == nullptr) { this->actions_begin_ = action; } else { - this->actions_end_->next_ = action; + // Walk to end of chain - action lists are short and only built during setup() + auto *it = this->actions_begin_; + while (it->next_ != nullptr) + it = it->next_; + it->next_ = action; } - this->actions_end_ = action; } void add_actions(const std::initializer_list *> &actions) { for (auto *action : actions) { @@ -465,7 +468,6 @@ template class ActionList { } Action *actions_begin_{nullptr}; - Action *actions_end_{nullptr}; }; template class Automation {