Julia: inference failure for Float64 constructor?

Created on 23 Jul 2020  Â·  5Comments  Â·  Source: JuliaLang/julia

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)
performance

Most helpful comment

Actually it's a specialization issue for sum not BenchmarkTools this time. @benchmark sum(Float64, $x) gives the same result this time.

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StefanKarpinski picture StefanKarpinski  Â·  3Comments

sbromberger picture sbromberger  Â·  3Comments

felixrehren picture felixrehren  Â·  3Comments

iamed2 picture iamed2  Â·  3Comments

manor picture manor  Â·  3Comments