1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-26 20:53:50 +00:00

Optimize memory usage by lazy-allocating raw callbacks in sensors (#9077)

This commit is contained in:
J. Nick Koston
2025-06-14 22:28:15 -05:00
committed by GitHub
parent 4305c44440
commit cb019fff9a
4 changed files with 23 additions and 8 deletions

View File

@@ -7,6 +7,7 @@
#include "esphome/components/sensor/filter.h"
#include <vector>
#include <memory>
namespace esphome {
namespace sensor {
@@ -149,8 +150,8 @@ class Sensor : public EntityBase, public EntityBase_DeviceClass, public EntityBa
void internal_send_state_to_frontend(float state);
protected:
CallbackManager<void(float)> raw_callback_; ///< Storage for raw state callbacks.
CallbackManager<void(float)> callback_; ///< Storage for filtered state callbacks.
std::unique_ptr<CallbackManager<void(float)>> raw_callback_; ///< Storage for raw state callbacks (lazy allocated).
CallbackManager<void(float)> callback_; ///< Storage for filtered state callbacks.
Filter *filter_list_{nullptr}; ///< Store all active filters.