BigUglySpider / EmuLibs

Selection of libraries designed to be used with Emu projects. This was originally a Math library only, but has since been changed to hold all Emu libraries to enable consistency in changes to dependencies (such as EmuCore modifications).
https://biguglyspider.github.io/math
0 stars 0 forks source link

VectorClamp potentially underperforming compared to VectorClampMin followed by VectorClampMax #7

Closed BigUglySpider closed 3 years ago

BigUglySpider commented 3 years ago

Initial mention

The initial mention of this issue was mentioned in commit d9199146748a09dd815091c8052a5741b58e5ac2, and may be found verbatim below:

VectorClamp is potentially underperforming, as it can be beaten by VectorClampMin followed by VectorClampMax.

However, this only happens in release mode after the first load of iterations of tests. VectorClamp is always faster than the combination on the first time around.

Additionally, VectorClamp is always faster in debug mode. As such, it is likely that the performance difference is due to some unlikely-to-occur-in-the-wild situation that the compiler is optimising the full program for - after all, it's unlikely one would ever be doing these millions of exact same operations across multiple vectors at a frequent rate.

Additional info

The compiler missing the optimisation in VectorClamp is potentially a result of VectorClamp's extensive use of (inline) references to keep the code somewhat cleaner. It may be worthwhile to implement the underlying VectorClamp in a single function similar to how Lerp handles it.

BigUglySpider commented 3 years ago

This is not being looked at for the moment, and no efforts are being made toward testing it. This is something to leave for a live environment to get accurate readings, which will be available in future endeavours.