Implicit QR code fragments

There have been a lot of questions and confusion over how to speed up a sequence of "data small" Householder rotations.  Here are some code fragments to try to help explain.  They all do the same thing in slightly different ways.  None of them are as fast as they can possibly be although some are getting there.

What we did before

HouseHolderDenseQ[u_,i_,m_] := Module[
{h =u,j,norm},
(* Zero top entries *)
Do[h[[j]]=0.0,{j,1,i-1}];
(* fix jth entry *)
h[[i]]+=Sign[h[[i]]] Norm[h]; 
(* scale vector *)
h = h/Norm[h];
IdentityMatrix[m]-2 Outer[Times,h,h]
]

Quite a lot better using Sparse

HouseHolderSparseQ1[u_,i_,m_] := Module[
{h =u[[i;;m]],j,k},
h[[1]]+=Sign[h[[1]]] Norm[h]; 
(* scale vector *)
h = h/Norm[h];
IdentityMatrix[m]+SparseArray[
Flatten[
Table[
{i+j-1,i+k-1}->-2 h[[j]]h[[k]],
{j,1, Length[h]},
{k,1, Length[h]}
]
],
{m,m}]
]

Submatrices and Sparse

HouseHolderSparseApplyQ1[A_,u_,i_,m_] := Module[
{AA=A[[i;;m,i;;m]],QQ,h =u[[i;;m]],j,k},
h[[1]]+=Sign[h[[1]]] Norm[h]; 
(* scale vector *)
h = h/Norm[h];
QQ=SparseArray[
Flatten[
Table[
{j,k}->-2 h[[j]]h[[k]],
{j,1, Length[h]},
{k,1, Length[h]}
]
]
];
AA+=QQ.AA
]

Pass by reference but fully using it

SetAttributes[HouseHolderSparseApplyQ2,HoldFirst]
HouseHolderSparseApplyQ2[A_,u_,i_,m_] := Module[
{AA=A[[i;;m,i;;m]],QQ,h =u[[i;;m]],j,k},
h[[1]]+=Sign[h[[1]]] Norm[h]; 
(* scale vector *)
h = h/Norm[h];
QQ=SparseArray[
Flatten[
Table[
{j,k}->-2 h[[j]]h[[k]],
{j,1, Length[h]},
{k,1, Length[h]}
]
]
];
AA+=QQ.AA
]

Pass by reference and using it

SetAttributes[HouseHolderSparseApplyQ3,HoldFirst]
HouseHolderSparseApplyQ3[A_,u_,i_,m_] := Module[
{QQ,h =u[[i;;m]],j,k},
h[[1]]+=Sign[h[[1]]] Norm[h]; 
(* scale vector *)
h = h/Norm[h];
QQ=SparseArray[
Flatten[
Table[
{j,k}->-2 h[[j]]h[[k]],
{j,1, Length[h]},
{k,1, Length[h]}
]
]
];
A[[i;;m,i;;m]]+=QQ.A[[i;;m,i;;m]]
]

Testing Code

m=5;
i=3;
A= RandomReal[{-1,1},{m,m}];
ACopy=A;
Q=HouseHolderDenseQ[A[[All,i]],i,m];

More Testing

m=5;
i=3;
A= RandomReal[{-1,1},{m,m}];
ACopy=A;
Q=HouseHolderDenseQ[A[[All,i]],i,m];
Qs=HouseHolderSparseQ1[A[[All,i]],i,m];
As1=HouseHolderSparseApplyQ1[A,A[[All,i]],i,m];
As2=HouseHolderSparseApplyQ2[A,A[[All,i]],i,m];
As3=HouseHolderSparseApplyQ3[ACopy,ACopy[[All,i]],i,m];
MatrixForm[A]
MatrixForm[Q.A]
MatrixForm[Qs.A]
MatrixForm[As1]
MatrixForm[As2]
MatrixForm[As3]
B=A;
B[[i;;m,i;;m]]=As1;
MatrixForm[B]
MatrixForm[ACopy]

Sweep Patterns for Similarity Transformations