From 87a2b623f36d6aa0e8e325acdf4cad4af084da77 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 30 Apr 2026 11:01:24 -0500 Subject: [PATCH] [sensor] Drop incorrect O(1) complexity claim from timeout filter comment set_timer_common_'s self-key cancel path scans items_ and to_add_ linearly, so the cancel-and-replace is O(N) in the global scheduler item count, not O(1). Reword to describe the behavior without the complexity claim. Address Copilot review feedback. --- esphome/components/sensor/filter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esphome/components/sensor/filter.cpp b/esphome/components/sensor/filter.cpp index 44556f6ed7..a4d42c5eea 100644 --- a/esphome/components/sensor/filter.cpp +++ b/esphome/components/sensor/filter.cpp @@ -323,8 +323,8 @@ optional or_filter_new_value(Filter **filters, size_t count, float value, } // TimeoutFilterLast - "last" mode: re-arm on every input; output the latest value if no further -// input arrives within time_period_. Self-keyed scheduler.set_timeout(this, ...) cancels and -// replaces any pending arm in O(1). +// input arrives within time_period_. Self-keyed scheduler.set_timeout(this, ...) cancels any +// pending arm with the same self-key and installs a new one. optional TimeoutFilterLast::new_value(float value) { this->pending_value_ = value; App.scheduler.set_timeout(this, this->time_period_, [this]() { this->output(this->pending_value_); });