Bug 21645 - Slow invocation of generic method on value type
Summary: Slow invocation of generic method on value type
Alias: None
Product: Runtime
Classification: Mono
Component: JIT ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2014-07-28 15:01 UTC by Marek Safar
Modified: 2014-07-29 00:32 UTC (History)
3 users (show)

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:

Description Marek Safar 2014-07-28 15:01:58 UTC
using System;
using System.Xml;
using System.Globalization;
using System.Threading;
using System.Diagnostics;

interface I
	int TestMe ();

struct C : I
	public int TestMe ()
		return 4;

static class X
    static int TestGeneric<T> (T t) where T : struct, I
    	return t.TestMe ();

	public static void Main ()
		var sw = new Stopwatch ();
		sw.Start ();

		var c = new C ();
		const int iter = 1000000000;
		int res = 0;
		for (int i = 0; i < iter; ++i) {
			res = TestGeneric (c);

		sw.Stop ();
		Console.WriteLine (sw.Elapsed);
		Console.WriteLine (res);



Mono: 04.5923078
.NET: 00.1720799

That's about 30x slower
Comment 1 Rodrigo Kumpera 2014-07-28 23:07:55 UTC
The problem here is not with generic invocation as all calls in the loop are inlined but that our AA pass is not working as it should on this case.
Comment 2 Rodrigo Kumpera 2014-07-29 00:32:21 UTC
Fixed on master.