Understanding the output of @code_warntype

Hard to help if you don’t share a working example of the input data and the full printout of @code_warntype (you omitted the part relevant to the possibly problematic @_8::Any). Don’t share a screenshot of the REPL, copy and paste the text. If space is an issue even with the formatted scroll bar, you can put text in a Hide Details block for us to expand and collapse manually (click gear icon when writing a post/comment).

Right off the bat though, change to @btime LL($(rand(3)), $data) or use a setup to do rand(3) so you’re not profiling that call and its allocations. LL(::Vector{Float64}, ::Vector{Observation}) also seems like a problem for type stability, Observation is an abstract type. EDIT: now you shared the full @code_warntype, type instability does indeed start at:

│    %39 = Main.getfield::Core.Const(getfield)
│    %40 = i::Int64
│    %41 = Base.getindex(data, %40)::Observation
│    %42 = (%39)(%41, :y)::Any

It can’t infer a concrete type for the y field of the abstract Observation. Do you need the vector to hold any instance of Observation? Or is there a particular value for T in Vector{Observation{T}} you can set?

2 Likes