diff --git a/crates/clawhdf5/src/writer.rs b/crates/clawhdf5/src/writer.rs index eb05b97..7949d13 100644 --- a/crates/clawhdf5/src/writer.rs +++ b/crates/clawhdf5/src/writer.rs @@ -289,7 +289,12 @@ fn write_file_atomically_with>( 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()?;