From 49ef5f9ad6a50457b44125558144f013bc3c64fd Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 9 Apr 2026 22:07:15 -1000 Subject: [PATCH] [api] Force inline encode_varint_raw_loop so pos stays in a register --- esphome/components/api/proto.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 8c233e8e09c..cdebbcafa73 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -304,7 +304,8 @@ class ProtoEncode { /// data-dependent back-edge branch, which measurably speeds up BLE raw /// advertisement MAC encoding (always 7-byte varints) among other hot paths. template - static inline void encode_varint_raw_loop(uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, T value) { + static inline void ESPHOME_ALWAYS_INLINE encode_varint_raw_loop(uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, + T value) { constexpr int MAX_VARINT_BYTES = (sizeof(T) * 8 + 6) / 7; // 5 for u32, 10 for u64 #pragma GCC unroll 10 for (int i = 0; i < MAX_VARINT_BYTES - 1; i++) {