Anyone notice burst being kind of... slow? Specifically when straight up iterating over arrays of TransformHandles? I know there's a performance hit when first calling burst code, but I'm using the performance package. I made a forum post about it: https://discussions.unity.com/t/burst-slower-than-non-burst/1710309 but I'm sure that will be lost, might get an answer here.
Was wondering if someone could sanity check me? Don't use burst that often. This is the code I'm using to test burst, which is slower than the code that just iterates over a normal array:
[Test, Performance]
[TestCase(1)]
[TestCase(100)]
[TestCase(250)]
[TestCase(500)]
[TestCase(1000)]
[TestCase(10000)]
public void SetPosition_TransformHandle_Burst(int objectCount)
{
var objects = new GameObject[objectCount];
var handles = default(NativeArray<TransformHandle>);
Measure.Method(() => { TransformHandle_Burst.Compute(ref handles, 0.1f); })
.SetUp(() =>
{
handles = new NativeArray<TransformHandle>(objectCount, Allocator.Persistent);
for (var i = 0; i < objectCount; i++)
{
objects[i] = new GameObject();
handles[i] = objects[i].transformHandle;
}
})
.CleanUp(() =>
{
handles.Dispose();
foreach (var obj in objects)
Object.DestroyImmediate(obj);
})
.WarmupCount(k_WARMUP_COUNT)
.MeasurementCount(k_MEASUREMENT_COUNT)
.Run();
}
[BurstCompile(OptimizeFor = OptimizeFor.Performance, CompileSynchronously = true)]
private static class TransformHandle_Burst
{
[BurstCompile(OptimizeFor = OptimizeFor.Performance, CompileSynchronously = true)]
public static void Compute(ref NativeArray<TransformHandle> handles, in float delta)
{
for (var i = 0; i < handles.Length; i++)
{
var transformHandle = handles[i];
transformHandle.position += new Vector3(i * delta, 0, 0);
}
}
}
For 10,000 transforms, I get a median time of 1.02 ms where without burst I get 0.84. Is 10,000 not enough to see a performance increase from using burst? I do see a performance increase when using IParallelForTransform and the TransformAccess struct, but I thought that burst iteration over 10k objects would be faster than non-burst iteration over 10k objects.
