J. Nick Koston
4b3091b01d
[scheduler] Inline delete instead of delete_item_ wrapper
...
A single-line wrapper around delete adds no value.
2026-03-08 00:16:21 -10:00
J. Nick Koston
982998c8fb
[scheduler] Replace unique_ptr with raw pointers, add leak detection
...
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.
2026-03-08 00:08:22 -10:00
J. Nick Koston and Claude Opus 4.6
1c5fd8bbd4
[core] Move millis_64 rollover tracking out of Scheduler ( #14360 )
...
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com >
2026-03-02 06:56:51 -10:00
J. Nick Koston and Claude Opus 4.6
280f874edc
[rp2040] Use native time_us_64() for millis_64() ( #14356 )
...
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-27 11:18:02 -10:00
J. Nick Koston and Claude Opus 4.6
63e757807e
[zephyr] Use native k_uptime_get() for millis_64() ( #14350 )
...
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-27 10:01:09 -10:00
J. Nick Koston and Claude Opus 4.6
8698b01bc7
[host] Use native clock_gettime for millis_64() ( #14340 )
...
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-27 18:54:13 +00:00
J. Nick Koston
1c7f769ec7
[core] Add millis_64() HAL function with native ESP32 implementation ( #14339 )
2026-02-27 07:48:21 -10:00
J. Nick Koston and pre-commit-ci-lite[bot]
2ff876c629
[core] Use custom deleter for SchedulerItem unique_ptr to prevent destructor inlining ( #14258 )
...
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
2026-02-25 13:18:44 +13:00
J. Nick Koston
08dc487b5b
[core] Pass std::function by rvalue reference in scheduler ( #14260 )
2026-02-25 13:08:07 +13:00
J. Nick Koston
a468261523
[scheduler] De-template and consolidate scheduler helper functions ( #14164 )
2026-02-21 19:41:26 -06:00
J. Nick Koston
462ac29563
[scheduler] Use relaxed memory ordering for atomic reads under lock ( #14140 )
2026-02-21 17:29:41 -06:00
J. Nick Koston
6f198adb0c
[scheduler] Reduce lock acquisitions in process_defer_queue_ ( #14107 )
2026-02-21 14:29:50 -06:00
J. Nick Koston
abe37c9841
[uptime] Use scheduler millis_64() for rollover-safe uptime tracking ( #14170 )
2026-02-21 03:08:49 +00:00
J. Nick Koston
dff9780d3a
[core] Use constexpr for compile-time constants ( #14071 )
2026-02-19 03:19:48 +00:00
J. Nick Koston
38bba3f5a2
[scheduler] Reduce set_timer_common_ hot path size by 25% ( #13899 )
2026-02-11 16:42:13 +13:00
J. Nick Koston and Jonathan Swoboda
e0712cc53b
[scheduler] Make core timer ID collisions impossible with type-safe internal IDs ( #13882 )
...
Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com >
2026-02-09 13:16:22 -06:00
J. Nick Koston
2383b6b8b4
[core] Deprecate set_retry, cancel_retry, and RetryResult ( #13845 )
2026-02-09 12:05:32 -06:00
J. Nick Koston
248fc06dac
[scheduler] Eliminate heap allocation in full_cleanup_removed_items_ ( #13837 )
2026-02-09 08:44:20 -06:00
J. Nick Koston
d5f557ad1c
[scheduler] Eliminate heap allocations for std::string names and add uint32_t ID API ( #13200 )
2026-01-14 09:15:31 -05:00
J. Nick Koston
3d74d1e7f0
[libretiny] Regenerate boards, enable Cortex-M4 atomics, and consolidate platform code ( #13191 )
2026-01-13 21:39:11 +00:00
J. Nick Koston
861ed8dd41
[scheduler] Avoid std::string allocation in RetryArgs ( #12311 )
2025-12-09 09:27:12 -05:00
J. Nick Koston
05826d5ead
[scheduler] Fix missing lock when recycling items in defer queue processing ( #12343 )
2025-12-07 13:30:22 -06:00
J. Nick Koston
80e881655f
[scheduler] Fix use-after-free when cancelling timeouts from non-main-loop threads ( #12288 )
2025-12-04 19:14:22 -06:00
J. Nick Koston
1fadd1227d
[scheduler] Fix use-after-move crash in heap operations ( #12124 )
2025-11-27 10:50:21 -06:00
J. Nick Koston
1888f5ffd5
[scheduler] Add defensive nullptr checks and explicit locking requirements ( #11974 )
2025-11-18 18:16:18 +00:00
J. Nick Koston
fc546ca3f6
[scheduler] Fix timing breakage after 49 days of uptime on ESP8266/RP2040 ( #11924 )
2025-11-15 22:20:57 -06:00
J. Nick Koston
df53ff7afe
[scheduler] Extract helper functions to improve code readability ( #11730 )
2025-11-06 07:13:12 +13:00
J. Nick Koston
4a5e6576c8
[scheduler] Refactor call() for improved code organization ( #11643 )
2025-11-03 14:29:29 +13:00
J. Nick Koston
f25af18655
[scheduler] Replace defer queue deque with vector to avoid 512-byte upfront allocation ( #11305 )
2025-10-20 07:34:34 +13:00
J. Nick Koston
e2c5eeef97
[scheduler] Deduplicate item removal code with template helper ( #11017 )
2025-10-05 16:32:51 -05:00
J. Nick Koston
ac07a00141
[scheduler] Fix timing accumulation in scheduler causing incorrect execution measurements ( #10719 )
2025-09-14 22:05:56 +00:00
J. Nick Koston
5cc0e21bc7
[core] Reduce unnecessary nesting in scheduler loop ( #10644 )
2025-09-09 09:04:07 +12:00
J. Nick Koston
8d90f13e97
[core] Store component source strings in flash on ESP8266 (breaking change) ( #10621 )
2025-09-07 20:10:00 -05:00
J. Nick Koston and Copilot
166ad942ef
[scheduler] Reduce SchedulerItem memory usage by 7.4% on 32-bit platforms ( #10553 )
...
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com >
2025-09-07 18:51:07 -05:00
J. Nick Koston
28d16728d3
[core] Add memory pool to scheduler to reduce heap fragmentation ( #10536 )
2025-09-08 10:27:58 +12:00
J. Nick Koston and Copilot
b25506b045
[core] Skip redundant process_to_add() call when no scheduler items added ( #10630 )
...
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com >
2025-09-08 09:10:55 +12:00
J. Nick Koston
61a5023888
[script] Fix parallel mode scripts with delays cancelling each other ( #10324 )
2025-08-25 08:49:52 +12:00
J. Nick Koston
6818439109
[core] Fix scheduler race condition where cancelled items still execute ( #10268 )
2025-08-18 11:14:41 -04:00
J. Nick Koston
85435e6b5f
[scheduler] Eliminate more runtime string allocations from retry ( #9930 )
2025-07-29 08:54:16 +12:00
Clyde Stubbs
2b87589562
[scheduler] Fix null pointer crash ( #9893 )
2025-07-25 09:12:33 -10:00
J. Nick Koston
88ccde4ba1
[scheduler] Fix retry race condition on cancellation ( #9788 )
2025-07-25 08:14:15 -10:00
J. Nick Koston
1344103086
[core] Revert #9851 and rename ESPHOME_CORES to ESPHOME_THREAD ( #9862 )
2025-07-24 11:04:00 +00:00
Clyde Stubbs
f9534fbd5d
[interval] Fix startup behaviour ( #9793 )
2025-07-24 08:03:36 +10:00
J. Nick Koston
ecd310dae1
[core] Refactor scheduler to eliminate hidden side effects in empty_ ( #9743 )
2025-07-20 23:11:30 +00:00
@RubenKelevra and J. Nick Koston
6e31fb181e
core/scheduler: Make millis_64_ rollover monotonic on SMP ( #9716 )
...
Co-authored-by: J. Nick Koston <nick@koston.org >
2025-07-20 21:57:52 +00:00
J. Nick Koston
a18ddd1169
[scheduler] Fix LibreTiny compilation error due to missing atomic operations ( #9643 )
2025-07-18 14:21:46 +12:00
J. Nick Koston
158a3b2835
[scheduler] Fix cancellation of timers with empty string names ( #9641 )
2025-07-18 14:20:35 +12:00
J. Nick Koston
dfa8c8c77f
Fix scheduler rollover detection with concurrent task calls ( #9624 )
2025-07-17 13:07:36 -10:00
J. Nick Koston
b1c86fe30e
Optimize scheduler timing by reducing millis() calls ( #9524 )
2025-07-16 13:41:55 +12:00
J. Nick Koston
bef20b60d0
Fix scheduler crash when cancelling items with NULL names ( #9444 )
2025-07-12 07:11:45 +12:00