du: warm OS page cache before timing in benchmarks - #13958
Conversation
First iterations run cold (page cache empty) and subsequent ones hot, creating a bimodal distribution and spurious CI regression alerts. Add warm_cache() to run one untimed traversal before measurement starts.
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
This PR stabilizes du benchmark results by warming the OS page/inode cache before timed measurements, reducing cold-vs-hot bimodal timing distributions that can trigger noisy CI regressions.
Changes:
- Add a
warm_cache()helper that runs one untimeddutraversal prior to benchmarking. - Invoke
warm_cache()in each benchmark after generating the filesystem tree. - Minor import/order and doc-comment punctuation updates.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| /// Run a throwaway traversal to warm the OS page/inode cache before timing. | ||
| fn warm_cache(path: &std::path::Path) { | ||
| let _ = black_box(uumain(get_bench_args(&[&path]).into_iter())); | ||
| } |
| fn du_all_wide_tree(bencher: Bencher, (total_files, total_dirs): (usize, usize)) { | ||
| let temp_dir = TempDir::new().unwrap(); | ||
| let temp_path = temp_dir.path(); | ||
| fs_tree::create_wide_tree(temp_path, total_files, total_dirs); | ||
| warm_cache(temp_path); | ||
|
|
||
| bencher | ||
| .with_inputs(|| get_bench_args(&[&"-a", &temp_path]).into_iter()) | ||
| .bench_values(|args| black_box(uumain(args))); |
| /// Benchmark du on wide directory structures (many files/dirs, shallow) | ||
| /// Run a throwaway traversal to warm the OS page/inode cache before timing. | ||
| fn warm_cache(path: &std::path::Path) { | ||
| let _ = black_box(uumain(get_bench_args(&[&path]).into_iter())); |
|
Binary size comparison: |
|
GNU testsuite comparison: |
Merging this PR will improve performance by 13.15%
Performance Changes
Tip Curious why this is faster? Comment Comparing Footnotes
|
First iterations run cold (page cache empty) and subsequent ones hot, creating a bimodal distribution and spurious CI regression alerts. Add warm_cache() to run one untimed traversal before measurement starts.