Repository navigation
mv: add --exchange to atomically swap two paths - #13633
Closed
codspeed[bot] wants to merge 2 commits into
Closed
codspeed[bot] wants to merge 2 commits into
codspeed[bot] wants to merge 2 commits into
Conversation
Should make test tests/mv/mv-exchange.sh pass
The same-file detection and the two-path handling in mv issued several stat calls whose result was already available, and assert_not_same_file formatted the quoted target path used in error messages even when the move succeeded. Reuse a single symlink_metadata lookup per path, only build the error string when an error is reported, and make the hardlink comparison helpers in uucore look up the target first so they can return early when it does not exist.
Contributor
Author
Merging this PR will regress 1 benchmark
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | mv_single_file |
63 ms | 65.1 ms | -3.25% |
| ⚡ | Simulation | mv_multiple_to_dir |
12.3 ms | 11 ms | +11.69% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing mv-exchange (d7c0cc7) with main (197eac4)
Footnotes
-
46 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. ↩
|
GNU testsuite comparison: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Should make test tests/mv/mv-exchange.sh pass
Performance follow-up (CodSpeed)
The reported regression on
mv_single_file/mv_force_overwritecomes from the CLI layer, not from the--exchangeimplementation: those benchmarks invokeuumain1000 times per iteration on tiny files, so ~80% of what they measure isclapbuilding and parsing theCommand. Registering one more argument costs ~5.8k instructions per invocation (verified by keeping the whole feature but dropping only the.arg(OPT_EXCHANGE…)registration, which lands exactly on themainnumbers).To offset it, this branch now removes redundant work from
mv's per-file hot path:handle_two_pathsreuses a singlesymlink_metadatacall for the source instead ofis_dir()+is_symlink(), and for the target instead ofis_symlink()+is_dir().target.exists()is only checked when the source is a directory (theexists()result is unused otherwise).assert_not_same_fileno longer formats the quoted "target display" error string on every successful move; it is now built only when an error is actually reported.BackupModecheck inassert_not_same_fileis evaluated before the file-identity checks, so nostatcalls are made when a backup mode makes them irrelevant.renamereplacesto.exists() && to.is_dir() && !to.is_symlink()with a singlesymlink_metadatalookup.uucore::fs::are_hardlinks_to_same_file/are_hardlinks_or_one_way_symlink_to_same_filelook up the target first and return early, instead of always querying both paths (the target is usually the one that does not exist).Measured locally with
codspeed run --mode simulation(instruction counts, deterministic):mv_single_filemv_force_overwritemv_multiple_to_dirmv_directorycpbenefits from theuucorechange as well:cp_recursive_wide_tree−2.4%, the balanced-tree/archive/preserve-metadata benchmarks ~−0.8% each.The remaining ~2.5% on the two single-file benchmarks is the intrinsic cost of registering an extra
clapflag (a few microseconds of CLI setup permvprocess); it does not affect actual move throughput, which is whymv_multiple_to_dir(1000 files in one invocation) is unchanged by the feature. Tests:cargo test --features mv test_mvand--features cp test_cpshow no new failures compared tomain.