Is it faster?
does the .NET 4.5 really run faster than 4?
this post will summaries TPL Performance Improvements in .NET 4.5.
the TPL team has put lot of effort to dramatically improve the overall performance of .NET 4.5.
the improvement was achieve both by execution and memory allocation optimization.
in result .NET 4.5 parallelism is faster and more GC friendly.
allocation optimization does improve the overall execution speedup, because GC collection does have significantly impact on the overall performance (thread freezing and more).
the benchmarks in this post were execute against 100000 tasks with 25 iterations.
.NET 4.5 acknowledged the continuation-style of programming to be a mainline scenario (async/await support). lot of effort were put into making continuations faster.
using the magical Interlocked.CompareExchange the continuation footprint were reduce while the task is having single continuation (there will be no continuation list assignment in this case), but even when having more than a single continuation .NET 4.5 is still faster than in .NET 4.
the following benchmark show single continuation assignment:
the following benchmark show multiple continuation assignment:
the task internal was redesign to have a minimal memory footprint for common scenarios, while also supporting more rare scenarios.
the following benchmark show improvement over Task creation:
the following benchmark show improvement over creation of Task<T>:
the following benchmark show improvement over creation of TaskCompletionSource:
TPL 4.5 performance was significantly improved both in terms of speedup and allocations.
you can see the full benchmarks information and more details about the inner stuff at TPL Performance Improvements in .Net 4.5 by Joseph E. Hoag.