I am upgrading my old code to version 0.7. I stumbled onto this little weird difference in performance between Julia 0.6 and 0.7. Here is a MWE.
julia> function h()
@inbounds for i = 1:5:180
j = 5. / sind(i)
length(0:j:360)
end
end
In Julia 0.6,
julia> @btime h()
7.936 μs (0 allocations: 0 bytes)
In Julia 0.7,
julia> @btime h()
21.553 μs (288 allocations: 12.38 KiB)
It is the line length(0:j:360)
that allocated memories and brought down the performance. If j
is fixed, then no memory allocation. So what happened here?
1 Like
rdeits
September 5, 2018, 8:05pm
2
Here’s a shorter example that demonstrates the issue:
julia> @btime 0:$(286.493442):360
499.269 ns (8 allocations: 352 bytes)
0.0:286.493442:286.493442
weirdly, slightly adjusting the step prevents the allocations:
julia> @btime 0:$(286.49344):360
188.621 ns (0 allocations: 0 bytes)
Seems to be the splatting at
function steprangelen_hp(::Type{Float64}, ref::F_or_FF,
step::F_or_FF, nb::Integer,
len::Integer, offset::Integer)
StepRangeLen(TwicePrecision{Float64}(ref...),
twiceprecision(TwicePrecision{Float64}(step...), nb), Int(len), offset)
end
julia> @btime Base.steprangelen_hp(Float64, 2.0, 25.0, 5, 10, 2)
1.470 μs (6 allocations: 320 bytes)
-23.0:25.0:202.0