Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's slow on IL2CPP build. isn't it? #6

Open
mrsions opened this issue Mar 21, 2024 · 3 comments
Open

It's slow on IL2CPP build. isn't it? #6

mrsions opened this issue Mar 21, 2024 · 3 comments

Comments

@mrsions
Copy link

mrsions commented Mar 21, 2024

[Mono Build] is better than Non BurstCompile

Editor
Win-Mono
Win-Mono-Dev

but [IL2cpp Build] is not fast than BurstCompile

Win-Il2cpp
Win-Il2cpp-Dev

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();
    }
}
@nuskey8
Copy link
Owner

nuskey8 commented Mar 21, 2024

Interesting result. I will need to look into this in more detail.

@nuskey8
Copy link
Owner

nuskey8 commented Mar 21, 2024

@apkd
Copy link

apkd commented Jul 21, 2024

These numbers look weird. Given that localValue isn't stored anywhere, perhaps IL2CPP optimized the computation away completely?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants