[core] Replace scheduler pool vector with unbounded intrusive freelist (#16172)

This commit is contained in:
J. Nick Koston
2026-05-05 18:26:19 -05:00
committed by GitHub
parent f30ad588ea
commit 39b2b901f7
6 changed files with 115 additions and 67 deletions
+7
View File
@@ -25,6 +25,10 @@ namespace esphome {
static const char *const TAG = "app";
// Delay after setup() finishes before trimming the scheduler freelist of its post-boot peak.
// 10 s is well past the bulk of post-setup async work (Wi-Fi/MQTT connects, first-read latency).
static constexpr uint32_t SCHEDULER_FREELIST_TRIM_DELAY_MS = 10000;
// Helper function for insertion sort of components by priority
// Using insertion sort instead of std::stable_sort saves ~1.3KB of flash
// by avoiding template instantiations (std::rotate, std::stable_sort, lambdas)
@@ -112,6 +116,9 @@ void Application::setup() {
ESP_LOGI(TAG, "setup() finished successfully!");
// Trim the scheduler freelist of its post-boot peak once startup churn settles.
this->scheduler.set_timeout(this, SCHEDULER_FREELIST_TRIM_DELAY_MS, [this]() { this->scheduler.trim_freelist(); });
#ifdef USE_SETUP_PRIORITY_OVERRIDE
// Clear setup priority overrides to free memory
clear_setup_priority_overrides();