Linq to Csla speed

Linq to Csla speed

Old forum URL: forums.lhotka.net/forums/t/7582.aspx


Ash002 posted on Tuesday, September 08, 2009

Hi

We have a use of linq on a BLB which can take approx. 5/100s of a second to execute. On a BLB descendant we run:

var result = (from item in this where item.InternalName = internalName select item).FirstOrDefault()

The collection size is only small, 120 or so. We are processing some objects for export to excel. However when processing uses about 40 calls per object, the time adds up, ie about 2 seconds per object. This is very slow. A foreach loop takes no time at all, hence processing decreases to 5/100s for the whole object. Is the delay is caused by Linq to Csla's advanced features, ie creating a synchronised query result set?

To avoid this delay, we can avoid Linq to Csla by effectively casting the BLB using ToList(),

var result = (from item in this.ToList<RegisterField>() where item.InternalName = internalName select item).FirstOrDefault()

Timing indicates ToList() is slightly faster than a foreach loop. Is there a performance hit to ToList()? and is it a decent practice? bearing in mind these result sets are not data bound to a UI.

I did try out the Linq to Csla indexing and that seemed slow too, and really a solution for a large set of data rather than a small one.

Thanks

Ashley

RockfordLhotka replied on Tuesday, September 08, 2009

L2C indexing is only useful in limited scenarios, because there is a very real cost to creating and maintaining the index. This is true of any indexing scenario, including those in databases like SQL Server.

You should use L2C indexing only if both of these are true:

  1. You have a large collection
  2. You do many queries over the same collection instance

And if your collection changes a lot, you might find that maintaining the index is too expensive as well. In such a case, careful testing is indicated.

JonnyBee replied on Wednesday, September 09, 2009

Hi,

You must also be aware of cahcing scenarios - that often serialize the instance to a "cache storage". Since the index is not serializable that means the index will have to be rebuilt every time you get the instance from the cache store.

/jonnybee

JoeFallon1 replied on Wednesday, September 09, 2009

JonnyBee:
Hi,

You must also be aware of cahcing scenarios - that often serialize the instance to a "cache storage". Since the index is not serializable that means the index will have to be rebuilt every time you get the instance from the cache store.

/jonnybee

I pointed this out a few months ago in a discussion of ASP.Net. Since the Session is serialized the index is not useful since it costs so much to re-build on each postback.

Joe

 

Copyright (c) Marimer LLC