The rider IDE is informing me that the following is inefficient
transform.Translate(moveDirection * speed * Time.smoothDeltaTime);
and wants to re-write it as
transform.Translate(Time.smoothDeltaTime * speed * moveDirection);
Anybody know why ?
Its all multiplications, whats the difference ?
For some context, here is the value of speed and moveDirection
private Vector3 moveDirection = Vector3.left;
private float speed = 2.5f;
I am little confused in understanding why its better ?
Can anyone help?
Thanks
Vector3 has 3 components. X, Y and Z.
Multiplying a Vector3 by a value multiplies the components by that value.
Since there are 2 values beside the vector, order matters not for the result, but does for the number of operations.
That is because vector-first will result in 3+3=6 multiplications:
While vector-last will be 1+3=4 multiplications:
Either way, it's just Rider being paranoid about performance, and that level of optimization, while always welcome, is definitely not required in most cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With