Bug 997 - ContinueWith is 20x slower than on .net
Summary: ContinueWith is 20x slower than on .net
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Jérémie Laval
URL:
Depends on:
Blocks:
 
Reported: 2011-09-22 11:53 UTC by Marek Safar
Modified: 2012-04-05 05:35 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Marek Safar 2011-09-22 11:53:42 UTC
using System;
using System.Threading;
using System.Diagnostics;
using System.Threading.Tasks;

namespace test6
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			var tasks = new Task<int>[10000];
			var cont = new Task[tasks.Length];

			for (int i = 0; i < tasks.Length; ++i) {
				var t = new Task<int> (() => 1);
				cont[i] = t.ContinueWith (l => { }).ContinueWith (l => { }).ContinueWith (l => { }).ContinueWith (l => { }).ContinueWith (l => { }).ContinueWith (l => { })
					.ContinueWith (l => { }).ContinueWith (l => { }).ContinueWith (l => { }).ContinueWith (l => { }).ContinueWith (l => { }).ContinueWith (l => { })
					.ContinueWith (l => { }).ContinueWith (l => { }).ContinueWith (l => { }).ContinueWith (l => { }).ContinueWith (l => { }).ContinueWith (l => { });
				tasks[i] = t;
			}

			var sw = new Stopwatch ();
			sw.Start ();
			for (int i = 0; i < tasks.Length; ++i) {
				tasks[i].Start ();
			}

			Task.WaitAll (cont);

			sw.Stop ();
			Console.WriteLine (sw.ElapsedMilliseconds);

		}
	}
}


Best results
.NET (2cores machine) 20
Mono (8cores machine) 1254
Comment 1 Jérémie Laval 2011-09-25 12:59:33 UTC
Ack. With master optimizations this code is down to 764 for my dual core.
Comment 2 Marek Safar 2011-09-26 05:23:54 UTC
I can now get

Mono (8cores machine) 400

Will update the title to be less embarrassing
Comment 3 Jérémie Laval 2012-04-05 05:35:44 UTC
I guess