Check @code_warntype without @threads since @threads will hide its body since it gets pulled out in a closure
julia> function f()
Threads.@threads for i in 1:5
x = rand() > 0.5 ? 1 : "1" # type unstable
end
end
f (generic function with 1 method)
julia> @code_warntype f() # does not show any type instability
...
julia> function g()
for i in 1:5
x = rand() > 0.5 ? 1 : "1"
end
end
g (generic function with 1 method)
julia> @code_warntype g() # shows type unstable
Variables
#self#::Core.Const(g)
@_2::Union{Nothing, Tuple{Int64, Int64}}
i::Int64
x::Union{Int64, String}
@_5::Union{Int64, String}