mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 13:24:58 +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.
49 lines
1.1 KiB
YAML
49 lines
1.1 KiB
YAML
esphome:
|
|
debug_scheduler: true # Enable scheduler leak detection
|
|
name: scheduler-string-lifetime-test
|
|
|
|
external_components:
|
|
- source:
|
|
type: local
|
|
path: EXTERNAL_COMPONENT_PATH
|
|
components: [scheduler_string_lifetime_component]
|
|
|
|
host:
|
|
|
|
logger:
|
|
level: DEBUG
|
|
|
|
scheduler_string_lifetime_component:
|
|
id: string_lifetime
|
|
|
|
api:
|
|
services:
|
|
- service: run_string_lifetime_test
|
|
then:
|
|
- lambda: |-
|
|
id(string_lifetime)->run_string_lifetime_test();
|
|
- service: run_test1
|
|
then:
|
|
- lambda: |-
|
|
id(string_lifetime)->run_test1();
|
|
- service: run_test2
|
|
then:
|
|
- lambda: |-
|
|
id(string_lifetime)->run_test2();
|
|
- service: run_test3
|
|
then:
|
|
- lambda: |-
|
|
id(string_lifetime)->run_test3();
|
|
- service: run_test4
|
|
then:
|
|
- lambda: |-
|
|
id(string_lifetime)->run_test4();
|
|
- service: run_test5
|
|
then:
|
|
- lambda: |-
|
|
id(string_lifetime)->run_test5();
|
|
- service: run_final_check
|
|
then:
|
|
- lambda: |-
|
|
id(string_lifetime)->run_final_check();
|