It's slow on IL2CPP build. isn't it?
mrsions opened this issue · 3 comments
mrsions commented
[Mono Build] is better than Non BurstCompile
but [IL2cpp Build] is not fast than BurstCompile
TestCode
[BurstCompile(OptimizeFor = OptimizeFor.Performance)]
public unsafe static class BurstLinq
{
public static int Sum(List<int> source)
{
var span = SpanHelper.AsSpan(source);
fixed (int* ptr = span)
{
SumCore(ptr, source.Count, out var result);
return result;
}
}
[BurstCompile(FloatMode = FloatMode.Fast)]
internal static void SumCore(int* ptr, [AssumeRange(1, int.MaxValue)] int length, out int result)
{
var sum = default(int);
for (var i = 0; i < length; i++) sum += ptr[i];
result = sum;
}
}
public unsafe static class NoBurstLinq
{
public static int Sum(List<int> source)
{
var span = SpanHelper.AsSpan(source);
fixed (int* ptr = span)
{
SumCore(ptr, source.Count, out var result);
return result;
}
}
internal static void SumCore(int* ptr, [AssumeRange(1, int.MaxValue)] int length, out int result)
{
var sum = default(int);
for (var i = 0; i < length; i++) sum += ptr[i];
result = sum;
}
}
public class TestBehaviour : MonoBehaviour
{
private List<int> ints;
private int = 1000000;
void Start()
{
ints = Enumerable.Range(0,1000).ToList();
}
void Update()
{
var localValue = 0;
Profiler.BeginSample("Linq");
for (var i = 0; i < length; i++)
{
localValue += ints.Sum();
}
Profiler.EndSample();
Profiler.BeginSample("NoBurstLinq");
for (var i = 0; i < length; i++)
{
localValue += NoBurstLinq.Sum(ints);
}
Profiler.EndSample();
Profiler.BeginSample("BurstLinq");
for (var i = 0; i < length; i++)
{
localValue += BurstLinq.Sum(ints);
}
Profiler.EndSample();
}
}
AnnulusGames commented
Interesting result. I will need to look into this in more detail.
AnnulusGames commented
Perhaps this may have something to do with it.
https://issuetracker-mig.prd.it.unity3d.com/issues/burst-compiled-job-is-completed-few-times-slower-than-il2cpp
apkd commented
These numbers look weird. Given that localValue
isn't stored anywhere, perhaps IL2CPP optimized the computation away completely?