This small package can detect the type instability.
add https://github.com/cometscome/FindingTypeAny.jl
global_var = 0
function myfastfunc()::Float64
i = global_var
for j in 1:10000
i += Float64(j)
end
return i
end
using FindingTypeAny
hasany = findingtypeany(myfastfunc,Any)
println(hasany)
The output is
Variables:
[Symbol("#self#"), Symbol(""), :i, :j]
#1 #self#::var"#myfastfunc#1"{Int64}
#2 ::Union{Nothing, Tuple{Int64, Int64}}
#3 i::Union{Float64, Int64}
Type instability is detected! the variable is i ::Union{Float64, Int64}
#4 j::Int64
true
The input variable f
is a function. the variable t
is the type(s) of the input variable(s) of the function f
.