FileBuilder::write: 64 KiB write buffer, not 1 MiB
A 1 MiB BufWriter sits above glibc's 128 KiB mmap threshold; depending on allocator history it was mapped afresh by every write, and its page faults (1.6 M vs 13 K over the criterion write_2d_chunked group) made 1 MiB chunked writes 1.35x-1.83x slower than main. With 64 KiB they match main. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
@@ -289,7 +289,12 @@ fn write_file_atomically_with<E: From<std::io::Error>>(
|
||||
let tmp_path = path.with_file_name(tmp_name);
|
||||
|
||||
let result = (|| -> Result<(), E> {
|
||||
let mut f = std::io::BufWriter::with_capacity(1 << 20, std::fs::File::create(&tmp_path)?);
|
||||
// 64 KiB, below glibc's 128 KiB mmap threshold: a 1 MiB buffer was
|
||||
// mapped afresh by each write once the threshold had not risen, and
|
||||
// its page faults made a 1 MiB chunked write 1.6x slower (criterion
|
||||
// `write_2d_chunked/512x512` after the smaller cases, 2026-09-29).
|
||||
// Writes larger than the buffer go straight to the file.
|
||||
let mut f = std::io::BufWriter::with_capacity(64 << 10, std::fs::File::create(&tmp_path)?);
|
||||
write(&mut f)?;
|
||||
f.flush()?;
|
||||
f.get_ref().sync_all()?;
|
||||
|
||||
Reference in New Issue
Block a user