Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Smooth.Slinq: Fast, allocation-free, LINQ-like enumeration API for Unity!

Discussion in 'Assets and Asset Store' started by Smooth-P, Apr 1, 2014.

  1. Smooth-P

    Smooth-P

    Joined:
    Sep 15, 2012
    Posts:
    214
    Smooth.Slinq Asset Store link.


    Smooth.Slinq is an asset store package that provides Linq-like operations backed by value type enumerators and pooled storage to significantly boost programmer productivity, increase code maintainability, and reduce time to market... all without any per-frame allocations.


    Some of the advantages of Smooth.Slinq over Unity's Linq implementation include:

    • Slinq is allocation-free and slightly faster than Linq for constant space operations.
    • Slinq uses pooled storage for operations that require non-constant space (eg: Distinct, GroupBy, Join, OrderBy). Once the pools are warm, these operations are allocation-free and are generally much faster than Linq's.*
    • Slinq provides many useful operations not available in Linq, including element removal operations for enumerations that are backed by an appropriate type (eg: List<T>, LinkedList<T>).
    • Slinq operations can be applied to and consume part of an emumeration, leaving the remainder for further processing.
    • Slinq operations with delegate parameters have secondary method signatures with an additional, user-defined parameter that can be used to capture and pass state without the need for a closure.
    • Slinq provides comprehension methods with Option<T> semantics rather than throwing exceptions on empty input or resorting to "OrDefault" methods that lose information.
    • Slinq provides access to its internal collection representation, enabling advanced users to perform nested operations on pool backed enumerations without creating multiple copies of the data.
    • Slinq uses Smooth.Compare to find comparers, which can help eliminate comparison allocations and JIT exceptions.
    Stop wasting precious development time on writing yet more for loops and maintanence heavy boilerplate and instead cut right to the chase with clean, declaritive code that directly expresses intent rather than being mired in bookkeeping logic! Companies like Twitter, Google, Amazon, and Microsoft don't squander time and resources by bogging programmers down with imperative minutae and neither should you!

    Start Slinqing, rediscover productivity, and get your project out the door fast!


    Online documentation for Smooth.Slinq can be found here.

    Discussion and support for Smooth Games products is available on the company forums.


    *: Slinq is much, much faster than Linq for most operations that require non-constant storage. However, Linq has better average case sorting performance for OrderBy / OrderByDescending operations as it uses quicksort while Slinq uses a linked list merge sort. An in-depth discussion of sorting algorithms is beyond the scope of this document, but if there is user demand for an array-based quicksort it may be added in a later version of Slinq.
     
    Last edited: May 9, 2014
    one_one and rakkarage like this.
  2. Smooth-P

    Smooth-P

    Joined:
    Sep 15, 2012
    Posts:
    214
    I've decided to release Slinq (and Smooth.Compare) as part of Smooth.Foundations under the MIT License.

    The latest version isn't up on the asset store yet, but direct download links to the code and documentation are available on the Smooth Games forums.

    Edit: The asset store package has been updated!
     
    Last edited: May 9, 2014
  3. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    Woah, this needs to be getting *much* more attention. Excellent work Smooth P, this is a godsend for us who like Linq on mobile devices..!
     
  4. Smooth-P

    Smooth-P

    Joined:
    Sep 15, 2012
    Posts:
    214
    Thanks, man!

    This code saves me time and makes me more productive every single day while putting nice round zeros in the GC column and keeping my frame rate smooth... And that's on top of getting rid of those ultra frustrating JIT exceptions. :)
     
  5. Kobix

    Kobix

    Joined:
    Jan 23, 2014
    Posts:
    146
    Thanks Smooth P!!! I posted this Smooth.Foundations on my favorite game-programmer forum (Facepunch/Programming) so it gets more attention!
     
  6. Lumos

    Lumos

    Joined:
    Feb 11, 2013
    Posts:
    49
    This doesn't appear to contain a .Any method (when used on a Transform array); it's also got trouble determining the parameters of a "block" .Select statement.
    Also, the documentation site is down, and I needed to do some manual fixes to make it work with Unity 5.

    I think I'm going to keep using the good ol' regular Linq for the time being.
     
  7. dkoontz

    dkoontz

    Joined:
    Aug 7, 2009
    Posts:
    198
    Slinq definitely contains an Any method, did you remember to .Slinq() the collection first? To get it running on Unity 5 you just need to comment out some lines that reference deprecated enum values that reference Blackberry and Wii platforms. Having zero GC pressure is a pretty good tradeoff for commenting out a few lines.
     
    rakkarage likes this.
  8. Lumos

    Lumos

    Joined:
    Feb 11, 2013
    Posts:
    49
    Derp. The documentation was down, how was I supposed to know I've got to do that?

    Having done that now, there appear to be some problems with using anonymous types, for whatever reason. Lambdas that use anonymous types fail to compile properly, with the strangest of compilation errors. Intriguing...
     
  9. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
  10. dkoontz

    dkoontz

    Joined:
    Aug 7, 2009
    Posts:
    198
    I fully agree that the docs being down is super annoying, I just wanted to point out Slinq isn't totally unusable.
     
  11. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Does anyone have a copy of the documentation on this that they can share? The original publisher is MIA now it appears, as the website doesn't even exist anymore.

    Without documentation its really hard to know how to use it :)
     
  12. adamhill

    adamhill

    Joined:
    May 30, 2008
    Posts:
    26
    Check out the /Test directory on Github . Its just like LINQ from C# (so any tutorial on LINQ can show you how it works) except it doesn't allocate / allocates very little memory when using it. So kinda safe to use on a per frame basis.
     
  13. Asse1

    Asse1

    Joined:
    Jan 9, 2013
    Posts:
    89
    Hey,

    any information about why this whole project has been taken offline?
     
  14. Ironmax

    Ironmax

    Joined:
    May 12, 2015
    Posts:
    890
    Nothing is allocated free, overhead free is another thing, and can easily be avoided in how you implement your <T> with linq enumerator . I don't really get the point with this asset, since it uses delegate just as ling.
     
  15. SkyWalker87

    SkyWalker87

    Joined:
    May 5, 2013
    Posts:
    1
    I run SlinqTest with profiler. It shows GC Alloc 123.6KB in SlinqTest.Update().
    Why the author says it is without any per-frame allocations?