There was a thread a week or two ago called 'Speed difference Windows
- Linux' which noted there was a big difference in performance between
.NET and mono. I did a brief bit of profiling and came up with this
patch which improves performance ~30% for the testcase which was
attached in the email. This reduces runtime memory usage by about 10MB
(80MB -> 70MB) and decreases processing time by 30% (3.4s -> 2.6s).

Anyone have any ideas on how to tidy this up to make it neater? Also,
would this optimisation be too specific, or can it be generalised
somewhere higher up in the stack.

Alan.
Index: System.Xml.Serialization/XmlSerializationReaderInterpreter.cs
===================================================================
--- System.Xml.Serialization/XmlSerializationReaderInterpreter.cs	(revision 90185)
+++ System.Xml.Serialization/XmlSerializationReaderInterpreter.cs	(working copy)
@@ -723,6 +723,9 @@
 			return list;
 		}
 
+		delegate void AddDelegate (object o);
+		private AddDelegate del;
+		private object previousObject;
 		void AddListValue (TypeData listType, ref object list, int index, object value, bool canCreateInstance)
 		{
 			Type type = listType.Type;
@@ -737,12 +740,22 @@
 					if (canCreateInstance) list = Activator.CreateInstance (type, true);
 					else throw CreateReadOnlyCollectionException (type.FullName);
 				}
-
+				
+#if NET_2_0
+				if (previousObject != list)
+				{
+					previousObject = list;
+					MethodInfo mi = type.GetMethod ("Add", new Type[] {listType.ListItemType} );
+					del = (AddDelegate)Delegate.CreateDelegate(typeof(AddDelegate), list, mi);
+				}
+				del(value);
+#else
 				MethodInfo mi = type.GetMethod ("Add", new Type[] {listType.ListItemType} );
-				mi.Invoke (list, new object[] { value });
+				mi.Invoke(list, new object[] { value });
+#endif
 			}
 		}
-
+		
 		object CreateInstance (Type type)
 		{
 			return Activator.CreateInstance (type, empty_array);
_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to