mirror of
https://github.com/esphome/esphome.git
synced 2025-09-07 05:42:20 +01:00
preen
This commit is contained in:
@@ -14,7 +14,7 @@ namespace esphome {
|
|||||||
|
|
||||||
static const char *const TAG = "scheduler";
|
static const char *const TAG = "scheduler";
|
||||||
|
|
||||||
static const uint32_t MAX_LOGICALLY_DELETED_ITEMS = 10;
|
static const uint32_t MAX_LOGICALLY_DELETED_ITEMS = 6;
|
||||||
// Half the 32-bit range - used to detect rollovers vs normal time progression
|
// Half the 32-bit range - used to detect rollovers vs normal time progression
|
||||||
static constexpr uint32_t HALF_MAX_UINT32 = std::numeric_limits<uint32_t>::max() / 2;
|
static constexpr uint32_t HALF_MAX_UINT32 = std::numeric_limits<uint32_t>::max() / 2;
|
||||||
// max delay to start an interval sequence
|
// max delay to start an interval sequence
|
||||||
@@ -765,12 +765,12 @@ void Scheduler::recycle_item_(std::unique_ptr<SchedulerItem> item) {
|
|||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Pool size of 8 is a balance between memory usage and performance:
|
// Pool size of 10 is a balance between memory usage and performance:
|
||||||
// - Small enough to not waste memory on simple configs (1-2 timers)
|
// - Small enough to not waste memory on simple configs (1-2 timers)
|
||||||
// - Large enough to handle complex setups with multiple sensors/components
|
// - Large enough to handle complex setups with multiple sensors/components
|
||||||
// - Prevents system-wide stalls from heap allocation/deallocation that can
|
// - Prevents system-wide stalls from heap allocation/deallocation that can
|
||||||
// disrupt task synchronization and cause dropped events
|
// disrupt task synchronization and cause dropped events
|
||||||
static constexpr size_t MAX_POOL_SIZE = 8;
|
static constexpr size_t MAX_POOL_SIZE = 10;
|
||||||
if (this->scheduler_item_pool_.size() < MAX_POOL_SIZE) {
|
if (this->scheduler_item_pool_.size() < MAX_POOL_SIZE) {
|
||||||
// Clear callback to release captured resources
|
// Clear callback to release captured resources
|
||||||
item->callback = nullptr;
|
item->callback = nullptr;
|
||||||
|
@@ -325,7 +325,7 @@ class Scheduler {
|
|||||||
// Memory pool for recycling SchedulerItem objects to reduce heap churn.
|
// Memory pool for recycling SchedulerItem objects to reduce heap churn.
|
||||||
// Design decisions:
|
// Design decisions:
|
||||||
// - std::vector is used instead of a fixed array because many systems only need 1-2 scheduler items
|
// - std::vector is used instead of a fixed array because many systems only need 1-2 scheduler items
|
||||||
// - The vector grows dynamically up to MAX_POOL_SIZE (8) only when needed, saving memory on simple setups
|
// - The vector grows dynamically up to MAX_POOL_SIZE (10) only when needed, saving memory on simple setups
|
||||||
// - This approach balances memory efficiency for simple configs with performance for complex ones
|
// - This approach balances memory efficiency for simple configs with performance for complex ones
|
||||||
// - The pool significantly reduces heap fragmentation which is critical because heap allocation/deallocation
|
// - The pool significantly reduces heap fragmentation which is critical because heap allocation/deallocation
|
||||||
// can stall the entire system, causing timing issues and dropped events for any components that need
|
// can stall the entire system, causing timing issues and dropped events for any components that need
|
||||||
|
Reference in New Issue
Block a user