mirror of
https://github.com/esphome/esphome.git
synced 2026-03-01 18:34:21 -07:00
[json] Increase SerializationBuffer stack size from 512 to 640 bytes
The reduction from 768 to 512 was overly aggressive - the stack overflow was caused by the 1400+ byte multipart parser, not the serialization buffer. 640 bytes covers climate DETAIL_ALL payloads (~520 bytes) on the stack without heap fallback.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user