From 99f7e9112d530c74e519588eeab2362ed6b19341 Mon Sep 17 00:00:00 2001 From: James Frowen Date: Tue, 8 Dec 2020 08:01:39 +0000 Subject: [PATCH] perf(NetworkTransform): removing allocations from Command (#2491) `byte[] payload` will cause a new array to be created when parameters are read, using `ArraySegment` avoids this. --- Assets/Mirror/Components/NetworkTransformBase.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Assets/Mirror/Components/NetworkTransformBase.cs b/Assets/Mirror/Components/NetworkTransformBase.cs index 5da7d0a59..957007d36 100644 --- a/Assets/Mirror/Components/NetworkTransformBase.cs +++ b/Assets/Mirror/Components/NetworkTransformBase.cs @@ -16,6 +16,7 @@ // * Only way for smooth movement is to use a fixed movement speed during // interpolation. interpolation over time is never that good. // +using System; using UnityEngine; namespace Mirror @@ -195,7 +196,7 @@ public override void OnDeserialize(NetworkReader reader, bool initialState) // local authority client sends sync message to server for broadcasting [Command] - void CmdClientToServerSync(byte[] payload) + void CmdClientToServerSync(ArraySegment payload) { // Ignore messages from client if not in client authority mode if (!clientAuthority) @@ -346,7 +347,7 @@ void Update() SerializeIntoWriter(writer, targetComponent.transform.localPosition, targetComponent.transform.localRotation, targetComponent.transform.localScale); // send to server - CmdClientToServerSync(writer.ToArray()); + CmdClientToServerSync(writer.ToArraySegment()); } } lastClientSendTime = Time.time;