Since my last post I decided to get a better grip on the new functionality in .NET 4.0. I will discuss some of the great new features in future posts, but for now I want to discuss some recent discoveries in the WCF framework I have created.
I recently revisited much of my code in the framework I created a couple of years ago for database and SOA communication. I thought perhaps implementing LINQ in a few places would help further increase my throughput.
I got interesting but expected results. Using the Distinct() method is memory intensive, especially when searching large blocks of data in a generic list. I am using LINQ in just a couple of the possible places because I got a plethora of OutOfMemory Exceptions. After doing some research into the MSIL of the framework, I see why.
The short answer is test, test, test. LINQ is a very valuable feature and will improve efficiency and ease of code writing/reading in many cases. But it has it's limits. In the case of large Generic lists, you are better using the Find or FindAll method unless you are doing pretty simplistic queries in LINQ.
Finally, I noticed that if you utilize the Enumerable<> type for your return type of LINQ queries then use foreach loops, you can greatly improve the speed at which large operations occur.