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;
|
||||
}
|
||||
|
||||
Unsafe.Copy(pJobData, in job);
|
||||
*(T*)pJobData = job;
|
||||
|
||||
var jobInfo = new JobInfo
|
||||
{
|
||||
@@ -569,10 +569,7 @@ public sealed unsafe partial class JobScheduler : IJobScheduler, IDisposable
|
||||
return JobHandle.Invalid;
|
||||
}
|
||||
|
||||
fixed (T* pJob = &job)
|
||||
{
|
||||
NativeMemory.Copy(pJobData, pJob, (nuint)sizeof(T));
|
||||
}
|
||||
*(T*)pJobData = job;
|
||||
|
||||
var optimalBatchSize = Math.Max(1, batchSize);
|
||||
var totalBatches = (totalIteration + optimalBatchSize - 1) / optimalBatchSize;
|
||||
@@ -617,10 +614,7 @@ public sealed unsafe partial class JobScheduler : IJobScheduler, IDisposable
|
||||
return JobHandle.Invalid;
|
||||
}
|
||||
|
||||
fixed (T* pJob = &job)
|
||||
{
|
||||
NativeMemory.Copy(pJobData, pJob, (nuint)sizeof(T));
|
||||
}
|
||||
*(T*)pJobData = job;
|
||||
|
||||
var optimalBatchSize = Math.Max(1, batchSize);
|
||||
var totalBatches = (totalIteration + optimalBatchSize - 1) / optimalBatchSize;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<AssemblyVersion>1.5.6</AssemblyVersion>
|
||||
<AssemblyVersion>1.5.7</AssemblyVersion>
|
||||
<Version>$(AssemblyVersion)</Version>
|
||||
<Authors>Misaki</Authors>
|
||||
<PackageProjectUrl>https://git.personalnas.com/Misaki/Misaki.HighPerformance.git</PackageProjectUrl>
|
||||
|
||||
@@ -54,6 +54,13 @@ public readonly struct AllocationManagerInitOpts
|
||||
{
|
||||
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>
|
||||
|
||||
@@ -22,6 +22,7 @@ public unsafe class TestJobSystem
|
||||
[ClassInitialize]
|
||||
public static void Initialize(TestContext testContext)
|
||||
{
|
||||
AllocationManager.Initialize(AllocationManagerInitOpts.Default);
|
||||
s_jobScheduler = new JobScheduler(3);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user