🔴 [H3] scroll_during_append 使用过期 PreadReader 导致增长文件 benchmark 失真 #36
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?
问题
bench_scroll_during_append在追加线程启动前只打开一次PreadReaderPlain。PreadReader的line_index.total_lines和文件大小在 open 时缓存,get_line_impl对idx >= total直接返回None。当
current_line超过初始行数后,后续读取不再触达追加的新内容,而是快速返回None。影响
该 benchmark 实际测到的是“部分真实读取 + 大量 None 快速返回”,无法反映滚动读取追加内容的性能。
位置
crates/bench/src/suites/growth.rs:183crates/bench/src/suites/growth.rs:188crates/bench/src/pread_reader.rs:109建议
周期性刷新 reader 或重新设计测试窗口,让读取逻辑能看到追加后的行数;不要每次迭代都重建索引,否则 benchmark 会变成测 reopen 成本。
修复方案
根因:
PreadReaderCore在open_raw时一次性构建LineIndex,file_size和total_lines之后永不更新。get_line_impl对idx >= total_lines直接返回None,导致 benchmark 在current_line超过初始 150K 行后全部测量None快速返回。修复 (commit
9baec5a):PreadReaderCore::refresh_index(&mut self)— seek 回文件头,完整重建LineIndex,更新file_size,清除读缓存PreadReaderPlain::refresh_index— 转发到 innerReadCache::invalidate— 清空缓存长度,强制下次 get() 执行真实 I/Obench_scroll_during_append:get_line返回Some时记录延迟;None时 sleep 1ms 等待追加max_line_seen > initial_lines,验证确实读到了追加内容refresh_count、none_count、initial_lines、max_line_seen测试: 新增 2 个回归测试(47/47 全部通过):
test_refresh_index_sees_appended_lines— 写 3 行 → 追加 2 行 → refresh → 断言可读新行test_refresh_index_no_change_is_noop— 文件未变时 refresh 不破坏已有索引