From 66e0c866d70c921862f096aecabb075bfef6ec5a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 21 Apr 2026 06:08:34 +0200 Subject: [PATCH] =?UTF-8?q?[core]=20rename=20after=5Floop=5Ftasks=5F=20?= =?UTF-8?q?=E2=86=92=20after=5Fcomponent=5Fphase=5F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Matches the before_component_phase_ / after_component_phase_ symmetry now that Phase A and Phase B are separated. Also move the call to the very end of the `if (do_component_phase) { ... }` block so the helper semantically closes out the phase, rather than sitting before the last_loop_ / now bookkeeping. No functional change: in_loop_ is read only inside the component iteration (disable_looping_component's swap fixup), so setting it false at any point after the for-loop ends is equivalent. Runtime-stats tail timing still captures the same region (the micros() sample happens before any of the moved lines). --- esphome/components/runtime_stats/runtime_stats.h | 2 +- esphome/core/application.cpp | 2 +- esphome/core/application.h | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/esphome/components/runtime_stats/runtime_stats.h b/esphome/components/runtime_stats/runtime_stats.h index 24b6807008..7299fd7315 100644 --- a/esphome/components/runtime_stats/runtime_stats.h +++ b/esphome/components/runtime_stats/runtime_stats.h @@ -41,7 +41,7 @@ class RuntimeStatsCollector { // active_us = total time between loop start and just before yield. // before_us = time spent in Phase A (scheduler tick) excluding time // already attributed to per-component stats. - // tail_us = time spent in after_loop_tasks_ + the trailing record/stats + // tail_us = time spent in after_component_phase_ + the trailing record/stats // prefix. On Phase A-only ticks (component phase gated) this // is just the small trailing prefix between loop_before_end_us // and loop_now_us — non-zero but typically a few µs. diff --git a/esphome/core/application.cpp b/esphome/core/application.cpp index b06d37ee44..b626eb1de6 100644 --- a/esphome/core/application.cpp +++ b/esphome/core/application.cpp @@ -106,7 +106,7 @@ void Application::setup() { this->feed_wdt(); } - this->after_loop_tasks_(); + this->after_component_phase_(); yield(); } while (!component->can_proceed() && !component->is_failed()); } diff --git a/esphome/core/application.h b/esphome/core/application.h index 808a75d880..e1a6109f3e 100644 --- a/esphome/core/application.h +++ b/esphome/core/application.h @@ -428,7 +428,7 @@ class Application { void activate_looping_component_(uint16_t index); inline uint32_t ESPHOME_ALWAYS_INLINE scheduler_tick_(uint32_t now); inline void ESPHOME_ALWAYS_INLINE before_component_phase_(); - inline void ESPHOME_ALWAYS_INLINE after_loop_tasks_() { this->in_loop_ = false; } + inline void ESPHOME_ALWAYS_INLINE after_component_phase_() { this->in_loop_ = false; } /// Process dump_config output one component per loop iteration. /// Extracted from loop() to keep cold startup/reconnect logging out of the hot path. @@ -694,10 +694,9 @@ inline void ESPHOME_ALWAYS_INLINE Application::loop() { #ifdef USE_RUNTIME_STATS loop_tail_start_us = micros(); #endif - this->after_loop_tasks_(); - this->last_loop_ = last_op_end_time; now = last_op_end_time; + this->after_component_phase_(); } #ifdef USE_RUNTIME_STATS