Skip to content

Commit

Permalink
Stop zeroing buffers in the local file storage. (#4712)
Browse files Browse the repository at this point in the history
  • Loading branch information
fulmicoton committed Mar 12, 2024
1 parent b5611a2 commit 0d54cf0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion quickwit/quickwit-storage/src/file_descriptor_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
7 changes: 5 additions & 2 deletions quickwit/quickwit-storage/src/local_file_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> = vec![0u8; range.len()];
let mut content_bytes: Vec<u8> = 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))
})
Expand Down

0 comments on commit 0d54cf0

Please sign in to comment.