Assignment inside a loop can be a problem, but I'm not familiar with the library. Moving it outside the for loop and doing field assignments manually can help. It would also help move the transforms out of the loop.
Edit:
This is more like what I was thinking.
// Apply Matrix glm::vec4 transformed; glm::mat4 translation = m_rotation * m_translation; for ( int i=0; i<6; i++ ) { transformed.x = vertices[i].x; transformed.y = vertices[i].y; transformed.z = vertices[i].z; transformed.w = 1.f; // ? /* I can't find docs, but assume they have an in-place multiply transformed.mult(translation); // */ vertices[i].x = transformed.x; vertices[i].y = transformed.y; }
Perhaps, perhaps, the task does not allow the compiler to embed or deploy something. I guess the multiplication is large enough to knock this out of the command cache. Indeed, if you start talking about cache sizes, you will not be stable on many platforms.
You can try to duplicate some stack and do more, fewer loops.
glm::vec4 transformed[6]; for (size_t i = 0; i < 6; i++) { transformed[i].x = vertices[i].x; transformed[i].y = vertices[i].y; transformed[i].z = vertices[i].z; transformed.w = 1.f; // ? } glm::mat4 translation = m_rotation * m_translation; for (size_t i = 0; i < 6; i++) { /* I can't find docs, but assume they have an in-place multiply transformed.mult(translation); // */ } for (size_t i = 0; i < 6; i++) { vertices[i].x = transformed[i].x; vertices[i].y = transformed[i].y; }
As Jason said, manually unrolling these loops would be interesting.
I really don't think you will see an improvement in order on any of these changes.
I suspect that calling this function is less important than speeding up this function. The fact that you have it requires checking the transformation inside this function, makes me think that this is probably relevant.
When you have high-level problems like this in low-level code, you end up just blindly repeating this method, thinking it is free. Regardless of whether your assumptions about how often the conversion is needed are true, they can be completely wrong.
The reality is that you should just call this method once. You must apply Transform when you want to apply Transform. You should not call applyTransform when you can apply Transform. Interfaces should be a contract, consider them as such.