From 569287b15b6482a39f2c816f103574c3b35351f8 Mon Sep 17 00:00:00 2001 From: Marcos Casagrande Date: Tue, 4 Oct 2022 15:48:50 +0200 Subject: perf(ext/fetch): consume body using ops (#16038) This commit adds a fast path to `Request` and `Response` that make consuming request bodies much faster when using `Body#text`, `Body#arrayBuffer`, and `Body#blob`, if the body is a FastStream. Because the response bodies for `fetch` are FastStream, this speeds up consuming `fetch` response bodies significantly. --- ext/fetch/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ext/fetch/lib.rs') diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index a7daaa63a..0adc32343 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -408,6 +408,7 @@ pub async fn op_fetch_send( .add(FetchResponseBodyResource { reader: AsyncRefCell::new(stream_reader), cancel: CancelHandle::default(), + size: content_length, }); Ok(FetchResponse { @@ -479,6 +480,7 @@ type BytesStream = struct FetchResponseBodyResource { reader: AsyncRefCell>, cancel: CancelHandle, + size: Option, } impl Resource for FetchResponseBodyResource { @@ -498,6 +500,10 @@ impl Resource for FetchResponseBodyResource { }) } + fn size_hint(&self) -> (u64, Option) { + (0, self.size) + } + fn close(self: Rc) { self.cancel.cancel() } -- cgit v1.2.3