From 44be29789ac300f7d257bd840e7850e21502ce46 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 1 Apr 2026 09:53:37 -1000 Subject: [PATCH] [api] Inline push_item to allow push_back to be inlined into caller The out-of-line push_item with __attribute__((flatten)) inlined push_back's callees into push_item, but push_item itself remained a function call barrier. Moving push_item inline lets the compiler inline push_back into the actual call sites (add_item, add_item_front). --- esphome/components/api/api_connection.cpp | 2 -- esphome/components/api/api_connection.h | 5 +---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 79df85ada35..6bcaf52ba61 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -2072,8 +2072,6 @@ 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 295346bb051..3187a6df057 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -647,10 +647,7 @@ 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); - // 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); + void push_item(const BatchItem &item) { items.push_back(item); } // Clear all items void clear() {