# What is the performance penalty for using MVector and MMatrix vs SVector and SMatrix

**URL:** https://discourse.julialang.org/t/what-is-the-performance-penalty-for-using-mvector-and-mmatrix-vs-svector-and-smatrix/89490
**Category:** General Usage
**Tags:** question
**Created:** [October 29, 2022, 12:38pm UTC](https://discourse.julialang.org/t/what-is-the-performance-penalty-for-using-mvector-and-mmatrix-vs-svector-and-smatrix/89490 "2022-10-29T12:38:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![prittjam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prittjam/32/21267_2.png) [@prittjam](https://discourse.julialang.org/u/prittjam)
#### Post date: [October 29, 2022, 12:38pm UTC](https://discourse.julialang.org/t/what-is-the-performance-penalty-for-using-mvector-and-mmatrix-vs-svector-and-smatrix/89490/1 "2022-10-29T12:38:19Z")

</div>

How do the two data types store data underneath?

As a more general question, when is an SVector or SMatrix allocated on the stack? Are MVector and MMatrix ever constructed on the stack?

---

<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: [October 29, 2022, 12:48pm UTC](https://discourse.julialang.org/t/what-is-the-performance-penalty-for-using-mvector-and-mmatrix-vs-svector-and-smatrix/89490/2 "2022-10-29T12:48:16Z")

</div>

If the mutable type does not escape, it can be stack allocated. For example: [Help with allocations (variable length least squares) - #6 by lmiq](https://discourse.julialang.org/t/help-with-allocations-variable-length-least-squares/57931/6)

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [October 30, 2022, 10:24pm UTC](https://discourse.julialang.org/t/what-is-the-performance-penalty-for-using-mvector-and-mmatrix-vs-svector-and-smatrix/89490/3 "2022-10-30T22:24:53Z")

</div>

Most of the time MVector is fast, but in some cases not. So benchmark your code and make sure there are no allocations.
