Commit Graph
26349 Commits
Author SHA1 Message Date
J. Nick Koston a91e6d92f6 [core] Remove dead get_loop_priority code (#15242) 2026-03-29 17:32:43 -04:00
J. Nick Koston 9df835600c [api] Rename write_raw_inline_ to write_raw_fast_ 2026-03-29 11:26:23 -10:00
J. Nick Koston f1e780be0c [api] Remove out-of-line write_raw_ wrappers to save flash
The wrappers called write_raw_inline_ which expanded the full fast
path code, defeating the purpose. Cold callers now call write_raw_slow_
directly with sent=-1, which is the same behavior without duplicating
the fast path at each cold call site.
2026-03-29 11:25:33 -10:00
J. Nick Koston 3af6001cdf [api] Keep write_raw_slow_ protected to not break subclass member visibility 2026-03-29 11:17:16 -10:00
J. Nick Koston 9fd745cb09 [api] Add out-of-line write_raw_ wrappers calling write_raw_inline_
Hot paths use write_raw_inline_ (ALWAYS_INLINE fast path).
Cold paths (handshake, error handling) use write_raw_ which is
an out-of-line wrapper that calls write_raw_inline_ — same logic,
no code duplication, but the compiler won't expand the fast path
at each cold call site.
2026-03-29 11:16:33 -10:00
J. Nick Koston ad25e2ae0c [api] Add single-buffer write_raw_slow_ overload for cold paths
Cold paths (write_frame_, bad indicator) no longer need to construct
an iovec just to call the slow path. The single-buffer overload wraps
in iovec internally, keeping call sites clean and avoiding iovec
setup in the caller's stack frame.
2026-03-29 11:12:10 -10:00
J. Nick Koston 5a8e54301f [api] Call write_raw_slow_ directly from cold paths to save flash
write_frame_ (handshake) and bad indicator response are cold paths
that don't benefit from the inlined write_raw_ fast path. Calling
write_raw_slow_ directly avoids expanding the inline fast path code
at these call sites, saving ~70 bytes per site.
2026-03-29 11:10:56 -10:00
J. Nick Koston ce9bc3aaa1 [api] Use iovec path for write_frame_ to avoid inlining write_raw_ in cold handshake code 2026-03-29 11:00:42 -10:00
J. Nick Koston aee9d93671 fix 2026-03-29 10:59:41 -10:00
J. Nick Koston a1163b298e [api] Inline check_socket_write_err_ in drain_overflow (removed from header) 2026-03-29 10:49:35 -10:00
J. Nick Koston 3277683058 [api] Add missing this-> prefix on write_raw_ calls 2026-03-29 10:48:47 -10:00
J. Nick Koston 348d5f583a [api] Restructure write_raw_ for single tail call to slow path 2026-03-29 10:47:07 -10:00
J. Nick Koston ea7dc663f6 [api] Inline write_raw_ fast paths into header with single slow path
Move the happy path (overflow empty + full write succeeds) inline into
the header so it gets inlined at each call site. Both overloads share
a single out-of-line write_raw_slow_ that handles partial writes,
errors, and overflow buffering.
2026-03-29 10:45:01 -10:00
J. Nick Koston f272826274 [api] Extract enqueue_overflow_ slow path and remove dead iovcnt==1 branch
Both write_raw_ overloads now have a clean fast path (direct socket
write) and delegate to a shared noinline enqueue_overflow_ for the
rare overflow case. The multi-iovec path now always calls writev
since single-message callers use the dedicated overload.
2026-03-29 10:43:01 -10:00
J. Nick Koston 5d8f67c819 [api] Add single-buffer write_raw_ overload for single-message path
The existing write_raw_ takes iovec array + count, but single-message
writes (87-100% of traffic) always pass iovcnt=1. Adding a dedicated
overload that takes (data, len) eliminates iovec construction, the
iovcnt==1 branch, and pointer indirection on the hot path.
2026-03-29 10:42:20 -10:00
J. Nick Koston 98b7f5a571 [api] Force inline write_plaintext_header to avoid batch regression 2026-03-29 10:38:54 -10:00
J. Nick Koston 4d72acafb5 Merge branch 'api/peel-first-write-iteration' of https://github.com/esphome/esphome into api/peel-first-write-iteration
# Conflicts:
#	esphome/components/api/api_frame_helper_noise.cpp
#	esphome/components/api/api_frame_helper_plaintext.cpp
2026-03-29 10:33:24 -10:00
J. Nick Koston 481c0688ad [api] Split write_protobuf_packet into dedicated virtual for single messages
Instead of routing single messages through write_protobuf_messages and
branching internally, make write_protobuf_packet a separate virtual
override in each frame helper. The single-message path gets its own
minimal stack frame with no StaticVector allocation, and the batch
path in write_protobuf_messages has no size==1 branch — each caller
picks the right method upfront.
2026-03-29 10:32:00 -10:00
J. Nick Koston 9a89641377 [api] Add flatten attribute to batch write functions to avoid regression
The noinline attribute on the batch path prevented the compiler from
inlining callees like write_plaintext_header and encrypt_noise_message_
into the loop body, causing a 5.6% regression on batch writes. Adding
flatten forces all callees to be inlined within the batch function while
noinline still keeps its large stack frame separate from the single-message
fast path.
2026-03-29 10:23:43 -10:00
J. Nick Koston 60c6bc3e21 try another way 2026-03-29 10:23:14 -10:00
J. Nick Koston 8e0763bfc5 Merge branch 'dev' into api/peel-first-write-iteration 2026-03-29 10:19:33 -10:00
J. Nick Koston 86f3eed1e0 revert 2026-03-29 08:47:40 -10:00
J. Nick Koston 58213d103a cleanup 2026-03-29 08:44:08 -10:00
J. Nick Koston b1ff7bc6e4 remove heap stats 2026-03-29 08:40:41 -10:00
J. Nick Koston a12dcc68a9 Merge remote-tracking branch 'upstream/component-8byte-optimization' into integration 2026-03-29 08:36:03 -10:00
J. Nick Koston fd8b8c6546 Merge branch 'dev' into component-8byte-optimization 2026-03-29 08:25:57 -10:00
J. Nick Koston e87239c7c3 Revert "revert peel"
This reverts commit 0606bf9c12.
2026-03-29 08:15:19 -10:00
J. Nick Koston b869701ee3 Revert "try revert float"
This reverts commit 868b2eb2ea.
2026-03-29 08:15:06 -10:00
Tobias StanzelandJonathan Swoboda d9adb078aa [tm1637] Add buffer manipulation methods (#13686)
Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com>
2026-03-29 14:41:00 -03:00
J. Nick Koston 4d9bbf3b51 Merge branch 'api-sint32-short-varint' into integration 2026-03-28 23:18:57 -10:00
J. Nick Koston 868b2eb2ea try revert float 2026-03-28 23:12:08 -10:00
J. Nick Koston 0606bf9c12 revert peel 2026-03-28 23:01:33 -10:00
J. Nick Koston 77e47f609d Merge branch 'dev' into api/peel-first-write-iteration 2026-03-28 22:59:05 -10:00
J. Nick Koston 35491f2649 Revert "[api] Merge tag + value into single __restrict__ scope in encode_uint32/uint64/bool/fixed32"
This reverts commit fe012272f8.
2026-03-28 22:15:28 -10:00
J. Nick Koston fe012272f8 [api] Merge tag + value into single __restrict__ scope in encode_uint32/uint64/bool/fixed32
Each of these methods called encode_field_raw() then a value encoder,
causing a store-load pair on pos_ between the tag and value writes.

Inline the tag write into the same __restrict__ local scope as the
value write so the compiler can emit tag + value with a single pos_
load at start and store at end. Verified on Xtensa: encode_uint32
now does one load + two writes + one store (was load-store-load-store).
2026-03-28 22:06:31 -10:00
J. Nick Koston 3e89858e39 Merge remote-tracking branch 'origin/api-sint32-short-varint' into integration 2026-03-28 21:43:28 -10:00
J. Nick Koston 0603190c3c [api] Restore debug bounds checks in __restrict__ varint loops
Add sync_debug_check_bounds_() that syncs pos_ from a local pointer
before checking bounds. Use it in encode_varint_raw_64 and
encode_varint_raw_slow_ to restore per-byte bounds checking in
debug mode without breaking the __restrict__ optimization in
production (where it's a no-op).
2026-03-28 19:55:50 -10:00
J. Nick Koston 3a76f9d5d2 [api] Merge varint length + memcpy into single pos scope in encode_string
Previously encode_string called encode_varint_raw(len) then
encode_raw(data, len) as separate methods, each with their own
__restrict__ pos scope. This caused a redundant store-load pair
of pos_ between the two operations.

Inline the length varint write and memcpy under a single local
pos variable so the compiler can keep pos_ in a register across
both operations. Eliminates one load-store pair per string encode.
2026-03-28 19:51:55 -10:00
J. Nick Koston c6938adb61 [api] Apply __restrict__ local hoist to all ProtoWriteBuffer pos_ accessors
Apply the same __restrict__ local pointer pattern proven in
encode_varint_raw_64 to all remaining methods that write through
pos_: encode_varint_raw, encode_varint_raw_short, write_raw_byte,
encode_raw, write_tag_and_fixed32, encode_string, encode_bool,
and encode_fixed32.

Each method now hoists pos_ into a __restrict__ local before
writing and stores back once at the end. When the compiler inlines
these into a generated encode() method, it can keep pos_ in a
register across consecutive calls instead of reloading from memory
after every write.
2026-03-28 19:47:40 -10:00
J. Nick Koston 83e4478bc2 [api] Apply __restrict__ local hoist to encode_varint_raw_slow_
Same optimization as encode_varint_raw_64: hoist pos_ into a
__restrict__ local so the compiler keeps it in a register across
the loop instead of reloading from memory each iteration.
2026-03-28 19:45:49 -10:00
J. Nick Koston 3886751662 [api] Restore comment on __restrict__ local in encode_varint_raw_64 2026-03-28 19:45:07 -10:00
J. Nick Koston 537af1fe6b [api] Hoist pos_ to local in encode_varint_raw_64 to avoid reload per byte
Use a __restrict__ local pointer for the varint write loop so the
compiler can keep it in a register instead of reloading pos_ from
memory on each iteration. Eliminates the store→load dependency
chain that was causing 7 load/store pairs for a typical 48-bit
BLE address varint.
2026-03-28 19:44:16 -10:00
J. Nick Koston 2137e4600a [api] Hoist pos_ to local in encode_varint_raw_64 to avoid reload per byte
Use a __restrict__ local pointer for the varint write loop so the
compiler can keep it in a register instead of reloading pos_ from
memory on each iteration. Eliminates the store→load dependency
chain that was causing 7 load/store pairs for a typical 48-bit
BLE address varint.
2026-03-28 17:43:11 -10:00
J. Nick Koston 52897fd067 [api] Add 2-byte inline fast path for sint32 varint encode/size
Add encode_varint_raw_short() and ProtoSize::varint_short() that
inline both the 1-byte and 2-byte varint paths, falling back to
the noinline slow path for 3+ bytes.

Use these for sint32 fields (zigzag encoding), where values like
RSSI (-100 to 0) produce zigzag values that are 1-2 bytes. This
avoids a function call for the common case without bloating the
generic encode_varint_raw fast path.
2026-03-28 17:27:40 -10:00
J. Nick Koston 777e162070 [benchmark] Add BLE raw advertisement proto encode benchmarks
Add CodSpeed benchmarks for BluetoothLERawAdvertisementsResponse
(12 advertisements) covering calculate_size, encode, calc+encode,
and fresh-buffer paths.

Includes a lightweight bluetooth_proxy stub header in
tests/benchmarks/stubs/ so the api component can compile with
USE_BLUETOOTH_PROXY on the host platform without pulling in
ESP32 BLE dependencies.
2026-03-28 17:08:52 -10:00
J. Nick Koston 2c0b9c431a Merge branch 'dedupe-build-time-str' into integration 2026-03-28 16:08:36 -10:00
J. Nick Koston 9b6d22be5f [version] Use App.get_build_time_string() instead of including build_info_data.h
Remove direct include of build_info_data.h from version_text_sensor.cpp
and use the existing App.get_build_time_string() API instead. This
eliminates duplicate ESPHOME_BUILD_TIME_STR and ESPHOME_COMMENT_STR
symbols that were emitted into every translation unit including the
header (static const in a header = one copy per TU).

Now only application.cpp includes build_info_data.h, which also
improves incremental rebuild times: when build info changes, only
application.cpp needs recompiling instead of both application.cpp
and version_text_sensor.cpp.
2026-03-28 16:05:36 -10:00
J. Nick Koston 90c7ad322b Merge remote-tracking branch 'upstream/dev' into integration 2026-03-28 15:50:13 -10:00
J. Nick Koston 7a7c33fdb1 [esp32_ble_server] Fix set_value action with static data lists (#15285) 2026-03-28 15:38:06 -10:00
J. Nick Koston ccc05bfd08 Merge remote-tracking branch 'upstream/fix-bl0942-energy-counter-reset' into integration 2026-03-28 14:12:32 -10:00