Improve performance of matrix transforms