[Mono-bugs] [Bug 75444][Nor] New - [GMCS] bad generic method instantations performance

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Sat Jul 2 08:01:45 EDT 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by malekith at pld-linux.org.

http://bugzilla.ximian.com/show_bug.cgi?id=75444

--- shadow/75444	2005-07-02 08:01:45.000000000 -0400
+++ shadow/75444.tmp.31935	2005-07-02 08:01:45.000000000 -0400
@@ -0,0 +1,121 @@
+Bug#: 75444
+Product: Mono: Runtime
+Version: 1.1
+OS: 
+OS Details: amd64 pld linux
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: JIT
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: malekith at pld-linux.org               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: [GMCS] bad generic method instantations performance
+
+Description of Problem:
+
+We are experiencing something like 10x slowdowns after switching from type
+erasure compilation method to generics. That is code using generics is
+10x slower (generation of this code is also slower but only 2x, and we
+will investigate this).
+
+Anyway this seems to be caused (at least partially) by some problems with
+instantiated generic method lookup.
+
+We have found mono to perform very badly on the following example:
+
+#v+
+class C1 <T> { }
+class C2 <T> { }
+class C3 <T> { }
+class C4 <T> { }
+
+class C5 <T> { }
+class C6 <T> { }
+class C7 <T> { }
+class C8 <T> { }
+
+class M {
+  static int dupl<T> (int cnt, T unused)
+  {
+    if (cnt < 0)
+      return 1;
+    else
+          return
+      dupl (cnt - 1, new C1<T> ()) +
+      dupl (cnt - 1, new C2<T> ()) +
+      dupl (cnt - 1, new C3<T> ()) +
+      dupl (cnt - 1, new C4<T> ()) +
+      dupl (cnt - 1, new C5<T> ()) +
+      dupl (cnt - 1, new C6<T> ()) +
+      dupl (cnt - 1, new C7<T> ()) +
+      dupl (cnt - 1, new C8<T> ());
+  }
+
+  public static void Main ()
+  {
+    string a = System.Environment.GetCommandLineArgs () [1];
+    System.Console.WriteLine (dupl (int.Parse (a), "foo"));
+  }
+}
+#v-
+
+It essentially does nothing, but when run with parameter N, it creates
+8^(N+2) generic instances of the method dupl. Running it with N=2 (so
+something about 1000 instances is created) takes 35s on 1.8Ghz amd64 box
+(under ms.net the time is not noticeable).
+
+The statistics are:
+
+Mono Jit statistics
+Compiled methods:       2159
+Methods from AOT:       0
+Methods cache lookup:   1621
+Method trampolines:     60344
+Basic blocks:           12428
+Max basic blocks:       91
+Allocated vars:         23886
+Analyze stack repeat:   0
+Compiled CIL code size: 108064
+Native code size:       339081
+
+Max code size ratio:    22.00 (Default::ReorderArgumentArray)
+Biggest method:         3158 (MonoType::InvokeMember)
+Code reallocs:          1
+Allocated code size:    339081
+Inlineable methods:     0
+Inlined methods:        4
+
+Created object count:   5822
+Initialized classes:    5096
+Used classes:           4824
+Static data size:       752
+VTable data size:       456888
+
+Generic instances:      69
+Initialized classes:    4759
+Inflated methods:       33746 / 33874
+Inflated types:         44348
+Generics metadata size: 3028792
+
+Which seems mostly OK, given that mono does not share code of different
+instantiations of dupl. However generating 300k of native code should
+be nowhere near 30s.
+
+Moreover, with slightly different version of this program, when increasing
+N we have found that the slowdown was at least quadratic, not linear,
+to number of type instantiations.
+
+If I were to guess it either hashtable collisions or plain lookup in list
+which makes it so slow.
+
+I were however unable to get mono compiled with -pg running :/
+
+Of course nemerle compiler doesn't use the code like the above, to get
+zillions of instantiations, it has real types there.
+
+I'm using mono svn.


More information about the mono-bugs mailing list