Add image processing and memory management features
Added new namespace `Misaki.HighPerformance.Image` for image processing, including classes for animated GIF handling and memory management. Added `AnimatedFrameResult` class for individual frames in animated images. Added `AnimatedGifEnumerator` class for enumerating frames in animated GIFs. Added `ColorComponents` enum for different color formats. Added `ImageInfo` struct for image dimensions and color components. Added `CRuntime` class for low-level memory management functions. Added `MemoryStats` class to track memory allocation statistics. Added utility functions for creating multi-dimensional arrays. Added new structures for fixed-size UTF-8 encoded strings. Added benchmarking classes to test new memory management features. Changed `StbImage.cs` to include new namespaces and functionality for image data manipulation. Changed project files to target .NET 9.0 and enable new features. Changed `Arena.cs` and `DynamicArena.cs` to use `nuint` for size parameters. Changed `BitSet.cs` to enhance bit manipulation methods. Changed `Program.cs` to run `FunctionPtrBenchmark` for performance testing. Removed memory tracking code from `AllocationManager.cs`, including the `_allocated` dictionary and related logic. Removed `Free` method from `IAllocator.cs` interface. Removed `UNSAFE_COLLECTION_CHECK` preprocessor directive from the codebase. Refactored various files to improve organization, moving from `Unsafe` to `LowLevel` namespace. Refactored `MemoryUtilities` class to include new memory operation methods. Refactored `UnsafeUtilities.cs` to support new collection structures.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Misaki.HighPerformance.Unsafe.Buffer;
|
||||
using Misaki.HighPerformance.Unsafe.Collections;
|
||||
using Misaki.HighPerformance.LowLevel.Buffer;
|
||||
using Misaki.HighPerformance.LowLevel.Collections;
|
||||
|
||||
namespace Misaki.HighPerformance.Test;
|
||||
|
||||
@@ -13,7 +13,6 @@ public unsafe class CollectionBenchmark
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
AllocationManager.Initialize();
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
@@ -34,7 +33,8 @@ public unsafe class CollectionBenchmark
|
||||
{
|
||||
array[i] = i;
|
||||
}
|
||||
AllocationManager.ResetCurrent();
|
||||
|
||||
AllocationManager.TempAllocator.Reset();
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
|
||||
47
Misaki.HighPerformance.Test/FunctionPtrBenchmark.cs
Normal file
47
Misaki.HighPerformance.Test/FunctionPtrBenchmark.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Misaki.HighPerformance.LowLevel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Misaki.HighPerformance.Test;
|
||||
|
||||
[MemoryDiagnoser]
|
||||
public unsafe class FunctionPtrBenchmark
|
||||
{
|
||||
private delegate float FunctionPointerDelegate(float a, float b);
|
||||
|
||||
private float _sink;
|
||||
|
||||
private FunctionPointer<FunctionPointerDelegate> _addManaged;
|
||||
private delegate* unmanaged<float, float, float> _addUnmanaged;
|
||||
|
||||
public FunctionPtrBenchmark()
|
||||
{
|
||||
_addManaged = new(Marshal.GetFunctionPointerForDelegate<FunctionPointerDelegate>(Add));
|
||||
_addUnmanaged = &AddUnmanaged;
|
||||
}
|
||||
|
||||
private float Add(float a, float b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
private static float AddUnmanaged(float a, float b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public void InvokeManaged()
|
||||
{
|
||||
_sink = _addManaged.Invoke(1.0f, 2.0f);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void InvokeUnmanaged()
|
||||
{
|
||||
_sink = _addUnmanaged(1.0f, 2.0f);
|
||||
}
|
||||
}
|
||||
114
Misaki.HighPerformance.Test/HashMapBenchmark.cs
Normal file
114
Misaki.HighPerformance.Test/HashMapBenchmark.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Misaki.HighPerformance.LowLevel.Collections;
|
||||
|
||||
namespace Misaki.HighPerformance.Test;
|
||||
|
||||
public class HashMapBenchmark
|
||||
{
|
||||
private UnsafeHashMap<int, float> _unsafeHashMap;
|
||||
private Dictionary<int, float> _dictionary = null!;
|
||||
|
||||
[Params(10, 100, 1000)]
|
||||
public int count;
|
||||
|
||||
[IterationSetup]
|
||||
public void Setup()
|
||||
{
|
||||
//_unsafeHashMap = new UnsafeHashMap<int, float>(count, Allocator.Persistent);
|
||||
_dictionary = new Dictionary<int, float>(count);
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
//_unsafeHashMap.Add(i, i);
|
||||
_dictionary.Add(i, i);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void UnsafeHashMapAdd()
|
||||
{
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
_unsafeHashMap.Add(count + i, i);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public void DictionaryAdd()
|
||||
{
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
_dictionary.Add(count + i, i);
|
||||
}
|
||||
}
|
||||
|
||||
public void UnsafeHashMapRemove()
|
||||
{
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
_unsafeHashMap.Remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
public void DictionaryRemove()
|
||||
{
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
_dictionary.Remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
public void UnsafeHashMapRandomRead()
|
||||
{
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var value = Random.Shared.Next(0, count);
|
||||
if (_unsafeHashMap.TryGetValue(value, out var result))
|
||||
{
|
||||
var r2 = result + result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DictionaryRandomRead()
|
||||
{
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var value = Random.Shared.Next(0, count);
|
||||
if (_dictionary.TryGetValue(value, out var result))
|
||||
{
|
||||
var r2 = result + result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UnsafeHashMapRandomWrite()
|
||||
{
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var value = Random.Shared.Next(0, count);
|
||||
if (_unsafeHashMap.TryGetValue(value, out var result))
|
||||
{
|
||||
_unsafeHashMap[value] = result + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DictionaryRandomWrite()
|
||||
{
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var value = Random.Shared.Next(0, count);
|
||||
if (_dictionary.TryGetValue(value, out var result))
|
||||
{
|
||||
_dictionary[value] = result + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[IterationCleanup]
|
||||
public void Cleanup()
|
||||
{
|
||||
//_unsafeHashMap.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using Misaki.HighPerformance.Jobs;
|
||||
using Misaki.HighPerformance.Unsafe.Collections;
|
||||
using Misaki.HighPerformance.LowLevel.Collections;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
|
||||
@@ -14,7 +14,10 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Misaki.HighPerformance.Unsafe\Misaki.HighPerformance.Unsafe.csproj" />
|
||||
<ProjectReference Include="..\Misaki.HighPerformance.Image\Misaki.HighPerformance.Image.csproj" />
|
||||
<ProjectReference Include="..\Misaki.HighPerformance.Jobs\Misaki.HighPerformance.Jobs.csproj" />
|
||||
<ProjectReference Include="..\Misaki.HighPerformance.LowLevel\Misaki.HighPerformance.LowLevel.csproj" />
|
||||
<ProjectReference Include="..\Misaki.HighPerformance.Mathematics\Misaki.HighPerformance.Mathematics.csproj" />
|
||||
<ProjectReference Include="..\Misaki.HighPerformance\Misaki.HighPerformance.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Misaki.HighPerformance.Jobs;
|
||||
using Misaki.HighPerformance.LowLevel.Collections;
|
||||
using Misaki.HighPerformance.Test.Jobs;
|
||||
using Misaki.HighPerformance.Unsafe.Collections;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Misaki.HighPerformance.Test;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using BenchmarkDotNet.Running;
|
||||
using Misaki.HighPerformance.Test;
|
||||
|
||||
BenchmarkRunner.Run<CollectionBenchmark>();
|
||||
BenchmarkRunner.Run<FunctionPtrBenchmark>();
|
||||
|
||||
Reference in New Issue
Block a user