mirror of
https://github.com/esphome/esphome.git
synced 2026-09-15 09:08:41 +00:00
[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.
This commit is contained in:
@@ -489,7 +489,7 @@ APIError APINoiseFrameHelper::encrypt_noise_message_(uint8_t *buf_start, const M
|
||||
}
|
||||
|
||||
// Outlined multi-message path to keep the single-message fast path's stack frame small.
|
||||
APIError __attribute__((noinline))
|
||||
APIError __attribute__((noinline, flatten))
|
||||
APINoiseFrameHelper::write_protobuf_messages_batch_(uint8_t *buffer_data, std::span<const MessageInfo> messages) {
|
||||
StaticVector<struct iovec, MAX_MESSAGES_PER_BATCH> iovs;
|
||||
uint16_t total_write_len = 0;
|
||||
|
||||
@@ -288,7 +288,7 @@ static inline uint8_t *write_plaintext_header(uint8_t *buf_start, const MessageI
|
||||
// Outlined multi-message path to keep the single-message fast path's stack frame small.
|
||||
// The StaticVector<iovec, MAX_MESSAGES_PER_BATCH> would force a ~300-byte stack frame
|
||||
// even when only sending one message if it were in the same function.
|
||||
APIError __attribute__((noinline))
|
||||
APIError __attribute__((noinline, flatten))
|
||||
APIPlaintextFrameHelper::write_protobuf_messages_batch_(uint8_t *buffer_data, std::span<const MessageInfo> messages) {
|
||||
StaticVector<struct iovec, MAX_MESSAGES_PER_BATCH> iovs;
|
||||
uint16_t total_write_len = 0;
|
||||
|
||||
Reference in New Issue
Block a user