From 8d36935083582a3e41db4e93d387935d1665034a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 5 Mar 2026 21:49:26 -1000 Subject: [PATCH] [log] Strengthen comment about no null checks on hot path --- esphome/core/log.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/esphome/core/log.cpp b/esphome/core/log.cpp index ad641f1981..13a1fef5f7 100644 --- a/esphome/core/log.cpp +++ b/esphome/core/log.cpp @@ -8,9 +8,13 @@ namespace esphome { -// No null check on global_logger — Logger::pre_setup() sets global_logger -// before any other component is created in the generated setup() function, -// so it is guaranteed to be valid by the time any log function is invoked. +// IMPORTANT: Do not add null checks on global_logger here. +// These functions are the hot path for ALL logging across the entire firmware, +// so every instruction matters. Logger::pre_setup() sets global_logger before +// any other component is created in the generated setup() function, so it is +// guaranteed to be valid by the time any log function is invoked. This invariant +// is enforced by codegen ordering and tested in +// tests/component_tests/logger/test_logger.py. void HOT esp_log_printf_(int level, const char *tag, int line, const char *format, ...) { // NOLINT #ifdef USE_LOGGER va_list arg;