Getproperty/getfield type instability?

To add to the previous comments: It is also good practice to make all fields of your struct concrete instead of abstract types. So instead of

struct MyStruct
    a::Int
    b::Number
    c::AbstractDict
end

you might want to use

struct MyStruct{NT<:Number,DT<:AbstractDict}
    a::Int
    b::NT
    c::DT
end

This ensures that when the compiler encounters a function f(x::MyStruct) that accesses the fields of x it compile a nice and fast method, depending on what exactly NT and DT are.

1 Like