# Performance of struct

**URL:** <https://discourse.julialang.org/t/performance-of-struct/111873>\
**Category:** New to Julia\
**Created:** [March 20, 2024, 1:09pm UTC](https://discourse.julialang.org/t/performance-of-struct/111873 "2024-03-20T13:09:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TongTongYee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tongtongyee/32/207244_2.png) [@TongTongYee](https://discourse.julialang.org/u/TongTongYee)\
**Post date:** [March 20, 2024, 1:09pm UTC](https://discourse.julialang.org/t/performance-of-struct/111873/1 "2024-03-20T13:09:34Z")

</div>

Hi!

I read performance tip of struct in julia manual.

[https://docs.julialang.org/en/v1/manual/performance-tips/#Avoid-fields-with-abstract-type](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?

```julia
 @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.

---

<div class="post-metadata">

**Author:** ![screw\_dog](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/screw_dog/32/48119_2.png) [@screw\_dog](https://discourse.julialang.org/u/screw_dog)\
**Post date:** [March 20, 2024, 1:16pm UTC](https://discourse.julialang.org/t/performance-of-struct/111873/2 "2024-03-20T13:16:00Z")

</div>

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:

```julia
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.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [March 20, 2024, 1:17pm UTC](https://discourse.julialang.org/t/performance-of-struct/111873/3 "2024-03-20T13:17:57Z")

</div>

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