Bug 21645

Summary: Slow invocation of generic method on value type
Product: [Mono] Runtime Reporter: Marek Safar <masafa>
Component: JITAssignee: Bugzilla <bugzilla>
Status: RESOLVED FIXED    
Severity: normal CC: kumpera, mono-bugs+mono, mono-bugs+runtime
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:

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);

		return;
	}

}

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.