Mirror
Mirror copied to clipboard
perf(PredictedRigidbody): Optimize SmoothFollowPhysicsCopy
-Use square distances for comparison to avoid Math.Sqrt, only calculate the distance after all early out code ran -Dont use Vector3.MoveTowards which calculates some variables we already calculated -Avoid vector ops because current scripting backends are terrible at inlining https://github.com/Unity-Technologies/UnityCsReference/blob/4e215c07ca8e9a32a589043202fd919bdfc0a26d/Runtime/Export/Math/Vector3.cs#L63
Using the Profile Analyzer package and taking a profile frame capture before and after this shows to make SmootFollowPhysics copys mean to be faster by 0.0124ms faster, the max is 0.0195ms faster per call, the function can be called many times per frame when many objects where moving it ran 100+ times.
(times above are in deep profiling)