Skip to content

cp: open the source once per copy - #14271

Closed
sylvestre wants to merge 1 commit into
uutils:mainfrom
sylvestre:ls
Closed

sylvestre wants to merge 1 commit into
uutils:mainfrom
sylvestre:ls

Conversation

@sylvestre

Copy link
Copy Markdown
Contributor

Every regular-file copy on Linux opened the source three times: once in check_for_data, once in check_sparse_detection, then again in the copy itself. Open it once and thread the descriptor through the probe and the copy, so the strategy and the bytes come from the same fd.

before: open("src", O_RDONLY) x3 + open("dst", O_WRONLY|O_CREAT) x1
after: open("src", O_RDONLY) x1 + open("dst", O_WRONLY|O_CREAT) x1

Copying 3000 small files, 50 runs: 199.9ms +/- 14.9 -> 171.7ms +/- 23.6. The ratio's error bars overlap; the stable signal is system time, 177.3ms -> 146.9ms, with user time unchanged at ~18ms.

Every regular-file copy on Linux opened the source three times: once in
check_for_data, once in check_sparse_detection, then again in the copy
itself. Open it once and thread the descriptor through the probe and the
copy, so the strategy and the bytes come from the same fd.

  before: open("src", O_RDONLY) x3 + open("dst", O_WRONLY|O_CREAT) x1
  after:  open("src", O_RDONLY) x1 + open("dst", O_WRONLY|O_CREAT) x1

Copying 3000 small files, 50 runs: 199.9ms +/- 14.9 -> 171.7ms +/- 23.6.
The ratio's error bars overlap; the stable signal is system time,
177.3ms -> 146.9ms, with user time unchanged at ~18ms.
@codspeed-hq

codspeed-hq Bot commented Aug 30, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 32.93%

⚡ 5 improved benchmarks
✅ 6 untouched benchmarks
⏩ 400 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation cp_recursive_wide_tree[(6000, 800)] 333.8 ms 236 ms +41.41%
Simulation cp_recursive_balanced_tree[(5, 4, 10)] 130.1 ms 96.7 ms +34.51%
Simulation cp_preserve_metadata[(5, 4, 10)] 135.8 ms 102.7 ms +32.24%
Simulation cp_archive_balanced_tree[(5, 4, 10)] 143.2 ms 109.8 ms +30.44%
Simulation cp_recursive_deep_tree[(120, 4)] 22.9 ms 18.1 ms +26.52%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing sylvestre:ls (b3f95a6) with main (bd240c0)

Open in CodSpeed

Footnotes

  1. 400 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 152.18 MB (+996 KB, +0.64%)

Significant per-binary changes:
  comm     1.12 MB ->    2.33 MB  (+1.21 MB, +107.29%)

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Note: The gnu test tests/unexpand/bounded-memory is now being skipped but was previously passing.

@sylvestre

Copy link
Copy Markdown
Contributor Author

moved here #14272

@sylvestre sylvestre closed this Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant