🔴 [H4] 大文件生成未使用 BufWriter 导致 benchmark 数据准备极慢 #35
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
问题
generate_test_file生成约 7400 万行,generate_growable_file生成约 15 万行,但都直接对File执行循环writeln!,没有使用BufWriter。影响
大文件生成会产生大量小写 syscall,尤其 5GB 测试文件可能慢几个数量级,影响 benchmark 可用性。
位置
crates/bench/src/data_gen.rs:54crates/bench/src/data_gen.rs:75建议
用
std::io::BufWriter::with_capacity(64 * 1024, file)包装输出文件,并在结束时 flush。Fixed in
6dd87d2.Root cause: writeln! directly on raw File — each line (~70 bytes) triggered a separate write syscall.
Fix: Wrapped all three write-heavy functions with BufWriter::with_capacity(64KB):
Added explicit flush()? + drop(file) before subsequent reads to ensure data visibility and propagate flush errors.