From 9ff7601214c8cbc022308dc62ed8aa321598a1df Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 9 Jun 2019 20:15:36 +0100 Subject: [PATCH] reduce some useless array copies --- OpenSim/Framework/IClientAPI.cs | 3 ++- .../ClientStack/Linden/UDP/LLClientView.cs | 19 +++++++++++--- .../CoreModules/Agent/Xfer/XferModule.cs | 26 +++++-------------- .../Server/IRCClientView.cs | 3 ++- .../OptionalModules/World/NPC/NPCAvatar.cs | 4 ++- OpenSim/Tests/Common/Mock/TestClient.cs | 3 ++- 6 files changed, 31 insertions(+), 27 deletions(-) diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index 8d0cb5afbd..68ca52e2ee 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs @@ -1235,7 +1235,8 @@ namespace OpenSim.Framework /// void SendBulkUpdateInventory(InventoryNodeBase node); - void SendXferPacket(ulong xferID, uint packet, byte[] data, bool isTaskInventory); + void SendXferPacket(ulong xferID, uint packet, + byte[] XferData, int XferDataOffset, int XferDatapktLen, bool isTaskInventory); void SendAbortXferPacket(ulong xferID); diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index 01a9fb6eb8..5d4d5cd823 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs @@ -2886,7 +2886,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP 18 // ID (high frequency bigendian) }; - public void SendXferPacket(ulong xferID, uint packet, byte[] payload, bool isTaskInventory) + public void SendXferPacket(ulong xferID, uint packet, + byte[] XferData, int XferDataOffset, int XferDatapktLen, bool isTaskInventory) { UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint); byte[] data = buf.Data; @@ -2896,7 +2897,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP Utils.UInt64ToBytesSafepos(xferID, data, 7); // 15 Utils.UIntToBytesSafepos(packet, data, 15); // 19 - int len = payload.Length; + + int len = XferDatapktLen; + if (XferDataOffset == 0) // first packet needs to send the total xfer data len + len += 4; + if (len > LLUDPServer.MAXPAYLOAD) // should never happen len = LLUDPServer.MAXPAYLOAD; if (len == 0) @@ -2908,7 +2913,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP { data[19] = (byte)len; data[20] = (byte)(len >> 8); - Buffer.BlockCopy(payload, 0, data, 21, len); + if(XferDataOffset == 0) + { + // need to send total xfer data len + Utils.IntToBytesSafepos(XferData.Length, data, 21); + if (XferDatapktLen > 0) + Buffer.BlockCopy(XferData, XferDataOffset, data, 25, XferDatapktLen); + } + else + Buffer.BlockCopy(XferData, XferDataOffset, data, 21, XferDatapktLen); } buf.DataLength = 21 + len; diff --git a/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs b/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs index 1b6401afd3..94e8064218 100644 --- a/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs +++ b/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs @@ -272,9 +272,9 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer if (!Transfers.ContainsKey(xferID)) { byte[] fileData = NewFiles[fileName].Data; - int burstSize = remoteClient.GetAgentThrottleSilent((int)ThrottleOutPacketType.Asset) >> 11; - if(Transfers.Count > 1) - burstSize /= Transfers.Count; + int burstSize = remoteClient.GetAgentThrottleSilent((int)ThrottleOutPacketType.Task) >> 10; + burstSize = burstSize * (remoteClient.PingTimeMS + 50); + burstSize >>= 9; // ping is ms, 2 round trips XferDownLoad transaction = new XferDownLoad(fileName, fileData, xferID, remoteClient, burstSize); @@ -332,7 +332,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer private int lastBytes; private int lastSentPacket; private int lastAckPacket; - private int burstSize; + private int burstSize; // additional packets, so can be zero private int retries = 0; public XferDownLoad(string fileName, byte[] data, ulong xferID, IClientAPI client, int burstsz) @@ -352,7 +352,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer { if(!isDeleted) { - Data = new byte[0]; + Data = null; isDeleted = true; } } @@ -381,7 +381,6 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer lastBytes = 1024; LastPacket--; } - } lastAckPacket = -1; @@ -422,20 +421,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer pktid = (uint)pkt; } - byte[] transferData; - if(pkt == 0) - { - transferData = new byte[pktsize + 4]; - Array.Copy(Utils.IntToBytes(Data.Length), 0, transferData, 0, 4); - Array.Copy(Data, 0, transferData, 4, pktsize); - } - else - { - transferData = new byte[pktsize]; - Array.Copy(Data, pkt << 10, transferData, 0, pktsize); - } - - Client.SendXferPacket(XferID, pktid, transferData, false); + Client.SendXferPacket(XferID, pktid, Data, pkt << 10, pktsize, true); lastSentPacket = pkt; lastsendTimeMS = now; diff --git a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs index 16be1c80f8..e27bbc3f74 100644 --- a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs +++ b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs @@ -1157,7 +1157,8 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server } - public void SendXferPacket(ulong xferID, uint packet, byte[] data, bool isTaskInventory) + public void SendXferPacket(ulong xferID, uint packet, + byte[] XferData, int XferDataOffset, int XferDatapktLen, bool isTaskInventory) { } diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs index b2a9716a93..d3eb25f671 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs @@ -868,9 +868,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC { } - public virtual void SendXferPacket(ulong xferID, uint packet, byte[] data, bool isTaskInventory) + public virtual void SendXferPacket(ulong xferID, uint packet, + byte[] XferData, int XferDataOffset, int XferDatapktLen, bool isTaskInventory) { } + public virtual void SendAbortXferPacket(ulong xferID) { diff --git a/OpenSim/Tests/Common/Mock/TestClient.cs b/OpenSim/Tests/Common/Mock/TestClient.cs index 3cd525369a..fd14291241 100644 --- a/OpenSim/Tests/Common/Mock/TestClient.cs +++ b/OpenSim/Tests/Common/Mock/TestClient.cs @@ -819,7 +819,8 @@ namespace OpenSim.Tests.Common { } - public virtual void SendXferPacket(ulong xferID, uint packet, byte[] data, bool isTaskInventory) + public virtual void SendXferPacket(ulong xferID, uint packet, + byte[] XferData, int XferDataOffset, int XferDatapktLen, bool isTaskInventory) { }