From dc8f2fd37e23b340fad0cb15b59d3454250a1b74 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 5 Jul 2025 22:15:45 -0500 Subject: [PATCH] Eliminate bluetooth_proxy guard variable to save 8 bytes RAM --- esphome/components/bluetooth_proxy/bluetooth_proxy.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp b/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp index fbe2a3e67c..0b25b64e3f 100644 --- a/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp +++ b/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp @@ -53,10 +53,12 @@ bool BluetoothProxy::parse_device(const esp32_ble_tracker::ESPBTDevice &device) } static constexpr size_t FLUSH_BATCH_SIZE = 8; -static std::vector &get_batch_buffer() { - static std::vector batch_buffer; - return batch_buffer; -} + +// Global batch buffer to avoid guard variable (saves 8 bytes) +// This is initialized at program startup before any threads +static std::vector batch_buffer; + +static std::vector &get_batch_buffer() { return batch_buffer; } bool BluetoothProxy::parse_devices(const esp32_ble::BLEScanResult *scan_results, size_t count) { if (!api::global_api_server->is_connected() || this->api_connection_ == nullptr || !this->raw_advertisements_)