feat(cp): optimize directory copy by caching file checks and refactoring calls#8805
feat(cp): optimize directory copy by caching file checks and refactoring calls#8805sylvestre merged 5 commits intouutils:mainfrom
Conversation
|
please add a benchmark testing this in a separate PR |
|
GNU testsuite comparison: |
CodSpeed Performance ReportMerging #8805 will improve performances by 4.06%Comparing Summary
Benchmarks breakdown
Footnotes
|
|
add #8807 |
|
Environment: hyperfine 1.19.0, binaries built via cargo build --release (multicall at target/release/coreutils); benchmark inputs copied from docs into target/tmp/cp_bench_src. Command setup: hyperfine --warmup 5 --runs 50 --prepare "rm -rf target/tmp/cp_bench_dst" "/bin/cp -R target/tmp/cp_bench_src target/tmp/cp_bench_dst" "target/release/coreutils cp -R target/tmp/cp_bench_src target/tmp/cp_bench_dst" --export-json target/tmp/cp_benchmark.json. Results: /bin/cp mean 17.2 ms (σ 0.9 ms, min 15.3 ms, max 20.2 ms); coreutils cp mean 10.1 ms (σ 0.5 ms, min 9.24 ms, max 11.3 ms); both commands exited with status 0 in all 50 runs. Relative performance: target/release/coreutils cp ran 1.71 ± 0.12 times faster than /bin/cp on this workload. |
…calls - Add `target_is_file` field to Context to avoid repeated `stat` calls on target - Refactor `copy_direntry` to accept `&Entry` and additional bool params for symlink/directory handling - Use cached value and local variables for cleaner access to entry properties - Pass `created_parent_dirs` to `copy_file` for improved directory creation tracking This reduces filesystem overhead in cp operations when copying directories.
|
GNU testsuite comparison: |

feat: optimize directory copy by caching file checks and refactoring calls
target_is_filefield to Context to avoid repeatedstatcalls on targetcopy_direntryto accept&Entryand additional bool params for symlink/directory handlingcreated_parent_dirstocopy_filefor improved directory creation trackingThis reduces filesystem overhead in cp operations when copying directories.