[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:
J. Nick Koston
2026-03-29 10:23:43 -10:00
parent 8e0763bfc5
commit 9a89641377
2 changed files with 2 additions and 2 deletions
@@ -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;