Skip to content

Commit 257ec7e

Browse files
evilsocketclaude
andcommitted
inference-io: pre-allocate read buffer in from_reader
Start with 8KB capacity instead of empty Vec, matching typical inference tensor sizes. Avoids initial reallocation on first resize. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3b9f882 commit 257ec7e

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

cake-core/src/cake/sharding/proto/message.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ impl Message {
221221
}
222222

223223

224+
224225
/// Create a Message::Batch message.
225226
pub fn from_batch(x: &Tensor, batch: Vec<(String, usize, usize)>) -> Self {
226227
Self::Batch {
@@ -272,7 +273,8 @@ impl Message {
272273
where
273274
R: AsyncReadExt + Unpin,
274275
{
275-
let mut buf = Vec::new();
276+
// Pre-allocate a reasonable buffer for typical inference messages (~2-8 KB).
277+
let mut buf = Vec::with_capacity(8 * 1024);
276278
Self::from_reader_buf(reader, &mut buf).await
277279
}
278280

0 commit comments

Comments
 (0)