From c17fdd91dee5475f80a0b8140dd0dd4e723b4e82 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 17 Jul 2025 10:23:00 -1000 Subject: [PATCH] commit overreserve fix --- esphome/components/bluetooth_proxy/bluetooth_proxy.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp b/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp index bb789347af..c22788de66 100644 --- a/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp +++ b/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp @@ -43,10 +43,11 @@ void BluetoothProxy::setup() { this->response_ = std::make_unique(); // Reserve capacity but start with size 0 - this->response_->advertisements.reserve(FLUSH_BATCH_SIZE); + // Reserve 50% since we'll grow naturally and flush at FLUSH_BATCH_SIZE + this->response_->advertisements.reserve(FLUSH_BATCH_SIZE / 2); - // Pre-allocate pool for overflow - this->advertisement_pool_.reserve(FLUSH_BATCH_SIZE); + // Don't pre-allocate pool - let it grow only if needed in busy environments + // Many devices in quiet areas will never need the overflow pool this->parent_->add_scanner_state_callback([this](esp32_ble_tracker::ScannerState state) { if (this->api_connection_ != nullptr) {