mirror of
https://github.com/esphome/esphome.git
synced 2026-03-02 10:48:22 -07:00
Reduce SerializationBuffer stack size from 768 to 512 bytes
768 bytes on the httpd task stack contributes to stack overflow when combined with other stack-allocated buffers (query string parsing, etc.). 512 bytes still covers all typical JSON payloads (sensors ~200B, lights ~170B, climate ~500-700B). Only extreme edge cases with 40+ options trigger heap fallback.
This commit is contained in:
@@ -70,7 +70,7 @@ SerializationBuffer<> JsonBuilder::serialize() {
|
||||
// directly in the caller's stack frame, eliminating the move constructor call entirely.
|
||||
//
|
||||
// WITHOUT NRVO: Each return would trigger SerializationBuffer's move constructor, which
|
||||
// must memcpy up to 768 bytes of stack buffer content. This happens on EVERY JSON
|
||||
// must memcpy up to 512 bytes of stack buffer content. This happens on EVERY JSON
|
||||
// serialization (sensor updates, web server responses, MQTT publishes, etc.).
|
||||
//
|
||||
// WITH NRVO: Zero memcpy, zero move constructor overhead. The buffer lives directly
|
||||
@@ -89,7 +89,7 @@ SerializationBuffer<> JsonBuilder::serialize() {
|
||||
// Should show only destructor, NOT move constructor
|
||||
//
|
||||
// Why we avoid measureJson(): It instantiates DummyWriter templates adding ~1KB flash.
|
||||
// Instead, try stack buffer first. 768 bytes covers 99.9% of JSON payloads (sensors ~200B,
|
||||
// Instead, 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.
|
||||
//
|
||||
// ===========================================================================================
|
||||
|
||||
Reference in New Issue
Block a user