ls: break a tie in the time sort with the name - #14049
Open
luantaraschi wants to merge 1 commit into
Open
Conversation
Merging this PR will degrade performance by 4.09%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | du_summarize_balanced_tree[(5, 4, 10)] |
16.2 ms | 16.9 ms | -4.21% |
| ❌ | Simulation | ls_recursive_long_all_balanced_tree[(6, 4, 15)] |
289.2 ms | 301.2 ms | -3.97% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing luantaraschi:fix/ls-time-sort-tiebreak (c7fbfea) with main (df30282)
Footnotes
-
50 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. ↩
Every other sort in sort_entries falls back on the name when its key ties. Sorting by time did not, so entries sharing a timestamp came out in the order the directory was read in, and since the sort is unstable that order was not guaranteed either. GNU ls breaks the tie with the collation rather than with the bytes, so the comparison Sort::Name already builds is hoisted out of the match and the fallback uses that same one.
cakebaker
force-pushed
the
fix/ls-time-sort-tiebreak
branch
from
August 21, 2026 13:56
4c71932 to
c7fbfea
Compare
|
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.
Every sort in
sort_entriesfalls back on the name when its key ties, apartfrom the sort by time.
Sort::Size,Sort::Version,Sort::ExtensionandSort::Widthall end in a.then(...)on the name;Sort::Timewas a baresort_unstable_by_keyon the timestamp.Entries sharing a timestamp therefore came out in the order the directory was
read in, and since the sort is unstable that order was not guaranteed either.
Four files created at the same mtime, against GNU coreutils 9.7:
ls -tinLC_ALL=CMike alpha bravo zulualpha bravo zulu MikeMike alpha bravo zululs -tinen_US.UTF-8alpha bravo Mike zulualpha bravo zulu Mikealpha bravo Mike zulualpha bravo zulu Mikeis whatls -Uprints, so the old output was the rawdirectory order.
GNU breaks the tie with the collation rather than with the bytes, which is why
the two locales disagree on where
Mikegoes. The comparisonSort::Namealready builds is hoisted out of the match so the fallback uses that same one.
Checked against GNU for
-t,-tr,-t -uand-t -cin both locales, andwith distinct timestamps to confirm the primary ordering is unchanged.