Performance of struct

Hi!

I read performance tip of struct in julia manual.

https://docs.julialang.org/en/v1/manual/performance-tips/#Avoid-fields-with-abstract-type

According to my understanding, performance can be increased by parameterising the struct, because the compiler can see the types of the struct.

Then, how about doing it like this?

 @kwdef struct El{T<:ComplexF64}
    H:: Array{T,2}
    N :: Int64
    name :: String
end

I want to use such a struct. But I’m worred that performance might decrease if I do that. Let me know if you have any tip.

This looks good, except that since ComplexF64 is a concrete type little is gained by parameterising like this. That is, the only type T that satisfies T <: ComplexF64 is T == ComplexF64.

Did you mean:

struct El{T<:Complex}
  H::Array{T,2}
  N::Int64
  name::String
end

instead? This works just as well as long as T is a concrete type, (which it will be since the only types that satisfy T <: Complex are types like Complex{Float64} which is a concrete type).

Edited: I forgot how Complex works.

3 Likes

Also note that Matrix{T} is an alias for Array{T,2}.

4 Likes