Search Unity

Smooth.Foundations: Free allocation-free LINQ replacement and JIT Exception Avoidance

Discussion in 'iOS and tvOS' started by Smooth-P, May 9, 2014.

  1. Smooth-P

    Smooth-P

    Joined:
    Sep 15, 2012
    Posts:
    214
    Smooth.Foundations is a C# package that provides basic classes for boosting programmer productivity and writing clean, maintainable, allocation-free code in Unity. The code is available under the MIT license, and is free to use and free to redistrubute, including as part of other Asset Store packages.

    Smooth.Foundations includes:
    • Smooth.Compare, a replacement for the default generic comparers that helps reduce runtime allocations and eliminate JIT exceptions on AOT platforms.
    • Smooth.Slinq, a faster, allocation-free replacement for LINQ with increased functionality and a more robust API.
    • Algebraic structs like Option<T>, Either<L, R>, and Tuple<T1, ..., Tn>.
    • Generic pools with a delegate-based API.
    • Generic event helpers for creating and maintaining robust, type safe events backed by multicast delegates.
    • A disposal API for performing cleanup operations in a background thread during the rendering phase.
    • Methods for determining basic information about the runtime platform.
    • Other miscellaneous utilities.
    Asset Store Link | Support Forums
     
    angrypenguin likes this.
  2. vexe

    vexe

    Joined:
    May 18, 2013
    Posts:
    644
    This sounds pretty sick! However, am I missing something here? (please say yes :p) - I downloaded&imported the package I got all sorts of errors. Any ideas?
     
  3. vexe

    vexe

    Joined:
    May 18, 2013
    Posts:
    644
    So I re-downloaded the package and imported again, same errors. I wonder how everybody else got it working, seems I'm the only one complaining :s
     
  4. Smooth-P

    Smooth-P

    Joined:
    Sep 15, 2012
    Posts:
    214
    Can I see an example of the Type and Argument errors? And what version of Unity and API compatibility level are you using?
     
  5. vexe

    vexe

    Joined:
    May 18, 2013
    Posts:
    644
    @Smooth P I'm currently using Unity 4.5.4f1 - I tried both .NET 2.0 and .NET 2.0 subset.

    Not sure what you mean with an example, a copy-paste of the console output for an error maybe? if so, here's some

    Code (csharp):
    1.  
    2. Assets/Smooth/Foundations/Compare/Factory.cs(202,105): error CS1061: Type `Tuple<System.Linq.Expressions.Expression,System.Reflection.MethodInfo>' does not contain a definition for `_1' and no extension method `_1' of type `Tuple<System.Linq.Expressions.Expression,System.Reflection.MethodInfo>' could be found (are you missing a using directive or an assembly reference?)
    3.  
    4. Assets/Smooth/Foundations/Compare/Factory.cs(202,88): error CS1502: The best overloaded method match for `System.Linq.Expressions.Expression.Call(System.Reflection.MethodInfo, params System.Linq.Expressions.Expression[])' has some invalid arguments
    5.  
    6. Assets/Smooth/Foundations/Compare/Factory.cs(202,88): error CS1503: Argument `#1' cannot convert `object' expression to type `System.Reflection.MethodInfo'
    7.  
    8. Assets/Smooth/Foundations/Compare/Factory.cs(205,76): error CS0119: Expression denotes a `variable', where a `method group' was expected
    9.  
     
  6. Smooth-P

    Smooth-P

    Joined:
    Sep 15, 2012
    Posts:
    214
    Sounds like you have Tuple types that are getting used instead of the TupleS from the Smooth.Algebraics package.

    Try replacing all usages of "Tuple" with "Smooth.Algebraics.Tuple" in the Factory.cs source. Fixing Factory may reveal other places you'll have to do a similar search and replace...
     
  7. vexe

    vexe

    Joined:
    May 18, 2013
    Posts:
    644
    That's really weird. I could have sworn that the first thing I tried when i got the errors was to import to an empty project. I did that now - Got errors that RuntimePlatform.WiiPlayer doesn't exist in BasePlatform.cs, I commented all instances and compiled successfully. I feel.... duh. You might wanna update this Wii thing, looks like it's recently removed from the API. Thanks for your input.
     
  8. vexe

    vexe

    Joined:
    May 18, 2013
    Posts:
    644
    However; all the scripts in the SlinqTest scene on the game objects are missing
     
  9. radimoto

    radimoto

    Joined:
    Aug 23, 2012
    Posts:
    257
    I imported Smooth.Foundations into my project, but started getting Mach-o linker errors in Xcode when trying to build to IOS.

    This was due to Assembly-CSharp.dll being too large. After inspecting the strings within the dll I noticed a lot of it was made up of Smooth.Foundations scripts. After moving Smooth.Foundations into the Plugins directory (e.g. /Assets/Plugins/Smooth/Foundations) my project builds OK. Not sure if there will be any issues with having it within the Plugins directory but this might help anyone else running into this issue.
     
  10. casimps1

    casimps1

    Joined:
    Jul 28, 2012
    Posts:
    254
    I just found out about this package and was very hopeful about it being an easy drop-in replacement for my Linq calls which were throwing JIT exceptions on iOS. I wasn't doing anything super-complicated with Linq to begin with. Unfortunately, I had to do a little tinkering to get it to do what I wanted.

    First off, it wouldn't even compile on Unity 4.6.1 because Wii support had been dropped and the package had references to Wii as a RuntimePlatform. I had to remove those references before it would even compile.

    Second, I couldn't get the built-in pools to work on iOS. Calling ToList() on a Slinq object was supposed to provide a List from a pool of Lists. Instead it threw a JIT exception during type initialization. Couldn't figure out how to easily fix the pools, so I had to modify the ToList() method to just instantiate and return a new List rather than messing around with the pools.

    Once I did that I managed to get my Linq calls working on iOS without JIT errors. Yay!