mirror of
https://github.com/esphome/esphome.git
synced 2026-09-01 02:26:01 +00:00
Revert core changes, use intervals with fake time for scheduler benchmark
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.
This commit is contained in:
@@ -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<uint16_t>::max()) {
|
||||
blocking_time = std::numeric_limits<uint16_t>::max();
|
||||
}
|
||||
bool should_warn;
|
||||
if (component != nullptr) {
|
||||
should_warn = component->should_warn_of_blocking(blocking_time);
|
||||
|
||||
@@ -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<uint32_t>(i), 1, [&fire_count]() { fire_count++; });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user