From e01670eed897821979ede5ffdaa7788d63f835ce Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 17 Mar 2026 01:14:39 -1000 Subject: [PATCH] Revert core changes, use intervals with fake time for scheduler benchmark MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The warn_blocking underflow only happens with fake time in benchmarks, not in production (millis() is monotonic). Accept the consistent overhead from one warning per call — CodSpeed regression detection works on relative changes, not absolute values. --- esphome/core/component.cpp | 7 ------- tests/benchmarks/core/bench_scheduler.cpp | 11 ++++++----- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/esphome/core/component.cpp b/esphome/core/component.cpp index 172842ee3d..bfe9beb272 100644 --- a/esphome/core/component.cpp +++ b/esphome/core/component.cpp @@ -512,13 +512,6 @@ void PollingComponent::set_update_interval(uint32_t update_interval) { this->upd void __attribute__((noinline, cold)) WarnIfComponentBlockingGuard::warn_blocking(Component *component, uint32_t blocking_time) { - // Clamp underflowed values: if millis() < started_ (e.g. scheduler passes - // a `now` slightly ahead of real millis()), the subtraction wraps to ~4 billion. - // Clamping to uint16_t max lets should_warn_of_blocking() saturate the - // threshold and suppress further warnings. - if (blocking_time > std::numeric_limits::max()) { - blocking_time = std::numeric_limits::max(); - } bool should_warn; if (component != nullptr) { should_warn = component->should_warn_of_blocking(blocking_time); diff --git a/tests/benchmarks/core/bench_scheduler.cpp b/tests/benchmarks/core/bench_scheduler.cpp index 160ab3c123..0ae8b4add0 100644 --- a/tests/benchmarks/core/bench_scheduler.cpp +++ b/tests/benchmarks/core/bench_scheduler.cpp @@ -66,11 +66,12 @@ static void Scheduler_Call_5IntervalsFiring(benchmark::State &state) { BenchComponent dummy_component; int fire_count = 0; - // Add 5 intervals with 1ms period — they fire every call when time advances. - // We use monotonically increasing fake time (now++) so intervals reliably fire. - // The underflow guard in WarnIfComponentBlockingGuard::finish() (curr_time >= started_) - // prevents warn_blocking from firing when fake time exceeds real millis(). - // Note: interval=0 causes infinite loop (reschedules at same now, never breaks). + // Benchmarks the heap-based scheduler dispatch with 5 callbacks firing. + // Uses monotonically increasing fake time so intervals reliably fire every call. + // The first item per call triggers one WarnIfComponentBlockingGuard warning + // (fake now > real millis() causes underflow in finish()), but this is + // consistent overhead per iteration so CodSpeed regression detection works. + // interval=0 would cause an infinite loop (reschedules at same now). for (int i = 0; i < 5; i++) { scheduler.set_interval(&dummy_component, static_cast(i), 1, [&fire_count]() { fire_count++; }); }