-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib][fix] Fixed wrong sorting behavior #19107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad the issue could be tracked down so quickly.
We need tests. At minimum, the original example in the bug report. But this raises concern for large gaps in testing and ideally a more systematic approach to closing them would be important.
stdlib/public/core/Sort.swift
Outdated
@@ -507,7 +507,7 @@ extension MutableCollection where Self: RandomAccessCollection { | |||
// If a child is bigger than the current node, swap them and continue sifting | |||
// down. | |||
if largest != i { | |||
swapAt(idx, largest) | |||
swapAt(i, largest) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no reason ever to use the original value idx
, then the first line of the function body should be var idx = idx
. Even if the proposed change here fixes this particular bug, leaving both i
and idx
around is a risk for the next edit made to this function.
@swift-ci please test |
@swift-ci please smoke benchmark |
Build comment file:Performance: -O
Code size: -O
Performance: -Osize
Performance: -Onone
Code size: Swift libraries
How to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the regressions before you merge the PR. Noise: Sometimes the performance results (not code size!) contain false alarms. Unexpected regressions which are marked with '(?)' are probably noise. If you see regressions which you cannot explain you can try to run the benchmarks again. If regressions still show up, please consult with the performance team (@eeckstein). Hardware Overview
|
Hmm, looks like the original improvement in performance that was observed in #18629 originates from the bug and not from making the change from recursion to iteration. |
Merging to fix bug on mater, but we may need to add further tests on top of what's here as a follow-on. |
On the bright side, this restores my hope that we can have a stable sort that doesn't significantly lose out to this one in terms of performance :) |
Fix for this bug.
We were using base index instead of index from current iteration in _siftDown.