diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 6bcaf52ba61..79df85ada35 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -2072,6 +2072,8 @@ void APIConnection::on_fatal_error() { this->flags_.remove = true; } +void __attribute__((flatten)) APIConnection::DeferredBatch::push_item(const BatchItem &item) { items.push_back(item); } + void APIConnection::DeferredBatch::add_item(EntityBase *entity, uint8_t message_type, uint8_t estimated_size, uint8_t aux_data_index) { // Check if we already have a message of this type for this entity diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index 3187a6df057..295346bb051 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -647,7 +647,10 @@ class APIConnection final : public APIServerConnectionBase { uint8_t aux_data_index = AUX_DATA_UNUSED); // Add item to the front of the batch (for high priority messages like ping) void add_item_front(EntityBase *entity, uint8_t message_type, uint8_t estimated_size); - void push_item(const BatchItem &item) { items.push_back(item); } + // Out-of-line with flatten: inlines push_back callees into push_item, + // but keeps push_item itself as a call from add_item. This prevents + // the compiler from bloating add_item's dedup loop and degrading icache. + void push_item(const BatchItem &item); // Clear all items void clear() {