This discrepancy doesn't seem right:
julia> x = rand(Float16, 10_000);
julia> @btime sum($Float64, $x);
776.911 μs (29999 allocations: 468.73 KiB)
julia> @btime sum($(y -> Float64(y)), $x);
42.417 μs (0 allocations: 0 bytes)
https://github.com/JuliaCI/BenchmarkTools.jl/issues/71
Most likely a benchmarktools bug.
Actually it's a specialization issue for sum not BenchmarkTools this time. @benchmark sum(Float64, $x) gives the same result this time.
Yes, it's not specializing on the function argument when it's a Type. Maybe we should disable the heuristic for Types when the argument is called in the body?
Agreed, seems like called should apply to anything we heuristically limit.
Thanks for this. I never really understood the motivation for not specializing on Type variables, as they are usually important to infer concrete types further down the road. This fix just reduced inference time of some example code in our group from 200 seconds down to the normal inference time when you hard code the specific type.
Most helpful comment
Actually it's a specialization issue for
sumnot BenchmarkTools this time.@benchmark sum(Float64, $x)gives the same result this time.