# Matrix Multiplication of a Large Number of Small Matrices

**URL:** <https://discourse.julialang.org/t/matrix-multiplication-of-a-large-number-of-small-matrices/93531>\
**Category:** Performance\
**Tags:** linearalgebra, tullio, column-major\
**Created:** [January 25, 2023, 7:45pm UTC](https://discourse.julialang.org/t/matrix-multiplication-of-a-large-number-of-small-matrices/93531 "2023-01-25T19:45:37Z")\
**Posts on this page:** 1\
**Showing post:** 9

<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:** [January 25, 2023, 9:11pm UTC](https://discourse.julialang.org/t/matrix-multiplication-of-a-large-number-of-small-matrices/93531/9 "2023-01-25T21:11:19Z")

</div>

> [@Dan](#):
>
> I’ve had a good speedup by calculating:
> 
> ```julia
> @tullio AB[k,m] := A[k]*B[k,m]
> @tullio AC[k,l] := A[k]*C[k,l]
> 
> ```

Good point, this is a classic space-time tradeoff — it’s a good idea to cache these products with `A` since they are re-used many times. This sort of thing comes up a lot in broadcast-type operations, e.g. [Why is this Julia code considerably slower than Matlab - #62 by stevengj](https://discourse.julialang.org/t/why-is-this-julia-code-considerably-slower-than-matlab/2365/62)

---

_[View the full topic](https://discourse.julialang.org/t/matrix-multiplication-of-a-large-number-of-small-matrices/93531)._
