From 22763af927990010e5c75f23e79d183bbaebf90d Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Mon, 11 Mar 2024 19:11:37 +0900 Subject: [PATCH] Stop zeroing buffers in the local file storage. --- quickwit/quickwit-storage/src/file_descriptor_cache.rs | 6 +++++- quickwit/quickwit-storage/src/local_file_storage.rs | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/quickwit/quickwit-storage/src/file_descriptor_cache.rs b/quickwit/quickwit-storage/src/file_descriptor_cache.rs index 909455eac99..9ea2ffea8cc 100644 --- a/quickwit/quickwit-storage/src/file_descriptor_cache.rs +++ b/quickwit/quickwit-storage/src/file_descriptor_cache.rs @@ -160,7 +160,11 @@ impl SplitFile { use std::os::unix::fs::FileExt; let file = self.clone(); let buf = tokio::task::spawn_blocking(move || { - let mut buf = vec![0u8; range.len()]; + let mut buf = Vec::with_capacity(range.len()); + #[allow(clippy::uninit_vec)] + unsafe { + buf.set_len(range.len()); + } file.0.file.read_exact_at(&mut buf, range.start as u64)?; io::Result::Ok(buf) }) diff --git a/quickwit/quickwit-storage/src/local_file_storage.rs b/quickwit/quickwit-storage/src/local_file_storage.rs index 5bbf42f05d9..9d1c032e990 100644 --- a/quickwit/quickwit-storage/src/local_file_storage.rs +++ b/quickwit/quickwit-storage/src/local_file_storage.rs @@ -215,12 +215,15 @@ impl Storage for LocalFileStorage { let full_path = self.full_path(path)?; tokio::task::spawn_blocking(move || { use std::io::{Read, Seek}; - // we run these io in a spawn_blocking so there is no scheduling delay between each // step, as there would be if using tokio async File. let mut file = std::fs::File::open(full_path)?; file.seek(SeekFrom::Start(range.start as u64))?; - let mut content_bytes: Vec = vec![0u8; range.len()]; + let mut content_bytes: Vec = Vec::with_capacity(range.len()); + #[allow(clippy::uninit_vec)] + unsafe { + content_bytes.set_len(range.len()); + } file.read_exact(&mut content_bytes)?; Ok(OwnedBytes::new(content_bytes)) })