From b8b219926d182ee90f9621401dc1aea3b42c5ce6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 7 Mar 2026 08:01:08 -1000 Subject: [PATCH] [core] Skip zero-initialization of StaticVector data array Remove value-initialization ({}) from StaticVector's underlying std::array. Only elements [0, count_) are ever accessed, so initializing the full array is wasted work. This eliminates a memset on every construction. Most impactful for stack-allocated StaticVectors in hot paths like APIPlaintextFrameHelper::write_protobuf_messages, which was memsetting 276 bytes of iovec storage on every BLE proxy flush. --- esphome/core/helpers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index 6ce5de4975..11e0afe526 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -215,7 +215,7 @@ template class StaticVector { using const_reverse_iterator = std::reverse_iterator; private: - std::array data_{}; + std::array data_; // intentionally not value-initialized to avoid memset size_t count_{0}; public: