From 244e672b0aee8c61cb8e4b7b585d0673d5905b82 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 7 Mar 2026 15:28:06 -1000 Subject: [PATCH] Revert force-inlining of calc_uint32 and calc_length The ESPHOME_ALWAYS_INLINE on these caused significant flash bloat in cold calculate_size() callers (DeviceInfoResponse +117B, HelloResponse +63B, ListEntitiesEventResponse +79B) while only benefiting the BLE hot path marginally. Let the compiler decide when to inline these. The varint() fast path remains force-inlined as that eliminates the most expensive indirect calls on the hot path. Co-Authored-By: Claude Opus 4.6 --- esphome/components/api/proto.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 33c72522200..2ac8dbd8447 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -609,7 +609,7 @@ class ProtoSize { static constexpr uint32_t calc_int32_force(uint32_t field_id_size, int32_t value) { return field_id_size + (value < 0 ? 10 : varint(static_cast(value))); } - static constexpr inline uint32_t ESPHOME_ALWAYS_INLINE calc_uint32(uint32_t field_id_size, uint32_t value) { + static constexpr uint32_t calc_uint32(uint32_t field_id_size, uint32_t value) { return value ? field_id_size + varint(value) : 0; } static constexpr uint32_t calc_uint32_force(uint32_t field_id_size, uint32_t value) { @@ -644,7 +644,7 @@ class ProtoSize { static constexpr uint32_t calc_uint64_force(uint32_t field_id_size, uint64_t value) { return field_id_size + varint(value); } - static constexpr inline uint32_t ESPHOME_ALWAYS_INLINE calc_length(uint32_t field_id_size, size_t len) { + static constexpr uint32_t calc_length(uint32_t field_id_size, size_t len) { return len ? field_id_size + varint(static_cast(len)) + static_cast(len) : 0; } static constexpr uint32_t calc_length_force(uint32_t field_id_size, size_t len) {