Skip to content

Commit 2ab4105

Browse files
authored
Fix typo in heuristics of BracketedSort (#52494)
The impact of this typo was a) massively decreased performance that was b) predicted by heuristic dispatch, resulting in this algorithm not being dispatched too. I introduced this typo in 187e8c2 after performing all the benchmarking and before merging.
1 parent b57f8d1 commit 2ab4105

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

base/sort.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ function _sort!(v::AbstractVector, a::BracketedSort, o::Ordering, kw)
12621262
k = cbrt(ln)
12631263
k2 = round(Int, k^2)
12641264
k2ln = k2/ln
1265-
offset = .15k2*top_set_bit(k2) # TODO for further optimization: tune this
1265+
offset = .15k*top_set_bit(k2) # TODO for further optimization: tune this
12661266
lo_signpost_i, hi_signpost_i =
12671267
(floor(Int, (tar - lo) * k2ln + lo + off) for (tar, off) in
12681268
((minimum(target), -offset), (maximum(target), offset)))

test/sorting.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -721,10 +721,9 @@ end
721721
for alg in safe_algs
722722
@test sort(1:n, alg=alg, lt = (i,j) -> v[i]<=v[j]) == perm
723723
end
724-
# This could easily break with minor heuristic adjustments
725-
# because partialsort is not even guaranteed to be stable:
726-
@test partialsort(1:n, 172, lt = (i,j) -> v[i]<=v[j]) == perm[172]
727-
@test partialsort(1:n, 315:415, lt = (i,j) -> v[i]<=v[j]) == perm[315:415]
724+
# Broken by the introduction of BracketedSort in #52006 which is unstable
725+
@test_broken partialsort(1:n, 172, lt = (i,j) -> v[i]<=v[j]) == perm[172]
726+
@test_broken partialsort(1:n, 315:415, lt = (i,j) -> v[i]<=v[j]) == perm[315:415]
728727

729728
# lt can be very poorly behaved and sort will still permute its input in some way.
730729
for alg in safe_algs

0 commit comments

Comments
 (0)