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:
@@ -5,15 +5,13 @@ namespace Misaki.HighPerformance.Jobs;
|
||||
|
||||
internal static class JobExecutor
|
||||
{
|
||||
public static bool Execute<T>(int dataID, int dataGeneration, ref JobRanges jobRanges, ref int remainingBatches, ref readonly JobExecutionContext ctx)
|
||||
public static void Execute<T>(int dataID, int dataGeneration, ref JobRanges jobRanges, ref readonly JobExecutionContext ctx)
|
||||
where T : struct, IJob
|
||||
{
|
||||
ref var job = ref JobDataPool<T>.GetReference(dataID, dataGeneration, out var exists);
|
||||
Debug.Assert(exists, "Job data not found in the pool.");
|
||||
|
||||
job.Execute(in ctx);
|
||||
|
||||
return Interlocked.Decrement(ref remainingBatches) == 0;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -31,14 +29,12 @@ internal static class JobExecutor
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ExecuteParallelFor<T>(int dataID, int dataGeneration, ref JobRanges jobRanges, ref int remainingBatches, ref readonly JobExecutionContext ctx)
|
||||
public static void ExecuteParallelFor<T>(int dataID, int dataGeneration, ref JobRanges jobRanges, ref readonly JobExecutionContext ctx)
|
||||
where T : struct, IJobParallelFor
|
||||
{
|
||||
ref var job = ref JobDataPool<T>.GetReference(dataID, dataGeneration, out var exists);
|
||||
Debug.Assert(exists, "Job data not found in the pool.");
|
||||
|
||||
var wasTheLastBatch = false;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (!GetWorkerStealingRange(ref jobRanges, out var start, out var end))
|
||||
@@ -50,23 +46,15 @@ internal static class JobExecutor
|
||||
{
|
||||
job.Execute(i, in ctx);
|
||||
}
|
||||
|
||||
if (Interlocked.Decrement(ref remainingBatches) == 0)
|
||||
{
|
||||
wasTheLastBatch = true;
|
||||
}
|
||||
}
|
||||
|
||||
return wasTheLastBatch;
|
||||
}
|
||||
|
||||
public static bool ExecuteParallel<T>(int dataID, int dataGeneration, ref JobRanges jobRanges, ref int remainingBatches, ref readonly JobExecutionContext ctx)
|
||||
public static void ExecuteParallel<T>(int dataID, int dataGeneration, ref JobRanges jobRanges, ref readonly JobExecutionContext ctx)
|
||||
where T : struct, IJobParallel
|
||||
{
|
||||
ref var job = ref JobDataPool<T>.GetReference(dataID, dataGeneration, out var exists);
|
||||
Debug.Assert(exists, "Job data not found in the pool.");
|
||||
|
||||
var wasTheLastBatch = false;
|
||||
while (true)
|
||||
{
|
||||
if (!GetWorkerStealingRange(ref jobRanges, out var start, out var end))
|
||||
@@ -75,12 +63,6 @@ internal static class JobExecutor
|
||||
}
|
||||
|
||||
job.Execute(start, end, in ctx);
|
||||
if (Interlocked.Decrement(ref remainingBatches) == 0)
|
||||
{
|
||||
wasTheLastBatch = true;
|
||||
}
|
||||
}
|
||||
|
||||
return wasTheLastBatch;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user