From 38209d1a6fdd6bb0404b0193cfb8cd4341760dd9 Mon Sep 17 00:00:00 2001 From: Misaki Date: Wed, 1 Apr 2026 01:40:22 +0900 Subject: [PATCH] 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. --- Misaki.HighPerformance.Jobs/JobScheduler.cs | 12 +++--------- .../Misaki.HighPerformance.Jobs.csproj | 2 +- .../Buffer/AllocationManager.cs | 7 +++++++ .../UnitTest/Jobs/TestJobSystem.cs | 1 + 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Misaki.HighPerformance.Jobs/JobScheduler.cs b/Misaki.HighPerformance.Jobs/JobScheduler.cs index e9691e1..0520cf7 100644 --- a/Misaki.HighPerformance.Jobs/JobScheduler.cs +++ b/Misaki.HighPerformance.Jobs/JobScheduler.cs @@ -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; diff --git a/Misaki.HighPerformance.Jobs/Misaki.HighPerformance.Jobs.csproj b/Misaki.HighPerformance.Jobs/Misaki.HighPerformance.Jobs.csproj index 05578a5..3e3e220 100644 --- a/Misaki.HighPerformance.Jobs/Misaki.HighPerformance.Jobs.csproj +++ b/Misaki.HighPerformance.Jobs/Misaki.HighPerformance.Jobs.csproj @@ -6,7 +6,7 @@ enable True True - 1.5.6 + 1.5.7 $(AssemblyVersion) Misaki https://git.personalnas.com/Misaki/Misaki.HighPerformance.git diff --git a/Misaki.HighPerformance.LowLevel/Buffer/AllocationManager.cs b/Misaki.HighPerformance.LowLevel/Buffer/AllocationManager.cs index f45b3ba..83c2419 100644 --- a/Misaki.HighPerformance.LowLevel/Buffer/AllocationManager.cs +++ b/Misaki.HighPerformance.LowLevel/Buffer/AllocationManager.cs @@ -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 + }; } /// diff --git a/Misaki.HighPerformance.Test/UnitTest/Jobs/TestJobSystem.cs b/Misaki.HighPerformance.Test/UnitTest/Jobs/TestJobSystem.cs index dfe7652..511d7dc 100644 --- a/Misaki.HighPerformance.Test/UnitTest/Jobs/TestJobSystem.cs +++ b/Misaki.HighPerformance.Test/UnitTest/Jobs/TestJobSystem.cs @@ -22,6 +22,7 @@ public unsafe class TestJobSystem [ClassInitialize] public static void Initialize(TestContext testContext) { + AllocationManager.Initialize(AllocationManagerInitOpts.Default); s_jobScheduler = new JobScheduler(3); }