From a4919f25044dad4a35f23c534b245be2a20175a1 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 5 Mar 2026 21:19:00 -1000 Subject: [PATCH] [log] Skip esp_log_vprintf_ indirection on non-flash platforms On platforms without USE_STORE_LOG_STR_IN_FLASH (ESP32, RP2040, LibreTiny), there is only one esp_log_printf_ overload, so the separate esp_log_vprintf_ function just adds an unnecessary call frame. Inline the logger dispatch directly into esp_log_printf_ for these platforms. The const char* esp_log_vprintf_ is still provided unconditionally for direct callers (e.g. midea component). On ESP8266 (USE_STORE_LOG_STR_IN_FLASH), the two esp_log_printf_ overloads continue to share esp_log_vprintf_ as before. Measured: 32 bytes flash saved on ESP32, no change on ESP8266. --- esphome/core/log.cpp | 30 +++++++++++++++--------------- esphome/core/log.h | 3 --- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/esphome/core/log.cpp b/esphome/core/log.cpp index 8338efbb33..8bf188ddbb 100644 --- a/esphome/core/log.cpp +++ b/esphome/core/log.cpp @@ -8,18 +8,31 @@ namespace esphome { +// Call log_vprintf_ directly to avoid extra indirection through esp_log_vprintf_ void HOT esp_log_printf_(int level, const char *tag, int line, const char *format, ...) { // NOLINT +#ifdef USE_LOGGER + auto *log = logger::global_logger; + if (log == nullptr) + return; + va_list arg; va_start(arg, format); - esp_log_vprintf_(level, tag, line, format, arg); + log->log_vprintf_(static_cast(level), tag, line, format, arg); va_end(arg); +#endif } #ifdef USE_STORE_LOG_STR_IN_FLASH void HOT esp_log_printf_(int level, const char *tag, int line, const __FlashStringHelper *format, ...) { +#ifdef USE_LOGGER + auto *log = logger::global_logger; + if (log == nullptr) + return; + va_list arg; va_start(arg, format); - esp_log_vprintf_(level, tag, line, format, arg); + log->log_vprintf_(static_cast(level), tag, line, format, arg); va_end(arg); +#endif } #endif @@ -33,19 +46,6 @@ void HOT esp_log_vprintf_(int level, const char *tag, int line, const char *form #endif } -#ifdef USE_STORE_LOG_STR_IN_FLASH -void HOT esp_log_vprintf_(int level, const char *tag, int line, const __FlashStringHelper *format, - va_list args) { // NOLINT -#ifdef USE_LOGGER - auto *log = logger::global_logger; - if (log == nullptr) - return; - - log->log_vprintf_(static_cast(level), tag, line, format, args); -#endif -} -#endif - #ifdef USE_ESP32 int HOT esp_idf_log_vprintf_(const char *format, va_list args) { // NOLINT #ifdef USE_LOGGER diff --git a/esphome/core/log.h b/esphome/core/log.h index a2c4b35c6e..14a0cb0572 100644 --- a/esphome/core/log.h +++ b/esphome/core/log.h @@ -60,9 +60,6 @@ void esp_log_printf_(int level, const char *tag, int line, const char *format, . void esp_log_printf_(int level, const char *tag, int line, const __FlashStringHelper *format, ...); #endif void esp_log_vprintf_(int level, const char *tag, int line, const char *format, va_list args); // NOLINT -#ifdef USE_STORE_LOG_STR_IN_FLASH -void esp_log_vprintf_(int level, const char *tag, int line, const __FlashStringHelper *format, va_list args); -#endif #if defined(USE_ESP32) int esp_idf_log_vprintf_(const char *format, va_list args); // NOLINT #endif