mirror of
https://github.com/esphome/esphome.git
synced 2026-03-01 02:14:19 -07:00
[json] Document heap fallback buffer sizing expectations
Payloads exceeding 1024 bytes are not known to exist in real configurations. One doubling iteration covers all known entity types. Cap at 4096 as a safety limit.
This commit is contained in:
@@ -120,7 +120,9 @@ SerializationBuffer<> JsonBuilder::serialize() {
|
||||
}
|
||||
|
||||
// Payload exceeded stack buffer. Double the buffer and retry until it fits.
|
||||
// Cap at 4096 to prevent runaway allocation on memory-constrained devices.
|
||||
// In practice, one iteration (1024 bytes) covers all known entity types.
|
||||
// Payloads exceeding 1024 bytes are not known to exist in real configurations.
|
||||
// Cap at 4096 as a safety limit to prevent runaway allocation.
|
||||
size_t heap_size = buf_size * 2;
|
||||
while (heap_size <= 4096) {
|
||||
result.reallocate_heap_(heap_size - 1);
|
||||
|
||||
Reference in New Issue
Block a user