Tuesday, December 22, 2009

Using PLINQ to improve performance

The version 4.0 of .Net has a new feature called “Parallel LINQ” or PLINQ. If you use LINQ to filter or process a large amount of objects in memory and/or it is required a high-cost evaluation, PLINQ is for you.

PLINQ segments the source in parts and it uses different threads in order to process each segment.

var validCustomers = allCustomers.AsParallel()
  .Where(c => c.IsValid())
  .ToArray();

PLINQ

Here you can download the sample code.

For more details I recommend you to watch the Igor Ostrovsky presentation in the PDC 2009 webpage.

0 comments: