Skip to content

Commit

Permalink
Stabilize, optimize, and increase robustness of QuickSort (#45222)
Browse files Browse the repository at this point in the history
* Change partitioning scheme to use scratch space

* Randomize pivot selection with a hash-based fallback for when `rand` is unavailable

* remove an unnecessary sorting operation in typealias construction in base/show.jl

* Seed rng before generating precompile statements

* Add presorted check to avoid performance regressions

* test invalid `lt` to close #11429 & #32675

* test that PartialQuickSort is stable

* update radix sort dispatch heuristics because quicksort is now faster and the primary competition

Co-authored-by: Petr Vana <petvana@centrum.cz>
Co-authored-by: Oscar Smith <oscardssmith@gmail.com>
  • Loading branch information
3 people authored Oct 15, 2022
1 parent 05cfe24 commit 35431bf
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 188 deletions.
4 changes: 3 additions & 1 deletion base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ since it is not idiomatic to explicitly export names from `Main`.
See also: [`@locals`](@ref Base.@locals), [`@__MODULE__`](@ref).
"""
names(m::Module; all::Bool = false, imported::Bool = false) =
sort!(ccall(:jl_module_names, Array{Symbol,1}, (Any, Cint, Cint), m, all, imported))
sort!(unsorted_names(m; all, imported))
unsorted_names(m::Module; all::Bool = false, imported::Bool = false) =
ccall(:jl_module_names, Array{Symbol,1}, (Any, Cint, Cint), m, all, imported)

isexported(m::Module, s::Symbol) = ccall(:jl_module_exports_p, Cint, (Any, Any), m, s) != 0
isdeprecated(m::Module, s::Symbol) = ccall(:jl_is_binding_deprecated, Cint, (Any, Any), m, s) != 0
Expand Down
4 changes: 2 additions & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ function make_typealias(@nospecialize(x::Type))
end
x isa UnionAll && push!(xenv, x)
for mod in mods
for name in names(mod)
for name in unsorted_names(mod)
if isdefined(mod, name) && !isdeprecated(mod, name) && isconst(mod, name)
alias = getfield(mod, name)
if alias isa Type && !has_free_typevars(alias) && !print_without_params(alias) && x <: alias
Expand Down Expand Up @@ -810,7 +810,7 @@ function make_typealiases(@nospecialize(x::Type))
end
x isa UnionAll && push!(xenv, x)
for mod in mods
for name in names(mod)
for name in unsorted_names(mod)
if isdefined(mod, name) && !isdeprecated(mod, name) && isconst(mod, name)
alias = getfield(mod, name)
if alias isa Type && !has_free_typevars(alias) && !print_without_params(alias) && !(alias <: Tuple)
Expand Down
Loading

0 comments on commit 35431bf

Please sign in to comment.