Bug 323080 (MONO80391) - Calling generic methods on interfaces is very slow
Summary: Calling generic methods on interfaces is very slow
Status: RESOLVED MOVED
Alias: MONO80391
Product: Mono: Runtime
Classification: Mono
Component: JIT (show other bugs)
Version: 1.0
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Paolo Molaro
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-29 04:57 UTC by Rolf Kvinge
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 20:21:24 UTC


---- Reported by rolfkvinge@ya.com 2006-12-28 21:57:25 MST ----

Calling generic methods on interfaces is very slow, code to reproduce:

using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;

class vbnc_bugs {
	interface iface {
		void method<T> ();
	}
	class test : iface  {
		public void method<T> () { }
	}
	static void Main (string [] args)
	{
		int iterations = 100000;
		DateTime start;
		TimeSpan t1, t2;
		test tester = new test ();
		iface itester = tester;
		
		if (args.Length == 1)
			iterations = int.Parse (args [0]);
		
		start = DateTime.Now;
		for (int i = 0; i < iterations; i++) {
			itester.method <object> ();
		}
		t1 = DateTime.Now - start;

		start = DateTime.Now;
		for (int i = 0; i < iterations; i++) {
			tester.method <object> ();
		}
		t2 = DateTime.Now - start;

		Console.WriteLine ("{0} iterations, with generics {1} ms, 
without {2} ms", iterations, (int) t1.TotalMilliseconds, (int) 
t2.TotalMilliseconds);
	}
}

Some benchmarks:
MS:
1000 iterations, with generics 0 ms, without 0 ms
10000 iterations, with generics 0 ms, without 0 ms
100000 iterations, with generics 0 ms, without 0 ms
1000000 iterations, with generics 15 ms, without 15 ms
10000000 iterations, with generics 250 ms, without 62 ms
100000000 iterations, with generics 2765 ms, without 828 ms

1000 iterations, with generics 24 ms, without 0 ms
10000 iterations, with generics 177 ms, without 0 ms
100000 iterations, with generics 4687 ms, without 0 ms
1000000 iterations, c-c'ed after a long wait.

If I debug with gdb and c-c, I'll almost always get this stack trace:
#0  0xb7e1518d in memmove () from /lib/libc.so.6
#1  0xb7f178a9 in g_array_insert_vals () from /opt/gnome/lib/libglib-
2.0.so.0
#2  0x08097dde in mono_jit_info_table_add (domain=0x21ed8, ji=0x8eca5b4) 
at domain.c:220
#3  0x08155f3c in mini_method_compile (method=0x8ed4cf8, opts=5335551, 
domain=0x21ed8, run_cctors=<value optimized out>, compile_aot=<value 
optimized out>, parts=0) at mini.c:10461
#4  0x08156651 in mono_jit_compile_method (method=0x8ed4cf8) at 
mini.c:10559
#5  0x08157231 in mono_helper_compile_generic_method (obj=0x2ffe8, 
method=0x826b918, context=0x826b8e8, this_arg=0xbfbbc20c) at jit-
icalls.c:804



---- Additional Comments From miguel@ximian.com 2007-01-01 16:39:48 MST ----

CCing Martin he could weight in here. 



---- Additional Comments From lupus@ximian.com 2007-06-05 12:12:51 MST ----



*** This bug has been marked as a duplicate of https://bugzilla.novell.com/show_bug.cgi?id=MONO81806 ***


Unknown operating system other. Setting to default OS "Other".
This bug was marked DUPLICATE in the database it was moved from.
    Changing resolution to "MOVED"