Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Unity + LINQ in 2020

Discussion in 'Scripting' started by roberto_sc, Jan 8, 2020.

  1. roberto_sc

    roberto_sc

    Joined:
    Dec 13, 2010
    Posts:
    139
    Where does the Community stand in relation to using LINQ, now in 2020?

    Re-reading old posts, there were problems using LINQ in iOS and also performance problems because of allocations made by the Linq implementation in old Mono versions that Unity was using. The general consensus was either "never use LINQ" or "avoid using LINQ, especially in big loops".

    Did this change?
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    7,153
    I've been using linq for years now.

    Sure, be aware of any garbage that could be created. But personally I've never really had any major memory issues with it as long as I avoided doing it in things like every Update.
     
    aaro4130 likes this.
  3. roberto_sc

    roberto_sc

    Joined:
    Dec 13, 2010
    Posts:
    139
    I’ve always used it too. My post is more in regards to if something has changed.
     
  4. eisenpony

    eisenpony

    Joined:
    May 8, 2015
    Posts:
    880
    Based on vicarious experience, I think the implementation of foreach in the old mono created garbage every step of every iteration. I'm pretty sure that was fixed with the switch to the new .net implementation a few years ago.

    Using LINQ is still subject to creating garbage where a careful use or arrays may not. However, it's much quicker to work with, so I suggest using LINQ and saving the performance tuning once the profiler shows your queries are causing a problem.
     
    roberto_sc and lordofduct like this.
unityunity