From cfd43c81fb81b398f4c8a4f2b88b215318babb6e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 6 Jul 2025 21:30:39 -0500 Subject: [PATCH 1/2] clarify what we know --- esphome/core/scheduler.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/esphome/core/scheduler.cpp b/esphome/core/scheduler.cpp index f67b3d7198..7e2b2741a8 100644 --- a/esphome/core/scheduler.cpp +++ b/esphome/core/scheduler.cpp @@ -398,7 +398,9 @@ void HOT Scheduler::cleanup_() { // Reading to_remove_ without lock is safe because: // 1. We only call this from the main thread during call() // 2. If it's 0, there's definitely nothing to cleanup - // 3. If it becomes non-zero after we check, cleanup will happen next time + // 3. If it becomes non-zero after we check, cleanup will happen on the next loop iteration + // 4. Not all platforms support atomics, so we accept this race in favor of performance + // 5. The worst case is a one-loop-iteration delay in cleanup, which is harmless if (this->to_remove_ == 0) return; From f23fd52a261db2a11c650ea2e3d10adf13ec9268 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 6 Jul 2025 21:31:39 -0500 Subject: [PATCH 2/2] clarify what we know --- esphome/core/scheduler.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/esphome/core/scheduler.h b/esphome/core/scheduler.h index 7e16f66423..abf52f5c13 100644 --- a/esphome/core/scheduler.h +++ b/esphome/core/scheduler.h @@ -163,7 +163,10 @@ class Scheduler { if (item_name == nullptr) { return false; } - // Fast path: if pointers are equal (common with string deduplication) + // Fast path: if pointers are equal + // This is effective because the core ESPHome codebase uses static strings (const char*) + // for component names. The std::string overloads exist only for compatibility with + // external components, but are rarely used in practice. if (item_name == name_cstr) { return true; }