perf(NetworkTransform): removing allocations from Command (#2491)

`byte[] payload` will cause a new array to be created when parameters are read, using `ArraySegment<byte>` avoids this.
This commit is contained in:
James Frowen 2020-12-08 08:01:39 +00:00 committed by GitHub
parent 53694e3be3
commit 99f7e9112d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<byte> 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;