From 769d4e444440bdea96b4cd293b597c313b3e56bf Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 9 Feb 2026 06:07:49 -0600 Subject: [PATCH] [scheduler] Inline InternalSchedulerID overloads to eliminate code size overhead Move the 4 Scheduler InternalSchedulerID methods from .cpp to inline in the header. They're trivial one-liners that extract .id and forward to set_timer_common_/cancel_item_, so the compiler can fold them into call sites instead of emitting separate function bodies. --- esphome/core/scheduler.cpp | 16 ---------------- esphome/core/scheduler.h | 18 ++++++++++++++---- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/esphome/core/scheduler.cpp b/esphome/core/scheduler.cpp index 173d0817c9..513547c487 100644 --- a/esphome/core/scheduler.cpp +++ b/esphome/core/scheduler.cpp @@ -224,11 +224,6 @@ void HOT Scheduler::set_timeout(Component *component, uint32_t id, uint32_t time this->set_timer_common_(component, SchedulerItem::TIMEOUT, NameType::NUMERIC_ID, nullptr, id, timeout, std::move(func)); } -void HOT Scheduler::set_timeout(Component *component, InternalSchedulerID id, uint32_t timeout, - std::function func) { - this->set_timer_common_(component, SchedulerItem::TIMEOUT, NameType::NUMERIC_ID_INTERNAL, nullptr, id.id, timeout, - std::move(func)); -} bool HOT Scheduler::cancel_timeout(Component *component, const std::string &name) { return this->cancel_item_(component, NameType::HASHED_STRING, nullptr, fnv1a_hash(name), SchedulerItem::TIMEOUT); } @@ -238,9 +233,6 @@ bool HOT Scheduler::cancel_timeout(Component *component, const char *name) { bool HOT Scheduler::cancel_timeout(Component *component, uint32_t id) { return this->cancel_item_(component, NameType::NUMERIC_ID, nullptr, id, SchedulerItem::TIMEOUT); } -bool HOT Scheduler::cancel_timeout(Component *component, InternalSchedulerID id) { - return this->cancel_item_(component, NameType::NUMERIC_ID_INTERNAL, nullptr, id.id, SchedulerItem::TIMEOUT); -} void HOT Scheduler::set_interval(Component *component, const std::string &name, uint32_t interval, std::function func) { this->set_timer_common_(component, SchedulerItem::INTERVAL, NameType::HASHED_STRING, nullptr, fnv1a_hash(name), @@ -256,11 +248,6 @@ void HOT Scheduler::set_interval(Component *component, uint32_t id, uint32_t int this->set_timer_common_(component, SchedulerItem::INTERVAL, NameType::NUMERIC_ID, nullptr, id, interval, std::move(func)); } -void HOT Scheduler::set_interval(Component *component, InternalSchedulerID id, uint32_t interval, - std::function func) { - this->set_timer_common_(component, SchedulerItem::INTERVAL, NameType::NUMERIC_ID_INTERNAL, nullptr, id.id, interval, - std::move(func)); -} bool HOT Scheduler::cancel_interval(Component *component, const std::string &name) { return this->cancel_item_(component, NameType::HASHED_STRING, nullptr, fnv1a_hash(name), SchedulerItem::INTERVAL); } @@ -270,9 +257,6 @@ bool HOT Scheduler::cancel_interval(Component *component, const char *name) { bool HOT Scheduler::cancel_interval(Component *component, uint32_t id) { return this->cancel_item_(component, NameType::NUMERIC_ID, nullptr, id, SchedulerItem::INTERVAL); } -bool HOT Scheduler::cancel_interval(Component *component, InternalSchedulerID id) { - return this->cancel_item_(component, NameType::NUMERIC_ID_INTERNAL, nullptr, id.id, SchedulerItem::INTERVAL); -} struct RetryArgs { // Ordered to minimize padding on 32-bit systems diff --git a/esphome/core/scheduler.h b/esphome/core/scheduler.h index 8ab8adca49..ed26eff27d 100644 --- a/esphome/core/scheduler.h +++ b/esphome/core/scheduler.h @@ -47,13 +47,18 @@ class Scheduler { /// Set a timeout with a numeric ID (zero heap allocation) void set_timeout(Component *component, uint32_t id, uint32_t timeout, std::function func); /// Set a timeout with an internal scheduler ID (separate namespace from component NUMERIC_ID) - void set_timeout(Component *component, InternalSchedulerID id, uint32_t timeout, std::function func); + void set_timeout(Component *component, InternalSchedulerID id, uint32_t timeout, std::function func) { + this->set_timer_common_(component, SchedulerItem::TIMEOUT, NameType::NUMERIC_ID_INTERNAL, nullptr, id.id, timeout, + std::move(func)); + } ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") bool cancel_timeout(Component *component, const std::string &name); bool cancel_timeout(Component *component, const char *name); bool cancel_timeout(Component *component, uint32_t id); - bool cancel_timeout(Component *component, InternalSchedulerID id); + bool cancel_timeout(Component *component, InternalSchedulerID id) { + return this->cancel_item_(component, NameType::NUMERIC_ID_INTERNAL, nullptr, id.id, SchedulerItem::TIMEOUT); + } ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_interval(Component *component, const std::string &name, uint32_t interval, std::function func); @@ -70,13 +75,18 @@ class Scheduler { /// Set an interval with a numeric ID (zero heap allocation) void set_interval(Component *component, uint32_t id, uint32_t interval, std::function func); /// Set an interval with an internal scheduler ID (separate namespace from component NUMERIC_ID) - void set_interval(Component *component, InternalSchedulerID id, uint32_t interval, std::function func); + void set_interval(Component *component, InternalSchedulerID id, uint32_t interval, std::function func) { + this->set_timer_common_(component, SchedulerItem::INTERVAL, NameType::NUMERIC_ID_INTERNAL, nullptr, id.id, interval, + std::move(func)); + } ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") bool cancel_interval(Component *component, const std::string &name); bool cancel_interval(Component *component, const char *name); bool cancel_interval(Component *component, uint32_t id); - bool cancel_interval(Component *component, InternalSchedulerID id); + bool cancel_interval(Component *component, InternalSchedulerID id) { + return this->cancel_item_(component, NameType::NUMERIC_ID_INTERNAL, nullptr, id.id, SchedulerItem::INTERVAL); + } ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_retry(Component *component, const std::string &name, uint32_t initial_wait_time, uint8_t max_attempts,