mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 16:04:55 +00:00
982998c8fbdc7b76079d07153574619f7feec275
The scheduler was already managing SchedulerItem lifecycle explicitly through its object pool (recycle_item_main_loop_ / get_item_from_pool_locked_). The unique_ptr wrapper added overhead (11 destructor call sites on the hot path) without providing safety — if a lifecycle path was missed, the unique_ptr would silently delete the item and cause needless heap allocations instead of pool reuse. Replace unique_ptr<SchedulerItem, SchedulerItemDeleter> with raw SchedulerItem* throughout. Every item is now explicitly recycled to the pool or deleted via delete_item_(). This eliminates all 11 unique_ptr destructor calls from the hot path and saves ~256 bytes of firmware. Add debug leak detection under ESPHOME_DEBUG_SCHEDULER: a live-item counter verified at the end of every call() cycle asserts that all allocated items are accounted for in items_, to_add_, defer_queue_, or the pool. This turns silent heap churn from missed lifecycle management into an immediate assert failure caught by integration tests. Also moves the retry-cancelled check before item allocation in set_timer_common_ to avoid needless alloc+delete on the cold retry path, and fixes a thread-safety issue where recycle_item_main_loop_ (main-loop-only) was called from set_timer_common_ which can run on non-main-loop threads. Enable debug_scheduler: true in all 18 scheduler integration test fixtures.
Description
ESPHome is a system to control your ESP8266/ESP32 by simple yet powerful configuration files and control them remotely through Home Automation systems.
Readme
Multiple Licenses
393 MiB
Languages
C++
60.7%
Python
38.9%
C
0.3%
