1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-05 11:23:47 +01:00

Pre-reserve looping components vector to reduce memory allocations

This commit is contained in:
J. Nick Koston
2025-06-22 22:56:31 +02:00
parent 788803d588
commit 13d53590b2

View File

@@ -257,6 +257,17 @@ void Application::teardown_components(uint32_t timeout_ms) {
}
void Application::calculate_looping_components_() {
// Count total components that need looping
size_t total_looping = 0;
for (auto *obj : this->components_) {
if (obj->has_overridden_loop()) {
total_looping++;
}
}
// Pre-reserve vector to avoid reallocations
this->looping_components_.reserve(total_looping);
// First add all active components
for (auto *obj : this->components_) {
if (obj->has_overridden_loop() &&