From 19e497cd6121845655d1df598c82dd61b483bc61 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 27 Mar 2026 16:58:49 -1000 Subject: [PATCH] Remove get_loop_component_start_time wrapper, use forward-declared App directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The wrapper added a function call indirection on every filter invocation that the compiler cannot inline without LTO. Forward-declaring Application and App lets the template body call App.get_loop_component_start_time() directly — the method is inline in application.h which is included by main.cpp where the template is instantiated. --- esphome/components/sensor/filter.cpp | 2 -- esphome/components/sensor/filter.h | 12 +++++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/esphome/components/sensor/filter.cpp b/esphome/components/sensor/filter.cpp index eef5c6cade..998f34be0f 100644 --- a/esphome/components/sensor/filter.cpp +++ b/esphome/components/sensor/filter.cpp @@ -222,8 +222,6 @@ MultiplyFilter::MultiplyFilter(TemplatableValue multiplier) : multiplier_ optional MultiplyFilter::new_value(float value) { return value * this->multiplier_.value(); } -uint32_t get_loop_component_start_time() { return App.get_loop_component_start_time(); } - // ValueListFilter helper (non-template, shared by all ValueListFilter instantiations) bool value_list_matches_any(Sensor *parent, float sensor_value, const TemplatableValue *values, size_t count) { int8_t accuracy = parent->get_accuracy_decimals(); diff --git a/esphome/components/sensor/filter.h b/esphome/components/sensor/filter.h index 87a309ffb3..db8156f544 100644 --- a/esphome/components/sensor/filter.h +++ b/esphome/components/sensor/filter.h @@ -332,8 +332,14 @@ class MultiplyFilter : public Filter { /// Non-template helper for value matching (implementation in filter.cpp) bool value_list_matches_any(Sensor *parent, float sensor_value, const TemplatableValue *values, size_t count); -/// Non-template helper to get cached loop start time (avoids circular include of application.h) -uint32_t get_loop_component_start_time(); +} // namespace esphome::sensor +// Forward declaration — avoids circular include of application.h. +// Template bodies are only instantiated in main.cpp where Application is fully defined. +namespace esphome { +class Application; +extern Application App; +} // namespace esphome +namespace esphome::sensor { /** Base class for filters that compare sensor values against a fixed list of configured values. * @@ -389,7 +395,7 @@ template class ThrottleWithPriorityFilter : public ValueListFilter : ValueListFilter(prioritized_values), min_time_between_inputs_(min_time_between_inputs) {} optional new_value(float value) override { - const uint32_t now = get_loop_component_start_time(); + const uint32_t now = App.get_loop_component_start_time(); if (this->last_input_ == 0 || now - this->last_input_ >= this->min_time_between_inputs_ || this->value_matches_any_(value)) { this->last_input_ = now;