From e2e2b7d699bd5a471a43053edc198c8bb7743383 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 1 Apr 2026 10:09:20 -1000 Subject: [PATCH] [api] Move schedule_message_front_ out-of-line to avoid cold path bloat schedule_message_front_ is only called from cold paths (on_shutdown, check_keepalive_). Moving it out-of-line prevents add_item_front and push_back from being inlined into those callers. --- esphome/components/api/api_connection.cpp | 5 +++++ esphome/components/api/api_connection.h | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index c882d48112..a3e899b32a 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -2072,6 +2072,11 @@ void APIConnection::on_fatal_error() { this->flags_.remove = true; } +bool APIConnection::schedule_message_front_(EntityBase *entity, uint8_t message_type, uint8_t estimated_size) { + this->deferred_batch_.add_item_front(entity, message_type, estimated_size); + return this->schedule_batch_(); +} + bool APIConnection::send_message_smart_(EntityBase *entity, uint8_t message_type, uint8_t estimated_size, uint8_t aux_data_index) { if (this->should_send_immediately_(message_type) && this->helper_->can_write_without_blocking()) { diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index 776b67738c..433b13bf2a 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -797,10 +797,8 @@ class APIConnection final : public APIServerConnectionBase { } // Helper function to schedule a high priority message at the front of the batch - bool schedule_message_front_(EntityBase *entity, uint8_t message_type, uint8_t estimated_size) { - this->deferred_batch_.add_item_front(entity, message_type, estimated_size); - return this->schedule_batch_(); - } + // Out-of-line: callers (on_shutdown, check_keepalive_) are cold paths + bool schedule_message_front_(EntityBase *entity, uint8_t message_type, uint8_t estimated_size); // Helper function to log client messages with name and peername void log_client_(int level, const LogString *message);