"LINQ on Speed"..faster LINQ and Live views

Posts   
 
    
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 14-Dec-2009 08:52:34   

I came across this library

http://www.componentone.com/SuperProducts/LiveLinq/?gclid=CMv1vMCg1J4CFUYA4wodvXWWqg

and wondered if the benefits its promising are applicable to LINQ to LLBL?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 14-Dec-2009 10:27:38   

I think it's for in-memory objects. So you can have indexed collections which you use inside linq queries over objects instead of lists, which are enumerated.

In v3, you'll get our library Algorithmia with a KeyedCommandifiedList, which has the same feature, and you can also use HashSet<T> today which often gives a lot of performance enhancements. So if you for example have a query like: var q = from c in someEnumerable where c.Country=="USA" select c;

and you then want to filter another enumerable with the contents of q, you could do: var q2 = from c in someOtherEnumerable where q.Contains(c) || c.SomeField==someVariable select c;

however, that's slow, as q is enumerated for every c in q2. So instead do: var set = new HashSet<TypeOfElementIn_q>(q); var q2 = from c in someOtherEnumerable where set.Contains(c) || c.SomeField==someVariable select c;

and you'll get better performance as set.Contains() is an O(1) operation instead of an O(n) simple_smile

On databases, it makes no sense to use indexed collections as the query is converted to a sql query.

Frans Bouma | Lead developer LLBLGen Pro