In Memory Filtering with large Entity Collection

Posts   
 
    
Makhaly_cs avatar
Makhaly_cs
User
Posts: 27
Joined: 12-Jan-2009
# Posted on: 19-Oct-2010 14:37:03   

Dear ALL;

I have loaded an Entity Collection of Customers (The number of the entity is about 13000 Customer). I provided the user with a text box to write the customer name and searches the collection. I use In Memory Filtering using EntityView but it is very slow in the first character the user write.

The Problem is that it is very slow while it is in the memory. Please advise.

We use the following tools: Visual Studio 2008 SP1. LLBL Version 2.6 (October 2009 Release).

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 19-Oct-2010 20:48:53   

Simple advise, really - don't filter large entity collections in memory simple_smile

Unless you really need to edit each entity in a collection, there is not a lot of point loading them all into memory. For display purposes you should use either a TypedView, and TypedList or a DynamicList.

There is also the question of where you do the filtering - usually the most efficient place is to let the DB server do the filtering for you, and then only return the filtered results.

Matt

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39905
Joined: 17-Aug-2003
# Posted on: 20-Oct-2010 11:19:54   

To elaborate: in-memory filtering / searching, be it with linq to objects or our own predicates for in-memory usage (e.g. in an entity view) are all based on linear searches, so always O(n), and not using indexes.

So to make things faster, it's easier to fetch data from the db, which can use indexes and can deliver the sets to use quicker than in-memory filtering.

Frans Bouma | Lead developer LLBLGen Pro
Makhaly_cs avatar
Makhaly_cs
User
Posts: 27
Joined: 12-Jan-2009
# Posted on: 20-Oct-2010 11:39:29   

Dear ALL;

Thanks a lot for your help.

I need to inform you that in the previous version of my application with the same number of Customers (13,000 customers) are working faster than this version and the same code is working in the previous version.

I have debugged my application and found that the problem is when i assign the filter to the EntityView object.

MTrinder I have created a TypedList on this Table and use it in binding instead of the EntityCollection and the same slowness is present.

Otis Thanks for your Clarification. The customer data does not change and the application is used from company branches so i load it one time when the user of the application logs in.

Thanks a lot.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Oct-2010 11:54:33   

Makahly,

I'm not sure why or how it was faster in an older version. But as Frans (Otis) have said, doing a linear search in a list/colletion of thousands of elements, won't be the fastest approach, to prove tha point, test this with a DataTable (btw, TypedList inherits from a dataTable).

So as I understand from you, you want to filter a huge collection of customers, by the customer name, but you do filtering as the user type in. So each letter he types you re-do the filtering.

To solve this you need to implement some advanced search algorithms, like the Trie.

Please check: http://en.wikipedia.org/wiki/Trie And you can find some C# implementations on the web, like: http://www.kerrywong.com/2006/04/01/implementing-a-trie-in-c/ http://paste.lisp.org/display/12161 http://www.koders.com/csharp/fid5C76413E2B0F5B83CEB84CB3DD9E38437858DBD2.aspx?s=mdef%3Afile http://www.techtalkz.com/c-c-sharp/161743-implementation-string-trie.html