Move millis_64() call inside non-defer path

defer() items go straight into defer_queue_ and never use a timestamp.
Now that millis_64() has its own lock separate from the scheduler,
the call no longer needs to happen before taking the scheduler lock.
Move it inside the non-defer branch so defer() avoids the cost entirely.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
J. Nick Koston
2026-02-27 10:56:29 -10:00
co-authored by Claude Opus 4.6
parent 6c8542026f
commit c121d8dc2a
+3 -3
View File
@@ -147,9 +147,6 @@ void HOT Scheduler::set_timer_common_(Component *component, SchedulerItem::Type
return;
}
// Get fresh 64-bit timestamp BEFORE taking lock
const uint64_t now_64 = millis_64();
// Take lock early to protect scheduler_item_pool_ access
LockGuard guard{this->lock_};
@@ -176,6 +173,9 @@ void HOT Scheduler::set_timer_common_(Component *component, SchedulerItem::Type
} else
#endif /* not ESPHOME_THREAD_SINGLE */
{
// Only non-defer items need a timestamp for scheduling
const uint64_t now_64 = millis_64();
// Type-specific setup
if (type == SchedulerItem::INTERVAL) {
item->interval = delay;