feat: Updates to .NET 6 (#843)
* Fixes an issue with moving directories across volumes * Removes usages of WebClient * Removes usages of Cryptographic Providers Note: Even though .NET 6 introduces Xoshiro RNG, there is no way to control the seed. I'll do some reconciliation of Xoshiro so it functions closer to the built in one. For the most part, it has parity though. Benchmarks show there is nothing odd about the implementations, they are within 1ns of each other.
This commit is contained in:
parent
a4d9a3bdc2
commit
c31bf20d0e
35 changed files with 192 additions and 231 deletions
|
|
@ -6,7 +6,7 @@ using Server.Collections;
|
|||
namespace Benchmarks
|
||||
{
|
||||
[MemoryDiagnoser]
|
||||
[SimpleJob(RuntimeMoniker.NetCoreApp50)]
|
||||
[SimpleJob(RuntimeMoniker.Net60)]
|
||||
public class BenchmarkOrderedHashSet
|
||||
{
|
||||
private readonly string[] _iterations = new string[16];
|
||||
|
|
|
|||
|
|
@ -1,90 +0,0 @@
|
|||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
using System.Security.Cryptography;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Jobs;
|
||||
using Server;
|
||||
using Server.Items;
|
||||
|
||||
namespace Benchmarks
|
||||
{
|
||||
[SimpleJob(RuntimeMoniker.NetCoreApp50)]
|
||||
public class BenchmarkFeatureFlags
|
||||
{
|
||||
public Dictionary<Type, FeatureFlag<Item>> m_Dictionary;
|
||||
public ILookup<Type, FeatureFlag<Item>> m_Lookup;
|
||||
|
||||
public Type[] m_TypesToLookUp;
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
RNGCryptoServiceProvider csp = new RNGCryptoServiceProvider();
|
||||
|
||||
string file = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "UOContent.dll");
|
||||
Assembly assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(file);
|
||||
|
||||
m_Dictionary = new Dictionary<Type, FeatureFlag<Item>>();
|
||||
List<FeatureFlag<Item>> m_Types = new List<FeatureFlag<Item>>();
|
||||
m_TypesToLookUp = new Type[100];
|
||||
|
||||
foreach (var type in assembly.GetTypes())
|
||||
{
|
||||
if (typeof(Item).IsAssignableFrom(type))
|
||||
{
|
||||
m_Dictionary.Add(type, new FeatureFlag<Item>());
|
||||
m_Types.Add(new FeatureFlag<Item>{Type = type});
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("Dictionary Size: {0}", m_Dictionary.Count);
|
||||
Console.WriteLine("Lookup Size: {0}", m_Types.Count);
|
||||
|
||||
m_Dictionary.TrimExcess();
|
||||
m_Lookup = m_Types.ToLookup(f => f.Type);
|
||||
Span<byte> bytes = stackalloc byte[4];
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
csp.GetBytes(bytes);
|
||||
m_TypesToLookUp[i] = m_Types[(int)(BinaryPrimitives.ReadUInt32BigEndian(bytes) % m_Types.Count)].Type;
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public FeatureFlag<Item> TestDictionary()
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
m_Dictionary.TryGetValue(typeof(ExplosionPotion), out var ff);
|
||||
if (i == 99)
|
||||
{
|
||||
return ff;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public FeatureFlag<Item> TestLookup()
|
||||
{
|
||||
FeatureFlag<Item> ff;
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
ff = m_Lookup[typeof(ExplosionPotion)].GetEnumerator().Current;
|
||||
if (i == 99)
|
||||
{
|
||||
return ff;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public class FeatureFlag<T> where T : Item
|
||||
{
|
||||
public Type Type { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ using Serilog.Core;
|
|||
|
||||
namespace Benchmarks
|
||||
{
|
||||
[SimpleJob(RuntimeMoniker.NetCoreApp50)]
|
||||
[SimpleJob(RuntimeMoniker.Net60)]
|
||||
public class BenchmarkConsoleLogging
|
||||
{
|
||||
private const string text = "Sample message";
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ using Server.Tests.Network;
|
|||
namespace Benchmarks
|
||||
{
|
||||
[MemoryDiagnoser]
|
||||
[SimpleJob(RuntimeMoniker.NetCoreApp50)]
|
||||
[SimpleJob(RuntimeMoniker.Net60)]
|
||||
public class OutgoingGumpPacketBenchmarks
|
||||
{
|
||||
private static readonly byte[] _layoutBuffer = GC.AllocateUninitializedArray<byte>(0x20000);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using Server.Network;
|
|||
|
||||
namespace Benchmarks
|
||||
{
|
||||
[SimpleJob(RuntimeMoniker.NetCoreApp50)]
|
||||
[SimpleJob(RuntimeMoniker.Net60)]
|
||||
public class BenchmarkPacketBroadcast
|
||||
{
|
||||
public static int SendUnicodeMessage(
|
||||
|
|
|
|||
46
Projects/Benchmarks/Benchmarks/Rng/BenchmarkXoshiro.cs
Normal file
46
Projects/Benchmarks/Benchmarks/Rng/BenchmarkXoshiro.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Jobs;
|
||||
using Server.Random;
|
||||
|
||||
namespace Benchmarks.Benchmarks.Rng
|
||||
{
|
||||
[MemoryDiagnoser]
|
||||
[SimpleJob(RuntimeMoniker.Net60)]
|
||||
public class BenchmarkXoshiro
|
||||
{
|
||||
private Random _random;
|
||||
private Xoshiro256PlusPlus _xoshiro256PlusPlus;
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
_xoshiro256PlusPlus = new Xoshiro256PlusPlus();
|
||||
_random = new Random();
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public int SystemRandomULong() => _random.Next(10000);
|
||||
|
||||
[Benchmark]
|
||||
public int XoshiroRandomULong() => _xoshiro256PlusPlus.Next(10000);
|
||||
|
||||
[Benchmark]
|
||||
public double SystemRandomDouble() => _random.NextDouble();
|
||||
|
||||
[Benchmark]
|
||||
public double XoshiroRandomDouble() => _xoshiro256PlusPlus.NextDouble();
|
||||
|
||||
[Benchmark]
|
||||
public int SystemRandomMinMax() => _random.Next(5000, 85000);
|
||||
|
||||
[Benchmark]
|
||||
public int XoshiroRandomMinMax()
|
||||
{
|
||||
const int min = 5000;
|
||||
const int max = 85000;
|
||||
|
||||
return min + (int)_xoshiro256PlusPlus.Next((uint)(max - min + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ using Server.Text;
|
|||
namespace Benchmarks.BenchmarkText
|
||||
{
|
||||
[MemoryDiagnoser]
|
||||
[SimpleJob(RuntimeMoniker.NetCoreApp50)]
|
||||
[SimpleJob(RuntimeMoniker.Net60)]
|
||||
public class BenchmarkTextEncoding
|
||||
{
|
||||
private const string text =
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using Server.Buffers;
|
|||
namespace Benchmarks.BenchmarkUtilities
|
||||
{
|
||||
[MemoryDiagnoser]
|
||||
[SimpleJob(RuntimeMoniker.NetCoreApp50)]
|
||||
[SimpleJob(RuntimeMoniker.Net60)]
|
||||
public class BenchmarkStringHelpers
|
||||
{
|
||||
private readonly string[] names =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue