From 73f100fa66900305820fb30c5beaac274dcd54e9 Mon Sep 17 00:00:00 2001 From: DioCrafts Date: Tue, 3 Mar 2026 19:48:53 +0100 Subject: [PATCH] perf(h1): pre-allocate read buffer to avoid early reallocations Change read_buf initialization from BytesMut::with_capacity(0) to BytesMut::with_capacity(INIT_BUFFER_SIZE) (8192 bytes). The read buffer almost always grows to INIT_BUFFER_SIZE on the first read. Pre-allocating avoids the initial zero-capacity allocation and the subsequent reallocation + copy when the first data arrives. --- src/proto/h1/io.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proto/h1/io.rs b/src/proto/h1/io.rs index 6a30d73c84..9f78e993f8 100644 --- a/src/proto/h1/io.rs +++ b/src/proto/h1/io.rs @@ -68,7 +68,7 @@ where io, partial_len: None, read_blocked: false, - read_buf: BytesMut::with_capacity(0), + read_buf: BytesMut::with_capacity(INIT_BUFFER_SIZE), read_buf_strategy: ReadStrategy::default(), write_buf, }