schedule_message_front_ is only called from cold paths (on_shutdown,
check_keepalive_). Moving it out-of-line prevents add_item_front and
push_back from being inlined into those callers.
add_item_front is only called from on_shutdown and check_keepalive_
which are cold paths. Keeping it out-of-line prevents inlining
push_back into those callers.
Both are only called from one site each. Moving them inline lets the
compiler inline push_back directly into the caller without a function
call barrier. Removes the now-unnecessary push_item wrapper.
Add __attribute__((flatten)) to add_item and add_item_front so the
compiler inlines push_item → push_back and all their callees directly
into these functions, eliminating the function call barrier.
The out-of-line push_item with __attribute__((flatten)) inlined
push_back's callees into push_item, but push_item itself remained
a function call barrier. Moving push_item inline lets the compiler
inline push_back into the actual call sites (add_item, add_item_front).
Inlining push_item into add_item bloated the dedup loop, causing
the compiler to make worse inlining decisions. Total time went from
44µs to 64.5µs. Restore out-of-line with __attribute__((flatten))
which keeps add_item's dedup loop tight while still inlining
push_back's callees into push_item.
push_item was defined out-of-line in the .cpp to avoid duplicate
_M_realloc_insert instantiation, but the function call overhead
on every add_item was visible in benchmarks. Move it inline since
it's a one-liner wrapper around push_back.
should_send_immediately_ requires both should_try_send_immediately
flag AND batch_delay==0. Without setting batch_delay to 0, all
sends were falling back to the batch path.
Increase socket buffer to 16MB so benchmarks never hit WOULD_BLOCK
during an inner loop iteration. Remove per-iteration drain_socket
calls that were adding noise and causing the immediate path to
fall back to batching. Drain only between outer iterations.
Add benchmarks for the full send_sensor_state path covering both
immediate send and batch paths. This measures the end-to-end cost
of sending a sensor state update through an APIConnection including
entity field population, proto encode, framing, and TCP write.
Co-authored-by: J. Nick Koston <nick+github@koston.org>
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>