You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JET reports no errors when calling sorted! on a three-element-long Vector{Int}, but Julia seems to allocate something on the heap anyway for some reason.
There are 64 bytes allocated on all of v1.9, v1.10 (beta) and v1.11 (nightly):
julia> include("/tmp/OSN.jl")
Main.OptimalSortingNetworks
julia> const sorted! = OptimalSortingNetworks.sorted!
sorted! (generic function with 2 methods)
julia> const v = [10, 3, 7]
3-element Vector{Int64}:
10
3
7
julia> sorted!(v)
3-element Vector{Int64}:
3
7
10
julia> @allocated sorted!(v)
64
julia> versioninfo()
Julia Version 1.11.0-DEV.777
Commit 96147bbe334 (2023-10-30 18:40 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 8 × AMD Ryzen 3 5300U with Radeon Graphics
WORD_SIZE: 64
LLVM: libLLVM-15.0.7 (ORCJIT, znver2)
Threads: 1 on 8 virtual cores
Environment:
JULIA_NUM_PRECOMPILE_TASKS = 3
JULIA_PKG_PRECOMPILE_AUTO = 0
@profview_allocs sorted!(v) sample_rate=1 indicates that the allocation happens in sorted_impl, in line 76, even though I think everything should be on the stack or even just in registers.
The text was updated successfully, but these errors were encountered:
I love a MWE that I can paste directly into a REPL; thanks!
Adding a type parameter for the type of minmax gives a hint to the compiler to specialize on that type. This diff applied to your second example removes the allocations:
- function Sorted.sorted!(minmax, v::MutableVector{T}) where {T}+ function Sorted.sorted!(minmax::M, v::MutableVector{T}) where {M, T}
A stripped-down version of my package:
EDIT: see a version that is further reduced in the comment below
JET reports no errors when calling
sorted!
on a three-element-longVector{Int}
, but Julia seems to allocate something on the heap anyway for some reason.There are 64 bytes allocated on all of v1.9, v1.10 (beta) and v1.11 (nightly):
@profview_allocs sorted!(v) sample_rate=1
indicates that the allocation happens insorted_impl
, in line 76, even though I think everything should be on the stack or even just in registers.The text was updated successfully, but these errors were encountered: