mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 17:05:36 +00:00
da926d904e
Extend the precomputed-tag approach from fixed32 key fields to all forced fields with single-byte tags (field IDs 1-15). The code generator now emits write_raw_byte(tag) followed by the raw encode primitive instead of calling the full encode_* method. For varint types (uint32, uint64, sint32, sint64, int64, bool, enum), this eliminates the zero-check branch and encode_field_raw indirection. For length-delimited types (bytes, string), it additionally skips the encode_string wrapper. Benchmarked on real hardware with BluetoothLERawAdvertisementsResponse (12 advertisements per message, 10000 iterations): ESP32 (Xtensa dual-core 240MHz): encode: 38498 -> 30460 ns/op (-20.9%) calc+encode: 48479 -> 40458 ns/op (-16.6%) ESP32-C3 (RISC-V single-core 160MHz): encode: 54199 -> 40342 ns/op (-25.6%) calc+encode: 57800 -> 51365 ns/op (-11.1%)