It seems I get a hard 48ms every time I try to use the burst compiler.
Here is the data structure:
public struct TileGenerationData
{
public float3 TilePosition;
public int X;
public int Z;
public int ChunkX;
public int ChunkZ;
}
Here is the Job:
[BurstCompile]
public struct TileInitializationJob : IJobParallelFor
{
//Inputs
public int ChunkSize;
public int ChunkWidth;
public int ChunkHeight;
public float XSlice;
public float ZSlice;
//Outputs
public NativeArray<TileGenerationData> result;
public void Execute(int index)
{
TileGenerationData tData = result[index];
//Calculation x, z given index
tData.X = index / (ChunkSize * ChunkWidth);
tData.Z = index % (ChunkSize * ChunkHeight);
//Calculate Chunk indexes
tData.ChunkX = tData.X / ChunkSize;
tData.ChunkZ = tData.Z / ChunkSize;
tData.TilePosition.x = (((tData.X + tData.Z * 0.5f - tData.Z / 2) * XSlice) - (XSlice * ChunkSize * tData.ChunkX)) + XSlice / 2; //Add HexMetrics.XSlice/2 to center the hex
tData.TilePosition.y = 0f;
tData.TilePosition.z = ((tData.Z * ZSlice) - (ZSlice * ChunkSize * tData.ChunkZ)) + ZSlice / 1.5f; //Add HexMetrics.ZSlice/1.5f to center the hex
result[index] = tData;
}
}
Here is the usage:
//Initialize Creation Job
TileInitializationJob createJob = new TileInitializationJob();
createJob.ChunkSize = WorldMetrics.ChunkSize;
createJob.ChunkWidth = WorldMetrics.WorldChunkWidth;
createJob.ChunkHeight = WorldMetrics.WorldChunkHeight;
createJob.XSlice = HexMetrics.XSlice;
createJob.ZSlice = HexMetrics.ZSlice;
createJob.result = _tilePositionData;
JobHandle createJobHandle = createJob.Schedule(_tilePositionData.Length, createJob.ChunkSize);
createJobHandle.Complete();
The timing I get from the burst compiler is as follows:
Burst timings (total: 48.8ms)
UpdateAssemblyCacheDirtyState: 1.1ms
FetchFromAssemblyCache: 0.0ms
ILCreateModule: 46.0ms
ILTransform: 0.0ms
ILAnalyzer: 0.0ms
ILHash: 0.9ms
IL2Module: 0.0ms
TargetModule: 0.1ms
StaticModule: 0.0ms
OptimizeModule: 0.0ms
CleanupModule: 0.0ms
PrintModule: 0.0ms
PrintModule: 0.0ms
VerifyModule: 0.0ms
AsmDump: 0.0ms
ILDump: 0.0ms
Initialize: 0.2ms
CompileModule: 0.0ms
LoadModuleFromCache: 0.0ms
SaveModuleToCache: 0.0ms
ExternalFunctions: 0.0ms
Total: 48.8ms
While compiling job: System.Void Unity.Jobs.IJobParallelForExtensions/ParallelForJobStruct`1<MainThread/TileInitializationJob>::Execute(T&,System.IntPtr,System.IntPtr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,System.Int32)
Any help would be appreciated. Thanks!