About optimization

Topics: Core, General
Nov 16, 2011 at 10:40 AM


I have about 10 000 records and theirs I received from files in IEnumerable<T> type.

When I want to search data from this records

ex: var data = IEnumerable<T>.Where(a=>a.Code == code || a.Part.Code == code)

This query running for a long time(more than minute).How I can do optimization?Can I run a raw sql script in Orchard?

Any help appreciated!

Nov 16, 2011 at 12:20 PM
Edited Nov 16, 2011 at 12:20 PM

The big problem here is that you have an IEnumerable in the first place. This means that you've already loaded 10,000 records into memory, consuming a lot of RAM, and Linq has no choice but to perform that query in-memory which is also slow. So there's really no way to optimise.

If these records aren't coming from a database, then you need to consider a batch process that will first load them into the database, so that you can query a proper IQueryable and let the database engine optimise for you. That will be significantly faster, and you can tune things even further with indexing.

Nov 17, 2011 at 3:28 AM

Thanks!I will try to do.