Unverified Commit 3eb23fe9 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: use mmap advise to help the OS preloading (#84379)

### What?

Help the OS to prefetch file ranges
parent 6d536ed2
...@@ -109,6 +109,11 @@ impl StaticSortedFile { ...@@ -109,6 +109,11 @@ impl StaticSortedFile {
let mmap = unsafe { Mmap::map(&File::open(&path)?)? }; let mmap = unsafe { Mmap::map(&File::open(&path)?)? };
#[cfg(unix)] #[cfg(unix)]
mmap.advise(memmap2::Advice::Random)?; mmap.advise(memmap2::Advice::Random)?;
#[cfg(unix)]
{
let offset = meta.block_offsets_start(mmap.len());
let _ = mmap.advise_range(memmap2::Advice::Sequential, offset, mmap.len() - offset);
}
let file = Self { meta, mmap }; let file = Self { meta, mmap };
Ok(file) Ok(file)
} }
...@@ -397,6 +402,12 @@ impl StaticSortedFile { ...@@ -397,6 +402,12 @@ impl StaticSortedFile {
self.meta.blocks_start() self.meta.blocks_start()
); );
} }
#[cfg(unix)]
let _ = self.mmap.advise_range(
memmap2::Advice::Sequential,
block_start,
block_end - block_start,
);
let uncompressed_length = (&self.mmap[block_start..block_start + 4]).read_u32::<BE>()?; let uncompressed_length = (&self.mmap[block_start..block_start + 4]).read_u32::<BE>()?;
let block = &self.mmap[block_start + 4..block_end]; let block = &self.mmap[block_start + 4..block_end];
Ok((uncompressed_length, block)) Ok((uncompressed_length, block))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment