[bluetooth_proxy] Optimize memory usage with fixed-size array and const string references - #10015
Conversation
|
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#10015
components: [bluetooth_proxy, esp32_ble_client]
refresh: 1h(Added by the PR bot) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #10015 +/- ##
=======================================
Coverage 60.19% 60.19%
=======================================
Files 51 51
Lines 10305 10305
Branches 1368 1368
=======================================
Hits 6203 6203
Misses 3745 3745
Partials 357 357 ☔ View full re
8000
port in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…st string references
68ab351 to
20959c2
Compare
|
👋 Hi there! I've automatically requested reviews from codeowners based on the files changed in this PR. @jesserockz - You've been requested to review this PR as codeowner(s) of 3 file(s) that were modified. Thanks for your time! 🙏 |
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes memory usage in the bluetooth_proxy component by implementing two key changes to reduce both flash and RAM consumption. The optimization converts dynamic memory structures to more efficient alternatives while maintaining the same functionality.
- Changed
address_str()method to return const string reference instead of by value to eliminate unnecessary string copies - Replaced dynamic
std::vectorwith fixed-sizestd::arrayfor connection storage since the connection count is determined at compile time
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| esphome/components/esp32_ble_client/ble_client_base.h | Modified address_str() to return const reference for optimized string handling |
| esphome/components/bluetooth_proxy/bluetooth_proxy.h | Replaced std::vector with std::array and added connection counter for fixed-size storage |
| esphome/components/bluetooth_proxy/bluetooth_proxy.cpp | Updated connection iteration logic to use array indexing with connection counter |
What does this implement/fix?
This PR optimizes the
bluetooth_proxycomponent to reduce both flash and RAM usage:Optimize string handling in logging: Changed
address_str()method inBLEClientBaseto return a const reference instead of by value, eliminating unnecessary string copies during frequent logging operations.Replace dynamic vector with fixed array: Converted the
connections_vector to a fixed-sizestd::arraysince all connection objects are created at compile time and the count never changes. This eliminates:These optimizations result in:
Types of changes
Related issue or feature (if applicable):
BLUETOOTH_PROXY_MAX_CONNECTIONSdefine)Pull request in esphome-docs with documentation (if applicable):
Test Environment
Example entry for
config.yaml:Checklist:
tests/folder).If user exposed functionality or configuration variables are added/changed: