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:
2026-04-01 01:40:22 +09:00
parent 4d3ba9927c
commit 38209d1a6f
4 changed files with 12 additions and 10 deletions

View File

@@ -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;

View File

@@ -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>

View File

@@ -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>

View File

@@ -22,6 +22,7 @@ public unsafe class TestJobSystem
[ClassInitialize]
public static void Initialize(TestContext testContext)
{
AllocationManager.Initialize(AllocationManagerInitOpts.Default);
s_jobScheduler = new JobScheduler(3);
}