From c7dd842f84268985e8701c67a9ea2607c13c9ae1 Mon Sep 17 00:00:00 2001 From: Marcos Casagrande Date: Mon, 26 Sep 2022 20:27:50 +0200 Subject: perf(ext/fetch): use content-length in InnerBody.consume (#15925) This fast path prevents repeated allocations when receiving a fetch body with a known size. Co-authored-by: Luca Casonato --- ext/fetch/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ext/fetch/lib.rs') diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index 20db7abbc..3988acf9e 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -361,6 +361,7 @@ pub struct FetchResponse { headers: Vec<(ByteString, ByteString)>, url: String, response_rid: ResourceId, + content_length: Option, } #[op] @@ -391,6 +392,8 @@ pub async fn op_fetch_send( res_headers.push((key.as_str().into(), val.as_bytes().into())); } + let content_length = res.content_length(); + let stream: BytesStream = Box::pin(res.bytes_stream().map(|r| { r.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err)) })); @@ -409,6 +412,7 @@ pub async fn op_fetch_send( headers: res_headers, url, response_rid: rid, + content_length, }) } -- cgit v1.2.3