From 3e86c8087409d082321a91d70cc83843d4edb71e Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 25 Jan 2024 09:58:36 -0800 Subject: [PATCH] Set buffer size when unzipping (#1101) The zip archive includes an uncompressed size header, which we can use to preallocate. --- crates/puffin-extract/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/puffin-extract/src/lib.rs b/crates/puffin-extract/src/lib.rs index 1a569b909..2dc0996dd 100644 --- a/crates/puffin-extract/src/lib.rs +++ b/crates/puffin-extract/src/lib.rs @@ -50,7 +50,9 @@ pub async fn unzip_no_seek( fs_err::tokio::create_dir_all(parent).await?; } let file = fs_err::tokio::File::create(path).await?; - let mut writer = tokio::io::BufWriter::new(file); + let size = + usize::try_from(entry.reader().entry().uncompressed_size()).unwrap_or(usize::MAX); + let mut writer = tokio::io::BufWriter::with_capacity(size, file); let mut reader = entry.reader_mut().compat(); tokio::io::copy(&mut reader, &mut writer).await?; }