Closed tpwrules closed 3 months ago
@dgirardeau Hello, would like to make sure this gets reviewed.
Ah, I forgot about this PR sorry.
Is it only about syntax?
No, there is a little bit of a behavior change. Please see the commit messages.
Sorry I fail to see what's optimized / improved 😅
m_minValue
and m_maxValue
in the future by making sure it is only accessed through getMin()
and getMax()
. I don't yet know if this is worthwhile.minVal
and maxVal
and then assign them to the member variables after the loop. This avoids the need to update the member copies and improves performance by about 30%. I noticed that computing min and max is an operation where a lot of time is spent in my tests so this is a worthwhile improvement.On which OS have you performed your benchmarks? Not sure to grasp why updating the members would be slower 🤔
And just to be sure again, was it in Release or Debug mode?
I checked on x86_64 Linux in Release mode. The compiler has to keep reading and writing the member variables in memory each loop iteration so that they have the latest value, I'm assuming in case of an exception. Usually this is not such a big deal but for how short the loop is it turns into a measurable overhead. If locals are used then they can be kept in registers. I checked the assembly code.
Wow, that's good to know. And I guess it must be the same on Windows if that's the explanation ... I guess there are other places where this happens then.
I did also remove the case through the function where the member variables never get set, maybe having that is why the compiler decided to access memory each iteration. I'm not exactly sure to be honest.
Please see commits for details.