Commit Graph

543 Commits

Author SHA1 Message Date
J. Nick Koston 34c617f046 Merge branch 'proto-speed-log-response' into integration 2026-04-12 22:45:34 -10:00
J. Nick Koston 4bcf3b9661 fix existing bug 2026-04-12 22:44:02 -10:00
J. Nick Koston b4982b9bff Merge remote-tracking branch 'upstream/proto-speed-log-response' into integration 2026-04-12 21:50:41 -10:00
J. Nick Koston 1703602c0f Merge branch 'proto-speed-optimized-v2' into integration 2026-04-12 20:30:34 -10:00
pre-commit-ci-lite[bot] a463e25aa1 [pre-commit.ci lite] apply automatic fixes 2026-04-13 06:23:08 +00:00
J. Nick Koston 603d5a2b54 Fix clang-tidy NOLINT for optimize(O2) in generated protobuf code 2026-04-12 20:21:43 -10:00
J. Nick Koston 830af94b2c Merge branch 'app-loop-optimize-speed' into integration 2026-04-12 19:57:45 -10:00
J. Nick Koston e1ea9cb66b Revert "Merge branch 'benchmark-crypto-o2' into integration"
This reverts commit c58447ad3a, reversing
changes made to 3b02c6d5ef.
2026-04-12 19:26:54 -10:00
J. Nick Koston d217ab3cd4 [api] Add speed_optimized proto option for hot encode paths
Add a new (speed_optimized) message option that emits
__attribute__((optimize("O2"))) on the generated encode() and
calculate_size() methods. Under -Os, GCC does not inline the small
ProtoEncode helpers (write_raw_byte, encode_varint, etc.) into the
generated methods, causing significant overhead on hot paths.

Apply to SensorStateResponse and BluetoothLERawAdvertisementsResponse
which are the highest-frequency encode paths.
2026-04-12 19:23:39 -10:00
J. Nick Koston 70dd732821 [api] Add speed_optimized proto option for hot encode paths
Add a new (speed_optimized) message option that emits
__attribute__((optimize("O2"))) on the generated encode() and
calculate_size() methods. Under -Os, GCC does not inline the small
ProtoEncode helpers (write_raw_byte, encode_varint, etc.) into the
generated methods, causing significant overhead on hot paths.

Apply to SensorStateResponse and BluetoothLERawAdvertisementsResponse
which are the highest-frequency encode paths.
2026-04-12 19:21:47 -10:00
J. Nick Koston c58447ad3a Merge branch 'benchmark-crypto-o2' into integration 2026-04-12 19:17:20 -10:00
J. Nick Koston 02f828fcbf [benchmark] Use -Os to match firmware optimization level
CodSpeed benchmarks were building with -O2, while all firmware
targets (ESP8266, ESP32, LibreTiny) use -Os. This mismatch means
the benchmarks cannot detect inlining regressions that affect real
devices — GCC under -O2 inlines functions that -Os outlines due to
its size-conscious cost model.

Switch to -Os with -ffunction-sections/-fdata-sections for proper
dead-code stripping (needed because -Os preserves references that
-O2 optimizes away at compile time).
2026-04-12 18:37:50 -10:00
J. Nick Koston ab64916c37 [benchmark] Use -Os to match firmware optimization level
CodSpeed benchmarks were building with -O2, while all firmware
targets (ESP8266, ESP32, LibreTiny) use -Os. This mismatch means
the benchmarks cannot detect inlining regressions that affect real
devices — GCC under -O2 inlines functions that -Os outlines due to
its size-conscious cost model.

Remove the -Os unflag and -O2 override so benchmarks use the
platform default -Os, matching what actually runs on devices.
2026-04-12 18:32:03 -10:00
J. Nick Koston ec420d5792 [api] Add (inline_encode) proto option for sub-message inlining (#15599) 2026-04-10 15:33:56 +12:00
J. Nick Koston efa334b79c Merge remote-tracking branch 'origin/entity-types-xmacro' into integration 2026-04-09 14:57:57 -10:00
J. Nick Koston 053cee4ec9 [core] Use ENTITY_TYPES_H_TARGET constant in helpers.py 2026-04-09 14:52:37 -10:00
J. Nick Koston 7d87b32033 [core] Exclude entity_types.h from clang-tidy all-include.cpp
The X-macro file requires macros to be defined before inclusion and
cannot be included bare in the clang-tidy all-include header.
2026-04-09 14:52:04 -10:00
J. Nick Koston affb20a9cf [core] Rename entity_types.inc to entity_types.h
Neither PlatformIO nor ESP-IDF/CMake copy .inc files to the build
directory. Rename to .h so it's recognized by both build systems.
Exempt from pragma-once lint since this file is intentionally included
multiple times with different macro definitions.
2026-04-09 14:44:52 -10:00
J. Nick Koston b9d0f96053 Merge remote-tracking branch 'origin/inline-encode-ble-adv' into integration 2026-04-09 11:57:55 -10:00
J. Nick Koston 781ab59611 Remove duplicate unrolled inline size cases, always use loop 2026-04-09 00:16:07 -10:00
J. Nick Koston 382202334a Simplify field_ifdef handling in inline blocks 2026-04-09 00:15:24 -10:00
J. Nick Koston 277552cef0 Address review: reserve_byte, varint(0), field_ifdef, getattr guard 2026-04-09 00:13:36 -10:00
J. Nick Koston 1279e6112a Support max_data_length in get_max_encoded_size for string types 2026-04-08 23:42:08 -10:00
J. Nick Koston 24edb9c98e Eliminate sub_size variable, accumulate directly into size 2026-04-08 23:29:51 -10:00
J. Nick Koston 1ac2a73267 Remove redundant body_start variable in inline encode 2026-04-08 23:25:12 -10:00
J. Nick Koston 14a4a2c618 Remove redundant block scoping inside loop bodies 2026-04-08 23:12:47 -10:00
J. Nick Koston 4d4b77f9fc [api] Add (inline_encode) proto option for sub-message inlining
Add a new message-level option (inline_encode) that causes the code
generator to inline sub-message encoding directly into the parent's
encode/calculate_size methods instead of going through the
encode_sub_message function pointer indirection.

When set on a sub-message type, the generator:
- Inlines field encoding directly (no function pointer, no backpatch overhead)
- Inlines size calculation (no separate method call)
- Skips generating standalone encode/calculate_size methods
- Validates at generation time that max encoded size < 128 bytes

Applied to BluetoothLERawAdvertisement which is encoded 12 times per
BLE advertisement batch in a hot loop.
2026-04-08 23:06:41 -10:00
J. Nick Koston d9ebe1e1e7 Merge branch 'crash-handler-dual-core' into integration 2026-04-08 09:34:33 -10:00
J. Nick Koston b83edf6c17 [script] Resolve IncludeFile objects in component config merge (#15575) 2026-04-08 08:57:56 -10:00
J. Nick Koston f278e12841 Merge remote-tracking branch 'upstream/templatable-value-specialize' into integration 2026-04-07 19:14:36 -10:00
J. Nick Koston c7513b9262 [ci] Add lint check for test package key matching bus directory (#15547) 2026-04-07 16:01:18 -10:00
J. Nick Koston 10b38e1588 [api] Add max_data_length proto option and optimize entity name/object_id (#15426) 2026-04-07 03:31:01 +00:00
J. Nick Koston d15fa84f4f [api] Auto-derive max_value for enum fields in protobuf codegen (#15469) 2026-04-06 14:39:55 -10:00
J. Nick Koston 136eabebb4 Merge branch 'api-enum-auto-max-value' into integration
# Conflicts:
#	esphome/components/api/api_pb2.cpp
#	script/api_protobuf/api_protobuf.py
2026-04-06 14:07:38 -10:00
J. Nick Koston 7c671cd0e6 Merge branch 'api-proto-max-length' into integration
# Conflicts:
#	esphome/components/api/api_connection.cpp
#	esphome/components/api/api_pb2.cpp
#	esphome/components/api/proto.h
#	esphome/core/application.h
#	esphome/core/component.cpp
#	script/api_protobuf/api_protobuf.py
2026-04-06 14:02:14 -10:00
J. Nick Koston 87622c9a74 [api] Add max_data_length proto option and optimize entity string encoding
Add a max_data_length field option to api_options.proto for string/bytes
fields. When max_data_length < 128 and force = true, the code generator
uses encode_short_string_force() — a single call that writes the tag
byte, 1-byte length varint, and raw string data with no branching. Size
calculation simplifies from calc_length(1, size) to 2 + size.

Annotate entity fields across all 25 ListEntities*Response messages:
- name and object_id: max_data_length = 120, force = true (50 fields)
- icon: max_data_length = 63 (25 fields)

The 120 and 63 values match NAME_MAX_LENGTH and ICON_MAX_LENGTH in
esphome/core/config.py, validated at config time.
2026-04-06 13:28:50 -10:00
J. Nick Koston 37258de6b1 [api] Auto-derive max_value for enum fields in protobuf codegen
Scan all enum definitions in api.proto at codegen time and automatically
populate max_value for enum-typed fields. This eliminates the need for
manual (max_value) annotations on every enum field.

When max_value < 128, the generated calculate_size uses constant-size
arithmetic instead of a function call:
- `calc_uint32(1, static_cast<uint32_t>(field))` → `field ? 2 : 0`

For repeated enum fields with constant element size, the per-element
loop is replaced with a multiply: `size += count * bytes_per_element`.
2026-04-06 13:19:37 -10:00
J. Nick Koston 2b5ee69eb2 [api] Speed up protobuf encode 17-20% with register-optimized write path (#15290)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
2026-04-06 12:42:18 -10:00
J. Nick Koston 4099064207 Use write_short_string for non-forced strings with max_data_length < 128
Add empty check wrapper for non-forced short strings instead of falling
through to the general encode_string path.
2026-04-06 08:43:24 -10:00
J. Nick Koston 33285dfe27 Fix merge issues: write_short_string to static ProtoEncode, add debug arg
- Convert ProtoEncode::write_short_string to static method with pos param
- Fix codegen to emit ProtoEncode::write_short_string(pos, ...)
- Add PROTO_ENCODE_DEBUG_INIT to encode_fn call in encode_to_buffer

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 08:33:13 -10:00
J. Nick Koston 7122fb6f88 Merge remote-tracking branch 'upstream/api-sint32-short-varint' into integration
Fix double static_cast in enum encode precomputed tag path by
passing raw field ref instead of pre-cast value_expr.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 08:31:05 -10:00
J. Nick Koston 8fc7cdbe28 Merge remote-tracking branch 'upstream/api-enum-auto-max-value' into integration 2026-04-05 19:04:51 -10:00
J. Nick Koston fef4ff4a82 [api] Remove encode_small_varint — no real benefit over encode_uint32 2026-04-05 19:04:01 -10:00
J. Nick Koston 03d64317c7 Merge remote-tracking branch 'upstream/api-enum-auto-max-value' into integration 2026-04-05 18:58:09 -10:00
J. Nick Koston d5b5a6a4a7 [api] Don't use encode_small_varint for forced fields (must encode zero) 2026-04-05 18:57:04 -10:00
J. Nick Koston 307f436229 [api] Move zero-check into encode_small_varint to simplify call sites 2026-04-05 18:56:10 -10:00
J. Nick Koston 883a300785 [api] Add encode_small_varint helper for single-byte tag+value encoding
Replace two separate write_raw_byte calls with a single
encode_small_varint(tag, value) call that writes both bytes
with one bounds check. Used for enum fields with max < 128.
2026-04-05 18:53:48 -10:00
J. Nick Koston 5a6330e366 [api] Remove redundant uint32_t cast in enum raw byte writes 2026-04-05 18:51:14 -10:00
J. Nick Koston 5c178eab63 [api] Optimize encode for non-forced enum fields with single-byte tags
When an enum field has max_value < 128 and a single-byte tag, emit
inline write_raw_byte calls instead of calling encode_uint32, which
avoids encode_field_raw and encode_varint_raw function call overhead.
2026-04-05 18:50:23 -10:00
J. Nick Koston 3f7e636f7a Merge remote-tracking branch 'upstream/api-enum-auto-max-value' into integration 2026-04-05 18:40:32 -10:00