A possible regression in 0.7?

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

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

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
4 Likes