From 0657da87eae34f4047da50a5c041fa6bf27f056a Mon Sep 17 00:00:00 2001 From: mischa Date: Thu, 14 Mar 2024 15:07:46 +0800 Subject: [PATCH] perf: PredictedRigidbody RecordState only grabs count once --- .../Components/PredictedRigidbody/PredictedRigidbody.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs b/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs index 226f67b9e..d1ac2fd4e 100644 --- a/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs +++ b/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs @@ -508,9 +508,10 @@ void RecordState() Vector3 velocityDelta = Vector3.zero; Vector3 angularVelocityDelta = Vector3.zero; Quaternion rotationDelta = Quaternion.identity; - if (stateHistory.Count > 0) + int stateHistoryCount = stateHistory.Count; // perf: only grab .Count once + if (stateHistoryCount > 0) { - RigidbodyState last = stateHistory.Values[stateHistory.Count - 1]; + RigidbodyState last = stateHistory.Values[stateHistoryCount - 1]; positionDelta = currentPosition - last.position; velocityDelta = currentVelocity - last.velocity; // Quaternions always need to be normalized in order to be valid rotations after operations