cancel
Showing results for 
Search instead for 
Did you mean: 

Is using LINQ allowed?

FocusVRGames
Adventurer
I have been using LINQ in parts of my game.

It is mentioned in the Oculus guide to avoid LINQ, I have the two below bits of code, both do the same job. I have done some performance tests on a 1 million iterations of the below. The LINQ executed 15,000 times per second and the NoneLinq 45,000 time per second. Obviously none LINQ is quicker. But still 15,000 time per second is pretty quick. I prefer the tidiness, readability and ease of development from LINQ. I would however avoid using in Update(), but this executes once on a button press. I must admit I'm not 100 sure on the garbage generated from either.

Thoughts on using LINQ?
Do Oculus allow LINQ in submissions or is it a complete no no?
Any advice on the garbage created from one to the other?

public bool checkPlayerShipPartExists(string shipPart)
    {
        if (setupBoardlist.Count(x => x.SP.shipPart == shipPart) > 0)
        {
            return true;
        }
        return false;
    }

    public bool checkPlayerShipPartExistsNoneLinq(string shipPart)
    {
        for(int x = 0; x < setupBoardlist.Count; x++ )
        {
            if (setupBoardlist.SP.shipPart == shipPart)
            {
                return true;
            }
        }
        return false;
    }

Thanks
2 REPLIES 2

vrdaveb
Oculus Staff
> Do Oculus allow LINQ in submissions or is it a complete no no?

There is no hard rule against LINQ or any of the practices our guides discourage. Our store team only looks at the end result - does the app pass the Technical Requirements Checks (Gear VR, Rift)? We try to help you meet those requirements, but how you meet them is of course up to you.

Any advice on the garbage created from one to the other?

Typically LINQ and foreach create more garbage than a plain for loop because they instantiate iterators that take a small amount of memory for each iteration. You can check the GC impact by watching for spikes in Unity's CPU profiler. Look for GC.Collect.

FocusVRGames
Adventurer
Okay great, thanks for the response.