[Mono-bugs] [Bug 51514][Wis] New - System.MonoType needlessly allocates memory when properties are accessed

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Sun, 30 Nov 2003 11:25:33 -0500 (EST)


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 bmaurer@users.sf.net.

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

--- shadow/51514	2003-11-30 11:25:33.000000000 -0500
+++ shadow/51514.tmp.4206	2003-11-30 11:25:33.000000000 -0500
@@ -0,0 +1,100 @@
+Bug#: 51514
+Product: Mono/Runtime
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: bmaurer@users.sf.net               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: System.MonoType needlessly allocates memory when properties are accessed
+
+Description of Problem:
+System.MonoType allocates extra memory, that is not needed.
+
+Steps to reproduce the problem:
+using System;
+using System.Reflection;
+
+class T {
+	static void Main () {
+		Type t = typeof (object);
+		Assembly a;
+		
+		for (int i = 0; i < 100000; i++)
+			 a = t.Assembly;
+	}
+}
+
+Run this code under --profile
+
+Actual Results:
+Allocation profiler
+Total mem Method
+########################
+    5078 KB System.MonoType::get_Assembly()
+        5078 KB   200000 System.String
+  Callers (with count) that contribute at least for 1%:
+      100000  100 % .T::Main()
+Total memory allocated: 5078 KB
+
+
+Expected Results:
+There should not be such a massive allocation.
+
+How often does this happen? 
+Always
+
+Additional Information:
+This is the code for the Assembly property in MonoType:
+
+		public override Assembly Assembly {
+			get {
+				MonoTypeInfo info;
+				get_type_info (_impl.Value, out info);
+				return info.assembly;
+			}
+		}
+
+The icall that this resolves to does:
+
+...
+	info->nested_in = class->nested_in ? mono_type_get_object (domain,
+&class->nested_in->byval_arg): NULL;
+	info->name = mono_string_new (domain, class->name);
+	info->name_space = mono_string_new (domain, class->name_space);
+	info->rank = class->rank;
+	info->assembly = mono_assembly_get_object (domain, class->image->assembly);
+	if (class->enumtype && class->enum_basetype) /* types that are modifierd
+typebuilkders may not have enum_basetype set */
+		info->etype = mono_type_get_object (domain, class->enum_basetype);
+	else if (class->element_class)
+		info->etype = mono_type_get_object (domain,
+&class->element_class->byval_arg);
+	else
+		info->etype = NULL;
+...
+
+Note the string allocations
+
+	info->name = mono_string_new (domain, class->name);
+	info->name_space = mono_string_new (domain, class->name_space);
+
+However, these strings are never accessed, meaning that it is just a waste
+of memory.
+
+Durring MCS bootstrap, this shows up:
+
+########################
+    2914 KB System.MonoType::get_Assembly()
+        2914 KB    96298 System.String                                   
+  Callers (with count) that contribute at least for 1%:
+       47615  98 %
+Mono.CSharp.TypeManager::MemberLookup_FindMembers(Type,MemberTypes,BindingFlags,string,bool&)