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:
J. Nick Koston
2026-03-17 01:14:39 -10:00
parent 2785edaac8
commit e01670eed8
2 changed files with 6 additions and 12 deletions
-7
View File
@@ -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);
+6 -5
View File
@@ -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++; });
}