I understand that because matrices in Julia are stored in column major order, it is best to iterate over them in column major order.

What is less clear to me is why one would want to store matrices in column major order in the first place.

Consider a matrix-vector multiplication

Ax = \begin{pmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{pmatrix} \begin{pmatrix}x_{11} \\ x_{21} \\ x_{21} \end{pmatrix} = \begin{pmatrix} b_{11} \\ b_{21} \\ b_{21}\end{pmatrix}.

To compute the first entry of b, we take the dot product of the first row of A with x. When A is stored in row-major order, the first row of A will be contiguous in memory. And the column vector x will still be contiguous in memory because there is only one entry per row. But if we stored things in column-major order, then only x would be contiguous memory.

Doesnâ€™t this mean that column-major ordering makes matrix multiplication less cache-friendly? And I would think matrix multiplication is the most common task done with matrices, so that we would want to choose the storage method which is best for matrix multiplication.