mirror of
https://github.com/esphome/esphome.git
synced 2026-09-17 18:18:43 +00:00
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.
40 lines
787 B
YAML
40 lines
787 B
YAML
esphome:
|
|
debug_scheduler: true # Enable scheduler leak detection
|
|
name: sched-recursive-timeout
|
|
|
|
external_components:
|
|
- source:
|
|
type: local
|
|
path: EXTERNAL_COMPONENT_PATH
|
|
components: [scheduler_recursive_timeout_component]
|
|
|
|
host:
|
|
|
|
logger:
|
|
level: VERBOSE
|
|
|
|
scheduler_recursive_timeout_component:
|
|
id: recursive_timeout
|
|
|
|
api:
|
|
services:
|
|
- service: run_recursive_timeout_test
|
|
then:
|
|
- lambda: |-
|
|
id(recursive_timeout)->run_recursive_timeout_test();
|
|
|
|
event:
|
|
- platform: template
|
|
name: "Test Complete"
|
|
id: test_complete
|
|
device_class: button
|
|
event_types:
|
|
- "test_finished"
|
|
- platform: template
|
|
name: "Test Result"
|
|
id: test_result
|
|
device_class: button
|
|
event_types:
|
|
- "passed"
|
|
- "failed"
|