refactor(jobs, allocator): optimize queues & dependencies
Major refactor of job system and memory allocator: - Replaced threadIndex with preferLocal for scheduling - Switched local queues to SPMCQueue for better performance - Introduced lock-free JobEdge pool for dependencies - Removed remainingBatches; use ref counting for completion - Updated all scheduling APIs and tests to new model - Optimized FreeList struct sizes and block management - Added allocation benchmarks - Disabled OwnershipTransferAnalyzer temporarily - Bumped assembly versions
This commit is contained in:
58
Misaki.HighPerformance.Test/Benchmark/AllocationBenchmark.cs
Normal file
58
Misaki.HighPerformance.Test/Benchmark/AllocationBenchmark.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Misaki.HighPerformance.LowLevel.Buffer;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Misaki.HighPerformance.Test.Benchmark;
|
||||
|
||||
[MemoryDiagnoser]
|
||||
public unsafe class AllocationBenchmark
|
||||
{
|
||||
private FreeList _frreList;
|
||||
|
||||
private void* _nativePtr;
|
||||
private void* _freeListPtr;
|
||||
private byte[]? _managedArray;
|
||||
private IntPtr _marshalPtr;
|
||||
|
||||
[Params(8, 64, 512, 1024, 4096, 8192)]
|
||||
public nuint Size = 1024;
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
_frreList = new FreeList(8);
|
||||
}
|
||||
|
||||
[GlobalCleanup]
|
||||
public void Cleanup()
|
||||
{
|
||||
_frreList.Dispose();
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void NativeMemoryAlloc()
|
||||
{
|
||||
_nativePtr = NativeMemory.Alloc(Size);
|
||||
NativeMemory.Free(_nativePtr);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void FreeListAlloc()
|
||||
{
|
||||
_freeListPtr = _frreList.Allocate(Size, 8);
|
||||
_frreList.Free(_freeListPtr);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void ManagedAlloca()
|
||||
{
|
||||
_managedArray = new byte[Size];
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void GCAlloc()
|
||||
{
|
||||
_marshalPtr = Marshal.AllocHGlobal((nint)Size);
|
||||
Marshal.FreeHGlobal(_marshalPtr);
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class ParallelNoiseBenchmark
|
||||
height = _HEIGHT
|
||||
};
|
||||
|
||||
var handle = _jobScheduler.ScheduleParallel(ref job, _LENGTH, 64, -1);
|
||||
var handle = _jobScheduler.ScheduleParallel(ref job, _LENGTH, 64);
|
||||
_jobScheduler.Wait(handle);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public unsafe class SPMDBenchmark
|
||||
height = _SIZE,
|
||||
};
|
||||
|
||||
var handle = _scheduler.ScheduleParallelSPDM<Jobs.NoiseJobMathSPMD, float>(ref job, _SIZE * _SIZE, 64, -1);
|
||||
var handle = _scheduler.ScheduleParallelSPDM<Jobs.NoiseJobMathSPMD, float>(ref job, _SIZE * _SIZE, 64, false);
|
||||
_scheduler.Wait(handle);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public unsafe class SPMDBenchmark
|
||||
height = _SIZE,
|
||||
};
|
||||
|
||||
var handle = _scheduler.ScheduleParallelFor(ref job, _SIZE * _SIZE, 64, -1);
|
||||
var handle = _scheduler.ScheduleParallelFor(ref job, _SIZE * _SIZE, 64);
|
||||
_scheduler.Wait(handle);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public unsafe class SPMDBenchmark
|
||||
height = _SIZE,
|
||||
};
|
||||
|
||||
var handle = _scheduler.ScheduleParallel(ref job, _SIZE * _SIZE, 64, -1);
|
||||
var handle = _scheduler.ScheduleParallel(ref job, _SIZE * _SIZE, 64);
|
||||
_scheduler.Wait(handle);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user