Hi guys,
I’m having some issues with performance in my project, part of them are caused by Vector and Mathf functions, but the problem isn’t with the math operations itself, the problem is that they are functions calls, every operation with a Vector is a function call, since the simple calling of a function in C# causes an overhead, if you have a code that requires a lot of them this causes a big impact on fps.
The obvious solution is to convert these operations to simple math operations like:
Vector3 result = vectorA+vectorB;
// to:
Vector3 result = new Vector3(vectorA.x+vectorB.x,vectorA.y+vectorB.y,vectorA.z+vectorB.z);
but the problem is that there are a lot of operations, and they are composed, not only this process will take a lot of time and cause a good amount of bugs during the conversion, as it will make my code terrible to read and to maintain.
In C++ you can define macros for the preprocessor, if C# had them I could use my own implementations to these functions created as macros, this way the compiler would convert all code to simple math operations and avoid the function call overhead, but C# doesn’t have support for macros, does anyone knows an alternative, or have another solution to deal with many Vector operations?