Skip to content

Commit 3eb23fe

Browse files
authored
Turbopack: use mmap advise to help the OS preloading (#84379)
### What? Help the OS to prefetch file ranges
1 parent 6d536ed commit 3eb23fe

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

turbopack/crates/turbo-persistence/src/static_sorted_file.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ impl StaticSortedFile {
109109
let mmap = unsafe { Mmap::map(&File::open(&path)?)? };
110110
#[cfg(unix)]
111111
mmap.advise(memmap2::Advice::Random)?;
112+
#[cfg(unix)]
113+
{
114+
let offset = meta.block_offsets_start(mmap.len());
115+
let _ = mmap.advise_range(memmap2::Advice::Sequential, offset, mmap.len() - offset);
116+
}
112117
let file = Self { meta, mmap };
113118
Ok(file)
114119
}
@@ -397,6 +402,12 @@ impl StaticSortedFile {
397402
self.meta.blocks_start()
398403
);
399404
}
405+
#[cfg(unix)]
406+
let _ = self.mmap.advise_range(
407+
memmap2::Advice::Sequential,
408+
block_start,
409+
block_end - block_start,
410+
);
400411
let uncompressed_length = (&self.mmap[block_start..block_start + 4]).read_u32::<BE>()?;
401412
let block = &self.mmap[block_start + 4..block_end];
402413
Ok((uncompressed_length, block))

0 commit comments

Comments
 (0)