Search Unity

Unity + LINQ in 2020

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

  1. roberto_sc

    roberto_sc

    Joined:
    Dec 13, 2010
    Posts:
    144
    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:
    8,531
    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.
     
    ZO5KmUG6R likes this.
  3. roberto_sc

    roberto_sc

    Joined:
    Dec 13, 2010
    Posts:
    144
    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:
    974
    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.