# Julia hangs while displaying an SMatrix

**URL:** https://discourse.julialang.org/t/julia-hangs-while-displaying-an-smatrix/45918
**Category:** General Usage
**Created:** [September 1, 2020, 7:27pm UTC](https://discourse.julialang.org/t/julia-hangs-while-displaying-an-smatrix/45918 "2020-09-01T19:27:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)
#### Post date: [September 1, 2020, 7:27pm UTC](https://discourse.julialang.org/t/julia-hangs-while-displaying-an-smatrix/45918/1 "2020-09-01T19:27:20Z")

</div>

The following code hangs on Windows 10 and Julia 1.5.0 on two different computers:

```julia
using StaticArrays

struct Points{N,T<:Number}
    p::SMatrix{3,N,T}
end
Points(x::Matrix{T}) where {T} = Points{size(x,2),T}(x)

points = Points(randn(3,2000))
points.p

```

`points = Points(randn(3,1000)); points.p` is slow but returns.

Am I doing something wrong?

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [September 1, 2020, 7:45pm UTC](https://discourse.julialang.org/t/julia-hangs-while-displaying-an-smatrix/45918/2 "2020-09-01T19:45:52Z")

</div>

From the StaticArrays manual:

> Note that in the current implementation, working with large StaticArrays puts a lot of stress on the compiler, and becomes slower than Base.Array as the size increases. A very rough rule of thumb is that you should consider using a normal Array for arrays larger than 100 elements.

A static array with 6000 elements is waaaaaaay too large. You’re essentially creating a 6000-element tuple, and the compiler is really struggling.

At least in the example you’ve given, there’s no reason at all to use an SMatrix for this. A plain `Matrix{T}` or a `Vector{SVector{3, T}}` would both work well and would not stress the compiler at all.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [September 2, 2020, 12:34am UTC](https://discourse.julialang.org/t/julia-hangs-while-displaying-an-smatrix/45918/3 "2020-09-02T00:34:19Z")

</div>

StaticArrays aren’t a panacea that you should drop into every array computation to make them faster.

They are useful for tiny arrays (e.g. coordinate-vectors in 3d geometry) where the overhead of allocating arrays or even just looping is comparable to the cost of elementary array operations like `vector + vector`. For large arrays this overhead is relatively unimportant, especially if you do in-place operations, and the costs of StaticArrays (e.g. in compile time and instruction-cache overutilization) outweigh the benefits.

---

<div class="post-metadata">

### Author: ![mateuszbaran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mateuszbaran/32/221842_2.png) [@mateuszbaran](https://discourse.julialang.org/u/mateuszbaran)
#### Post date: [September 4, 2020, 7:37am UTC](https://discourse.julialang.org/t/julia-hangs-while-displaying-an-smatrix/45918/4 "2020-09-04T07:37:29Z")

</div>

[https://github.com/mateuszbaran/HybridArrays.jl](https://github.com/mateuszbaran/HybridArrays.jl) is designed exactly for the case of some dimensions being small and some being large. It’s much more convenient than `Vector{SVector{3, T}}`.
