From 19cc6ee6d4aedb530e1203e12786bb21f6b79012 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Tue, 14 Jul 2026 09:13:50 -0700 Subject: [PATCH] Batch streamed request body history into full-size chunks (#508) --- crates/yaak/src/send.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/crates/yaak/src/send.rs b/crates/yaak/src/send.rs index cd16812b..113a3903 100644 --- a/crates/yaak/src/send.rs +++ b/crates/yaak/src/send.rs @@ -949,14 +949,24 @@ async fn persist_request_body_stream( ) -> std::result::Result { let mut chunk_index: i32 = 0; let mut total_bytes = 0usize; + + // Stream reads arrive in small (eg. 8-16 KiB) pieces, so accumulate them into + // full-size chunks to avoid thousands of tiny inserts for large bodies + let mut buf: Vec = Vec::with_capacity(REQUEST_BODY_CHUNK_SIZE); while let Some(data) = rx.recv().await { total_bytes += data.len(); - if data.is_empty() { - continue; + buf.extend_from_slice(&data); + while buf.len() >= REQUEST_BODY_CHUNK_SIZE { + let data = buf.drain(..REQUEST_BODY_CHUNK_SIZE).collect(); + let chunk = BodyChunk::new(&body_id, chunk_index, data); + blob_manager.connect().insert_chunk(&chunk).map_err(|e| e.to_string())?; + chunk_index += 1; } - let chunk = BodyChunk::new(&body_id, chunk_index, data); + } + + if !buf.is_empty() { + let chunk = BodyChunk::new(&body_id, chunk_index, buf); blob_manager.connect().insert_chunk(&chunk).map_err(|e| e.to_string())?; - chunk_index += 1; } Ok(total_bytes)