From 7b04b174b9de66d7fef8903894a6d802a8e7f25d Mon Sep 17 00:00:00 2001 From: Jake Date: Sat, 26 Apr 2025 00:37:32 -0700 Subject: [PATCH] axum-extra: Pre-allocate right sized buffer when encoding protobuf response (#3325) --- axum-extra/src/protobuf.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/axum-extra/src/protobuf.rs b/axum-extra/src/protobuf.rs index 0060cd74..fb63c7a4 100644 --- a/axum-extra/src/protobuf.rs +++ b/axum-extra/src/protobuf.rs @@ -128,7 +128,7 @@ where T: Message + Default, { fn into_response(self) -> Response { - let mut buf = BytesMut::with_capacity(128); + let mut buf = BytesMut::with_capacity(self.0.encoded_len()); match &self.0.encode(&mut buf) { Ok(()) => buf.into_response(), Err(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response(),