feat(jobs): optimize job data copy and add default opts
Replaces Unsafe.Copy/NativeMemory.Copy with direct pointer assignment for job data in JobScheduler, improving performance and code clarity. Adds a static Default property to AllocationManagerInitOpts for easier initialization. Updates test setup to use the new default options. Bumps assembly version to 1.5.7.
This commit is contained in:
@@ -532,7 +532,7 @@ public sealed unsafe partial class JobScheduler : IJobScheduler, IDisposable
|
|||||||
return JobHandle.Invalid;
|
return JobHandle.Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
Unsafe.Copy(pJobData, in job);
|
*(T*)pJobData = job;
|
||||||
|
|
||||||
var jobInfo = new JobInfo
|
var jobInfo = new JobInfo
|
||||||
{
|
{
|
||||||
@@ -569,10 +569,7 @@ public sealed unsafe partial class JobScheduler : IJobScheduler, IDisposable
|
|||||||
return JobHandle.Invalid;
|
return JobHandle.Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
fixed (T* pJob = &job)
|
*(T*)pJobData = job;
|
||||||
{
|
|
||||||
NativeMemory.Copy(pJobData, pJob, (nuint)sizeof(T));
|
|
||||||
}
|
|
||||||
|
|
||||||
var optimalBatchSize = Math.Max(1, batchSize);
|
var optimalBatchSize = Math.Max(1, batchSize);
|
||||||
var totalBatches = (totalIteration + optimalBatchSize - 1) / optimalBatchSize;
|
var totalBatches = (totalIteration + optimalBatchSize - 1) / optimalBatchSize;
|
||||||
@@ -617,10 +614,7 @@ public sealed unsafe partial class JobScheduler : IJobScheduler, IDisposable
|
|||||||
return JobHandle.Invalid;
|
return JobHandle.Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
fixed (T* pJob = &job)
|
*(T*)pJobData = job;
|
||||||
{
|
|
||||||
NativeMemory.Copy(pJobData, pJob, (nuint)sizeof(T));
|
|
||||||
}
|
|
||||||
|
|
||||||
var optimalBatchSize = Math.Max(1, batchSize);
|
var optimalBatchSize = Math.Max(1, batchSize);
|
||||||
var totalBatches = (totalIteration + optimalBatchSize - 1) / optimalBatchSize;
|
var totalBatches = (totalIteration + optimalBatchSize - 1) / optimalBatchSize;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||||
<AssemblyVersion>1.5.6</AssemblyVersion>
|
<AssemblyVersion>1.5.7</AssemblyVersion>
|
||||||
<Version>$(AssemblyVersion)</Version>
|
<Version>$(AssemblyVersion)</Version>
|
||||||
<Authors>Misaki</Authors>
|
<Authors>Misaki</Authors>
|
||||||
<PackageProjectUrl>https://git.personalnas.com/Misaki/Misaki.HighPerformance.git</PackageProjectUrl>
|
<PackageProjectUrl>https://git.personalnas.com/Misaki/Misaki.HighPerformance.git</PackageProjectUrl>
|
||||||
|
|||||||
@@ -54,6 +54,13 @@ public readonly struct AllocationManagerInitOpts
|
|||||||
{
|
{
|
||||||
get; init;
|
get; init;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static AllocationManagerInitOpts Default => new AllocationManagerInitOpts
|
||||||
|
{
|
||||||
|
ArenaCapacity = 1024 * 1024 * 1024, // 1 GB
|
||||||
|
StackCapacity = 16 * 1024 * 1024, // 16 MB per thread
|
||||||
|
FreeListConcurrencyLevel = Environment.ProcessorCount
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public unsafe class TestJobSystem
|
|||||||
[ClassInitialize]
|
[ClassInitialize]
|
||||||
public static void Initialize(TestContext testContext)
|
public static void Initialize(TestContext testContext)
|
||||||
{
|
{
|
||||||
|
AllocationManager.Initialize(AllocationManagerInitOpts.Default);
|
||||||
s_jobScheduler = new JobScheduler(3);
|
s_jobScheduler = new JobScheduler(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user