[Mono-list] Advice on optimisation in xml deserialisation
Robert Jordan
robertj at gmx.net
Wed Jan 9 19:36:26 EST 2008
Robert Jordan wrote:
> Alan McGovern wrote:
>> 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.
>
> I don't think the patch is correct. It is assuming that every
> "Add" method of a collection/list is compatible with
> AddDelegate(object).
>
> If the test cases are still working, it could be that
> CreateDelegate is buggy: MSDN states:
>
> "A parameter of a delegate is compatible with the corresponding
> parameter of a method if the type of the delegate parameter is more
> restrictive than the type of the method parameter, because this
> guarantees that an argument passed to the delegate can be passed safely
> to the method."
It's indeed a bug in Mono's CreateDelegate. The following test case
must fail but it doesn't:
using System;
delegate void Method(object o);
class T
{
static void Main ()
{
T t = new T ();
Method m = (Method) Delegate.CreateDelegate (typeof(Method), t,
t.GetType ().GetMethod ("Test"));
m (new Uri ("http://mono-project.com"));
}
public void Test (Uri uri)
{
Console.WriteLine (uri);
}
}
Robert
More information about the Mono-list
mailing list