asp.netperformanceloadcontrol

ASP.NET performance: using LoadControl in for-each


I'm trying to make a decision about how to display my data. What I have now is a list of products displayed in a repeater. But for code-maintenance I've put my product items in a seperate usercontrol and loading them in a loop with db results using LoadControl.

The product control itself is very simple, just a few public properties like title, url, rating but I'm not sure if this will affect my performance. I did some reading here and on forums and some people say it's not the best practice especially if you have more then 20 or 30 of these controls.

So, is it really a performance hit using this method or does it stay ok with around 10.000 hits a day. Any other suggestions are welcome as well.


Solution

  • I did some testing because I was interested in this as well, and it seems that there is like a pretty significant performance hit on LoadControl compared to instantiating a normal class.

    I tested creating 100,000 instances of a simple class with one property vs 100,000 instances of loadcontrol loading a new blank control. And it was 16ms for the classes vs 1950ms for the load control. There seems to be a lot of overhead. I did notice that if I added more constituent controls to the user control the load time went up. (this is just the load I did not actually add the controls to the page or render them)

    Is it enough of a hit to be noticeable to a user? Probably not unless you are loading a large amount of instances with loadcontrol.