mirror of
https://github.com/esphome/esphome.git
synced 2026-09-11 15:27:33 +00:00
The ProtoEncode helpers took the write cursor by reference and a bool force flag. At -Os the compiler outlines most of them, so every call site had to keep pos in a stack slot and pass its address, plus a constant for the flag. The helpers now take the cursor by value and return the advanced cursor, so consecutive calls chain through the return register; forced fields call a _force overload instead of passing a flag. The fixed32 writers use __builtin_memcpy, which stays a builtin under ESP-IDF's -fno-builtin-memcpy, and are outlined on embedded targets so each fixed32 or float field is a short call instead of an inline memcpy call. Non-forced float and fixed32 fields with a single-byte tag share the same writer behind a zero check. Generated encode bodies shrink by 18 percent on an ESP32 IDF proxy build (2360 to 1932 bytes for 27 messages); entity messages gain the most, for example ListEntitiesSensorResponse::encode 190 to 134 bytes and SensorStateResponse::encode 78 to 49 bytes.