Loop ordering
I never "enforced" this rule but, if possible, we should always take care of the following.
If an Eigen Matrix is stored in ColMajor format (as MatrixXd), we should take particular care in how we loop the matrix.
for(unsigned int i = 0; i < n; ++i) {
for(unsigned int j = 0; j < n; ++j) {
C(i,j) = A(i,j) + B(i,j);
}
}
will give runtimes completely different than
for(unsigned int j = 0; j < n; ++j) {
for(unsigned int i = 0; i < n; ++i) {
C(i,j) = A(i,j) + B(i,j);
}
}
This is because in the second case, the iteration will constantly jump in memory locations, breaking "data locality". https://en.wikipedia.org/wiki/Locality_of_reference
blur
is one of this examples.