Skip to content

Commit

Permalink
perf: using pool for send notify
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Jun 23, 2021
1 parent 821e2d2 commit ac000eb
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Assets/Mirage/Runtime/SocketLayer/AckSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,21 @@ public INotifyToken SendNotify(byte[] inPacket, int inOffset, int inLength)
var token = new NotifyToken();
ushort sequence = (ushort)sentAckablePackets.Enqueue(new AckablePacket(token));

// todo check packet size is within MTU
// todo use pool to stop allocations
byte[] outPacket = new byte[inLength + HEADER_SIZE_NOTIFY];
Buffer.BlockCopy(inPacket, inOffset, outPacket, HEADER_SIZE_NOTIFY, inLength);
using (ByteBuffer buffer = bufferPool.Take())
{
byte[] outPacket = buffer.array;
Buffer.BlockCopy(inPacket, inOffset, outPacket, HEADER_SIZE_NOTIFY, inLength);

int outOffset = 0;
int outOffset = 0;

ByteUtils.WriteByte(outPacket, ref outOffset, (byte)PacketType.Notify);
ByteUtils.WriteByte(outPacket, ref outOffset, (byte)PacketType.Notify);

ByteUtils.WriteUShort(outPacket, ref outOffset, sequence);
ByteUtils.WriteUShort(outPacket, ref outOffset, LatestAckSequence);
ByteUtils.WriteULong(outPacket, ref outOffset, AckMask);
ByteUtils.WriteUShort(outPacket, ref outOffset, sequence);
ByteUtils.WriteUShort(outPacket, ref outOffset, LatestAckSequence);
ByteUtils.WriteULong(outPacket, ref outOffset, AckMask);

Send(outPacket, outPacket.Length);
Send(outPacket, outOffset + inLength);
}

return token;
}
Expand Down

0 comments on commit ac000eb

Please sign in to comment.