diff --git a/esphome/components/json/json_util.cpp b/esphome/components/json/json_util.cpp index 8734d2e1e7..6ec4d657a1 100644 --- a/esphome/components/json/json_util.cpp +++ b/esphome/components/json/json_util.cpp @@ -88,15 +88,15 @@ SerializationBuffer<> JsonBuilder::serialize() { // - Test: objdump -d -C firmware.elf | grep "SerializationBuffer.*SerializationBuffer" // Should show only destructor, NOT move constructor // - // Try stack buffer first. 512 bytes covers 99.9% of JSON payloads (sensors ~200B, - // lights ~170B, climate ~700B). Only entities with 40+ options exceed this. + // Try stack buffer first. 640 bytes covers 99.9% of JSON payloads (sensors ~200B, + // lights ~170B, climate ~500-700B). Only entities with 40+ options exceed this. // // IMPORTANT: ArduinoJson's serializeJson() with a bounded buffer returns the actual // bytes written (truncated count), NOT the would-be size like snprintf(). When the // payload exceeds the buffer, the return value equals the buffer capacity. The heap // fallback doubles the buffer size until the payload fits. This avoids instantiating // measureJson()'s DummyWriter templates (~736 bytes flash) at the cost of temporarily - // over-allocating heap (at most 2x) for the rare payloads that exceed 512 bytes. + // over-allocating heap (at most 2x) for the rare payloads that exceed 640 bytes. // // =========================================================================================== constexpr size_t buf_size = SerializationBuffer<>::BUFFER_SIZE; diff --git a/esphome/components/json/json_util.h b/esphome/components/json/json_util.h index 3ea551bc8e..eb18e7a237 100644 --- a/esphome/components/json/json_util.h +++ b/esphome/components/json/json_util.h @@ -19,7 +19,7 @@ namespace json { /// Buffer for JSON serialization that uses stack allocation for small payloads. /// Template parameter STACK_SIZE specifies the stack buffer size (default 512 bytes). /// Supports move semantics for efficient return-by-value. -template class SerializationBuffer { +template class SerializationBuffer { public: static constexpr size_t BUFFER_SIZE = STACK_SIZE; ///< Stack buffer size for this instantiation