From 57fd7552e3c3d59e97d0508463e03f84040d0903 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 6 Sep 2025 22:52:48 -0500 Subject: [PATCH] [core] Skip redundant process_to_add() call when no scheduler items added --- esphome/core/scheduler.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/esphome/core/scheduler.cpp b/esphome/core/scheduler.cpp index a907b89b02..65c58e401e 100644 --- a/esphome/core/scheduler.cpp +++ b/esphome/core/scheduler.cpp @@ -326,6 +326,9 @@ void HOT Scheduler::call(uint32_t now) { const auto now_64 = this->millis_64_(now); // 'now' from parameter - fresh from Application::loop() this->process_to_add(); + // Track if we add any interval items during this call + bool added_intervals = false; + #ifdef ESPHOME_DEBUG_SCHEDULER static uint64_t last_print = 0; @@ -470,10 +473,14 @@ void HOT Scheduler::call(uint32_t now) { // since we have the lock held this->to_add_.push_back(std::move(item)); } + + added_intervals |= this->to_add_.empty() == false; } } - this->process_to_add(); + if (added_intervals) { + this->process_to_add(); + } } void HOT Scheduler::process_to_add() { LockGuard guard{this->lock_};