# Performance issue with QRCompactWYQ

**URL:** <https://discourse.julialang.org/t/performance-issue-with-qrcompactwyq/53732>\
**Category:** Performance\
**Tags:** performance, linearalgebra, qr\
**Created:** [January 21, 2021, 4:38pm UTC](https://discourse.julialang.org/t/performance-issue-with-qrcompactwyq/53732 "2021-01-21T16:38:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![theogf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theogf/32/1987_2.png) [@theogf](https://discourse.julialang.org/u/theogf)\
**Post date:** [January 21, 2021, 4:38pm UTC](https://discourse.julialang.org/t/performance-issue-with-qrcompactwyq/53732/1 "2021-01-21T16:38:28Z")

</div>

Hey, since it’s not a bug specifically but a performance issue I post it here instead on Github.  
In the attempt of generating random positive definite matrices I realized there was a huge performance issue with the `QRCompactWYQ` type, here is an example:

```julia
using BenchmarksTools, LinearAlgebra
A = Diagonal(exp.(rand(100)) # Vector of eigenvalues
B, _ = qr(rand(100, 100)) # We obtain a unitary matrix
C = Matrix(B) # For comparison
@btime Symmetric($B * $A * $(B)')
## 149.708 ms (30008 allocations: 25.86 MiB)
@btime Symmetric($C * $A * $(C)')
## 71.447 μs (6 allocations: 156.50 KiB)

```

Which is a 2000x speedup…

---

<div class="post-metadata">

**Author:** ![moeddel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moeddel/32/18641_2.png) [@moeddel](https://discourse.julialang.org/u/moeddel)\
**Post date:** [January 26, 2021, 8:46am UTC](https://discourse.julialang.org/t/performance-issue-with-qrcompactwyq/53732/2 "2021-01-26T08:46:19Z")

</div>

The issue here is that the factor Q of the factorization A=QR is stored in _Compact WY_ format as documented [here](https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/#LinearAlgebra.QRCompactWY). So if you try to multiply the factor Q with another matrix this is **not** done via the fast [BLAS functions](https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/#BLAS-functions), but the slow generic fallback function.

Maybe the documentation should be more clear on this issue and specifically state that Q should be converted into a regular matrix for matrix-matrix operations?

Another way would be to dispatch such operations and do this conversion behind the scenes.
