# Function on matrix transpose and performance

**URL:** <https://discourse.julialang.org/t/function-on-matrix-transpose-and-performance/20068>\
**Category:** General Usage\
**Tags:** performance\
**Created:** [January 25, 2019, 2:33am UTC](https://discourse.julialang.org/t/function-on-matrix-transpose-and-performance/20068 "2019-01-25T02:33:12Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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, 2019, 3:20am UTC](https://discourse.julialang.org/t/function-on-matrix-transpose-and-performance/20068/4 "2019-01-25T03:20:03Z")

</div>

> [@tlienart](#):
>
> rather that I don’t understand why adding the `collect` makes it faster. It seems a bit counterintuitive to me since it fully allocates the object?

It should be even faster if you call `copy(transpose(X))` — Julia has an optimized `copy(A)` routine for transposed arrays that has good cache-line utilization. Basically, this is the problem of optimized out-of-place transposition, and has been extensively studied; the optimum is some kind of blocked or recursive cache-oblivious algorithm, and a [cache-oblivious transpose routine](https://github.com/JuliaLang/julia/blob/master/stdlib/LinearAlgebra/src/transpose.jl) is implemented in Julia (from [#6690](https://github.com/JuliaLang/julia/pull/6690), I believe).

It doesn’t look like `collect` calls this optimized routine, but it probably should.

> [@tlienart](#):
>
> Edit: yes it seems to be version related, I get similar results to yours on 1.1 and no discrepancy in terms of time between using `Xt` and `collect(transpose(X))` . Should I report this somewhere?

Did it get faster or slower in 1.2? If `maximum(X)` got much faster, the question is why and whether that can be replicated for other memory layouts. If, on the other hand, it got much slower in 1.2, then you should certainly file a performance issue.

---

_[View the full topic](https://discourse.julialang.org/t/function-on-matrix-transpose-and-performance/20068)._
