Paper :: TPL Performance Improvements in .NET 4.5

Paper :: TPL Performance Improvements in .NET 4.5

  • Comments 9

We invested a lot of time into making parallel programming “just faster” for .NET 4.5.  You’ve already seen some neat tricks to ConcurrentDictionary.  There’s a lot more to say about improving the performance of the Task Parallel Library, and Joe Hoag has a written an excellent paper on the subject:

TPL Performance Improvements in .NET 4.5

The paper examines some of the changes made to TPL in .NET 4.5, compares times for selected operations in .NET 4 vs .NET 4.5, and makes some general “best practices” recommendations for those interested in using TPL performantly in .NET 4.5.

Enjoy!

Leave a Comment
  • Please add 8 and 5 and type the answer here:
  • Post
  • Awesome paper !

    But how about the TPL in Silverlight 5 ? is it somewhere between 4 and 4.5 ?

  • Many of the improvements described in the paper are in Silverlight 5 RC.

  • Very good, as always though,  but if I may say there is a little glitch where the Enclose Closure  goes:

     .. task.ContinueWith( (antecedent, state) =>...

    I got this error:

     ... Delegate 'System.Action<System.Threading.Tasks.Task<int>>' does not take 2 arguments...

    I've tried to fix that but I haven't had any success.

    Since it seem to me an important point to wrap up this important topic, if you could help me with this I' ll appreciate.

    Thanks for the time you'll spend with this

  • @robo.warrier2: Are you using .NET 4 rather than .NET 4.5?  The ContinueWith overload that accepts an Action<Task,object> was introduced in .NET 4.5 and doesn't exist in .NET 4.

  • Sorry Stephen but I've tried this on both .NET 4.0 with (Async CTP) and .NET 4.5 with VS 2012 but I have had the same error.

  • @robo.warrier2: Can you share a small repro of what you're trying with .NET 4.5 that's not working?

  • here you go:

           public static Task<int> ResultOrZero(Task<int> task)

           {

               //TaskCompletionSource<int> tcs = new TaskCompletionSource<int>();

               //task.ContinueWith(_ =>

               //{

               //    if (task.Status == TaskStatus.RanToCompletion)

               //        tcs.SetResult(task.Result);

               //    else

               //        tcs.SetResult(0);

               //});

               TaskCompletionSource<int> tcs = new TaskCompletionSource<int>();

               task.ContinueWith( (antecedent, state) =>

               {

                   var myTcs = (TaskCompletionSource<int>)state;

                   if (antecedent.Status == TaskStatus.RanToCompletion)

                       myTcs.SetResult(antecedent.Result);

                   else

                       myTcs.SetResult(0);

               }, tcs);

               return tcs.Task;

           }

    I've comment out the first portion of the method, that actually work well.

  • @robo.warrier2: Your code compiles fine for me with .NET 4.5.  Are you sure when you're using VS2012 that your project is configured to target .NET 4.5 and not to target .NET 4 through multitargeting?  This would be in your project's properties under "Target framework".

  • You' re right Stephen.. sorry the problem was there Target framework were set to .NET 4.0

    Many thanks

Page 1 of 1 (9 items)