[Mono-dev] [PATCH] - optimization for System.Xml.XmlNode::SelectSingleNode
Alan McGovern
alan.mcgovern at gmail.com
Mon May 10 14:28:56 EDT 2010
Why would a c-cast be so much slower than an 'as' cast? Surely they
should be equivalent or the c-cast should be faster.
Alan.
On Mon, May 10, 2010 at 7:24 PM, Atsushi Eno
<atsushieno at veritas-vos-liberabit.com> wrote:
> Well, it wasn't really internal, but that does not affect my statement.
>
> Atsushi Eno
>
> On 2010/05/11 2:55, Atsushi Eno wrote:
>> Hi,
>>
>> Thanks Tom, it looks like a good catch. The interface is internal, and
>> cast exceptions should not happen there anyways. Once the build got
>> fixed, I'll verify the patch and apply it unless it regresses.
>>
>> Atsushi Eno
>>
>>
>> On 2010/05/11 2:09, tom hindle wrote:
>>
>>> Hi,
>>>
>>> While performance profiling our code, with mono's nice profiling
>>> tools :), I noticed System.Xml.XmlNode::SelectSingleNode was taking 23ms
>>> a call while the sum of the methods it was calling took< 5ms.
>>> SelectSingleNode is a very simple method however it contains a (dynamic)
>>> down cast. I replaced the (Cstyle/prefix) cast with a 'as' cast and this
>>> seem to reduce the method time by about 7ms.
>>>
>>>
>>> // With 'Cstyle' cast
>>> 39672.303 1717 23.106
>>> System.Xml.XmlNode::SelectSingleNode(string,XmlNamespaceManager)
>>> Callers (with count) that contribute at least for 1%:
>>> 1717 100 % System.Xml.XmlNode::SelectSingleNode(string)
>>>
>>> // With 'as' cast
>>> 29238.117 1880 15.552
>>> System.Xml.XmlNode::SelectSingleNode(string,XmlNamespaceManager)
>>> Callers (with count) that contribute at least for 1%:
>>> 1880 100 % System.Xml.XmlNode::SelectSingleNode(string)
>>>
>>>
>>> I read that this is because 'as' cast generates IL instr 'isinst' while
>>> 'cstyle' cast generates 'castclass'.
>>>
>>> The msdn documentation about XmlNode.SelectSingleNode doesn't state that
>>> an InvalidCastException, can/could be thrown.
>>>
>>> Is this a sensible thing to do? If so could someone review/commit my
>>> patch as I believe it will make a fairly major difference for
>>> applications that make much use of SelectSingleNode.
>>>
>>>
>>> Thanks
>>> Tom
>>>
>>>
>>>
>>> _______________________________________________
>>> Mono-devel-list mailing list
>>> Mono-devel-list at lists.ximian.com
>>> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>>>
>>>
>> _______________________________________________
>> Mono-devel-list mailing list
>> Mono-devel-list at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>>
>>
>>
>>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
More information about the Mono-devel-list
mailing list