By default, LINQ is single-threaded. PLINQ allows you to automatically spread your query across all available CPU cores with a single method call.
Converting a standard LINQ query to PLINQ is as simple as adding .AsParallel() at the start. PLINQ then partitions the data, runs the query on multiple threads, and merges the results back.
// Calculate complex hashes for 1 million items in parallel
var results = data.AsParallel()
.Select(x => ComplexHashFunction(x))
.ToList();
Parallelism isn't free. There is a cost to starting threads, partitioning data, and merging results. If your query is fast (e.g., simple filtering of a small list), PLINQ might actually be slower than standard LINQ. Use it only for CPU-intensive work or very large collections.
Q: "Does PLINQ maintain the order of the list?"
Architect Answer: "By default, NO. Because elements are processed in parallel, they finish at different times. If order matters, you must call .AsOrdered() after .AsParallel(). Be warned: AsOrdered() introduces a significant performance penalty because the merger must 'wait' for late-finishing items to maintain the sequence."