# Allocations with BlockArrays multiplication

**URL:** <https://discourse.julialang.org/t/allocations-with-blockarrays-multiplication/87331>\
**Category:** Performance\
**Created:** [September 15, 2022, 7:35pm UTC](https://discourse.julialang.org/t/allocations-with-blockarrays-multiplication/87331 "2022-09-15T19:35:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![moataz-sabry](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moataz-sabry/32/36856_2.png) [@moataz-sabry](https://discourse.julialang.org/u/moataz-sabry)\
**Post date:** [September 15, 2022, 7:35pm UTC](https://discourse.julialang.org/t/allocations-with-blockarrays-multiplication/87331/1 "2022-09-15T19:35:07Z")

</div>

I’m trying to do a vector matrix multiplication and store the result in a block vector from the BlockArrays package. But I ended up with a lot of allocations. Any ideas why?

```julia
using BlockArrays, BenchmarkTools, LinearAlgebra
A = rand(9)
B = rand(19, 9)
C = mortar([rand(10), rand(9)])

@btime mul!($C, $B, $A)
  20.583 μs (342 allocations: 8.02 KiB)

```

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [September 21, 2022, 1:39pm UTC](https://discourse.julialang.org/t/allocations-with-blockarrays-multiplication/87331/2 "2022-09-21T13:39:14Z")

</div>

This is perhaps hitting some fallback method. Could you use a `Vector` in `mul!`, and subsequently create the `BlockVector` from that? This will be much faster, albeit with a few allocations. Something like

```julia
julia> C = zeros(19);

julia> mul!(C, B, A);

julia> mortar([view(C, 1:10), view(C, 11:19)])

```

or

```julia
mortar([C[1:10], C[11:19]])

```

depending on your use case
