Implement an ingenious solution to pacekt pool performance suggested by
dlslake.0.6.5-rc1
parent
a1631c496e
commit
c8d44971c4
|
@ -46,8 +46,8 @@ namespace OpenSim.Framework
|
||||||
|
|
||||||
private readonly Dictionary<PacketType, Stack<Packet>> pool = new Dictionary<PacketType, Stack<Packet>>();
|
private readonly Dictionary<PacketType, Stack<Packet>> pool = new Dictionary<PacketType, Stack<Packet>>();
|
||||||
|
|
||||||
private static Dictionary<Type, List<Object>> DataBlocks =
|
private static Dictionary<Type, Stack<Object>> DataBlocks =
|
||||||
new Dictionary<Type, List<Object>>();
|
new Dictionary<Type, Stack<Object>>();
|
||||||
|
|
||||||
static PacketPool()
|
static PacketPool()
|
||||||
{
|
{
|
||||||
|
@ -212,18 +212,18 @@ namespace OpenSim.Framework
|
||||||
{
|
{
|
||||||
lock (DataBlocks)
|
lock (DataBlocks)
|
||||||
{
|
{
|
||||||
if (DataBlocks.ContainsKey(typeof(T)) && DataBlocks[typeof(T)].Count > 0)
|
Stack<Object> s;
|
||||||
|
|
||||||
|
if (DataBlocks.TryGetValue(typeof(T), out s))
|
||||||
{
|
{
|
||||||
T block = (T)DataBlocks[typeof(T)][0];
|
if (s.Count > 0)
|
||||||
DataBlocks[typeof(T)].RemoveAt(0);
|
return (T)s.Pop();
|
||||||
if (block == null)
|
|
||||||
return new T();
|
|
||||||
return block;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new T();
|
DataBlocks[typeof(T)] = new Stack<Object>();
|
||||||
}
|
}
|
||||||
|
return new T();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,17 +234,7 @@ namespace OpenSim.Framework
|
||||||
|
|
||||||
lock (DataBlocks)
|
lock (DataBlocks)
|
||||||
{
|
{
|
||||||
if (!DataBlocks.ContainsKey(typeof(T)))
|
DataBlocks[typeof(T)].Push(block);
|
||||||
{
|
|
||||||
List<Object> l = new List<Object>();
|
|
||||||
l.Add(block);
|
|
||||||
DataBlocks.Add(typeof(T), l);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (DataBlocks[typeof(T)].Count < 500)
|
|
||||||
DataBlocks[typeof(T)].Add(block);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue