# How do you use RadixSort in the Julia v1.9?

**URL:** <https://discourse.julialang.org/t/how-do-you-use-radixsort-in-the-julia-v1-9/95954>\
**Category:** General Usage\
**Created:** [March 12, 2023, 5:42am UTC](https://discourse.julialang.org/t/how-do-you-use-radixsort-in-the-julia-v1-9/95954 "2023-03-12T05:42:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [March 12, 2023, 5:42am UTC](https://discourse.julialang.org/t/how-do-you-use-radixsort-in-the-julia-v1-9/95954/1 "2023-03-12T05:42:12Z")

</div>

```julia
using Base.Sort: RadixSort;
x = rand(100)
sort(x, alg=RadixSort())

```

This should sort `x` but is giving me the error and I don’t understand the issue here. Also, the doc doesn’t currently list RadixSort yet [Sorting and Related Functions · The Julia Language](https://docs.julialang.org/en/v1.9.0-rc1/base/sort/#Alternate-orderings)

```julia
        
ERROR: ArgumentError: mn is needed but has not been computed
Stacktrace:
 [1] _mn(v::Vector{Float64}, o::Base.Order.ForwardOrdering, kw::NamedTuple{(:scratch, :lo, :hi), Tuple{Nothing, Int64, Int64}})
   @ Base.Sort .\sort.jl:430
 [2] _sort!(v::Vector{Float64}, a::RadixSort, o::Base.Order.ForwardOrdering, kw::NamedTuple{(:scratch,), Tuple{Nothing}})
   @ Base.Sort .\sort.jl:924
 [3] sort!(v::Vector{Float64}; alg::RadixSort, lt::Function, by::Function, rev::Nothing, order::Base.Order.ForwardOrdering, scratch::Nothing)
   @ Base.Sort .\sort.jl:1374
 [4] sort(v::Vector{Float64}; kws::Base.Pairs{Symbol, RadixSort, Tuple{Symbol}, NamedTuple{(:alg,), Tuple{RadixSort}}})
   @ Base.Sort .\sort.jl:1400
 [5] top-level scope
   @ c:\git\SortingLab\test\tests.jl:8

```

---

<div class="post-metadata">

**Author:** ![Lilith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lilith/32/27492_2.png) [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Post date:** [October 5, 2025, 12:03pm UTC](https://discourse.julialang.org/t/how-do-you-use-radixsort-in-the-julia-v1-9/95954/2 "2025-10-05T12:03:42Z")

</div>

> Context

RadixSort is an internal performance optimization. There’s no extensible API to define radixing on custom types and no public way to opt-in to using it when Julia thinks it’s not the best algorithm for the task at hand.

> “How do you use RadixSort in Julia v1.9?”

This will use RadixSort in Julia 1.9:

```julia-auto
x = rand(1000)
sort(x)

```

The reason we need `x = rand(1000)` instead of `x = rand(100)` is because RadixSort is not a great algorithm for small inputs and so we don’t use it for small inputs.

> How can I tell Julia to use RadixSort even when Julia thinks it’s not the right choice

The only good reason I can think of to do this is if you are investigating sorting performance for sorting-related research (e.g. trying to make `Base.sort` faster). However, if you insist, it is possible to do this, while depending on Julia internals (i.e. your code may break in a minor release)

Here are a couple ways to do this:

```julia-auto
x = rand(100)
@assert v"1.9" <= VERSION < v"1.13"
sort(x, alg=Base.Sort.IEEEFloatOptimization(Base.Sort.ComputeExtrema(Base.Sort.RadixSort())))

# or

x = rand(UInt, 100)
@assert v"1.9" <= VERSION < v"1.13"
Base.Sort.radix_sort!(x, extrema(eachindex(x))..., unsigned(8*Base.elsize(x)), similar(x), 0)

```
