[Mono-dev] performance patch for TypeDescriptor

Andrew Skiba andrews at mainsoft.com
Wed Feb 22 09:20:33 EST 2006


Hello,

I found a big performance trouble relative to dotnet with the following
code:

   static void Main(string[] args)
   {
        while (true) {
                DateTime start = DateTime.Now;
                for (int i=0; i<10000000; i++) {
                        TextBox tb = new TextBox ();
                        TypeDescriptor.GetProperties (tb);
                        tb.Dispose ();
                }
                TimeSpan ts = DateTime.Now - start;
                Console.WriteLine (ts.ToString());
        }
   }

on dotnet it takes 12 seconds to perform 10,000,000 of such loops, while
on mono it takes 20 second for 10,000. So the performance is worse in
more than 1000 times.

'TypeDescriptor.GetProperties(Object component)' treats component
differently if it
implements IComponent. This is done in order to allow the component
'Site' to filter
the attributes (see TypeDescriptor lines 760-764).

However, if the Site of the component is null all of this is unnecessary
and one can
use the component type to retrieve the components properties. We have
seen that
System.Web.UI.Control implements IComponent but its Site property is
always null (unless
modified by the programmer explicitly) making this case frequent and
important.
We therefore propose the attached patch that uses the component's type
to retrieve its
properties, events and attributes if the component Site property is
null, and uses the
component only if Site is not null.

I attach also a simple WebForm that reveals the performance gain in a
real web environment.
To test it, make a GET request, set the value of TextBox1 to a string
starting with 'a' to pass
validation, and make POST. Before this patch I had 1800 rps, and after -
2600 rps.

Regards, Andrew.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: TypeDescriptor.cs.patch
Type: application/octet-stream
Size: 2545 bytes
Desc: TypeDescriptor.cs.patch
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060222/c037a778/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: WebForm1.aspx
Type: application/octet-stream
Size: 711 bytes
Desc: WebForm1.aspx
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060222/c037a778/attachment-0001.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: WebForm1.aspx.cs
Type: application/octet-stream
Size: 1367 bytes
Desc: WebForm1.aspx.cs
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060222/c037a778/attachment-0002.obj 


More information about the Mono-devel-list mailing list