.NETGURU
user control design and performance questions
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngspeed' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

agaisin@currentechonline.com
-- Moved from [aspngarchitecture] to [aspngspeed] by Charles M. Carroll <Click here to reveal e-mail address> --Is there any (significant) performance hit in using user controls (.ascx)? What about dynamically loading user controls?It certainly makes life easier to be able to encapsulate layout/functionality into user controls etc... but is there such a thing as overusing user controls? What if I have a user control that contains other user controls and so on etc...? Is there cause for concern? Am I going to be reading in a year from now in "25+ performance tips for ASP.NET" or in "Server Performance and Scalability Killers for ASP.NET" ;-) that rule number one is "don't dynamically load user controls unless you have to" and rule number two is "don't use too many levels of nested user controls - i.e. a user control that contains user controls that contain user controls" ?????Or b/c it's all compiled is there really no performance hit to speak of???Even if it were true that performance is negatively affected with user controls, one thing that would compensate is Fragment Caching, but then there's no hard and fast rule and it would depend on many factors (how often does the user control generate new content? i.e. Fragment Caching won't always help...)Are other people getting into the groove and using the rich functionality of ASP.NET or are they being conservative and generating html content dynamically in event handling methods more like in classic asp and then innerhtml'ing it?Would that technique (building html strings manually and innerHTML'ing it) perform significantly better?What about dynamically manipulating server control properties like building a table dynamically like this:...for rowIndex = 0 to rows objRow = new TableRow() for colIndex = 0 to cols objCell = new TableCell() objCell.Controls.add(new LiteralControl ("r" & rowIndex & "c" & colIndex)) objRow.Cells.add(objCell) next placeHolder.Rows.add(objRow)nextIs this a bad practice in general???And what about bubbling up events etc... Is this bad practice performance-wise (we could just info back to the same page on the querystring instead???) or is it a good idea to take advantage of these capabilities??Summary:- Are user controls a performance hit?- Should we be using them anyway?- Should we be wary of designing pages that contain more than x levels of nested user controls?- Should we be wary of manipulating server control properties dynamically (when instead we could generate html content and innerHtml or innerText it)?- Should we be wary of bubbling up events etc...Any and all thoughts and comments would be greatly appreciated!!Thx in advance,Arthur Click here to reveal e-mail address
Reply to this message...
 
    
Steven A Smith (VIP)
> - Are user controls a performance hit?
Yes. According to
http://aspalliance.com/quickstart/aspplus/doc/perftuning.aspx, #5:
Use server controls sparingly and appropriately: Even though it is extremely
easy to use, a server control might not always be the best choice. In many
cases, a simple rendering or databinding substitution will accomplish the same
thing. For example:

> - Should we be using them anyway?
IMHO, yes. You should be caching everything that can be cached. As long as you
are using caching liberally, the perf hit should only rarely be an issue. If
you have data that is not cacheable and is a major perf problem, then I'd
consider eliminating some controls from that page. But until there is a
problem, let caching cover up your "sins".

> - Should we be wary of designing pages that contain more than x levels of
nested user controls?
See #2.
> - Should we be wary of manipulating server control properties dynamically
(when instead we could generate html content and innerHtml or innerText it)?
When possible (and assuming you have a separate graphic artist), you should
avoid programmatically manipulating controls like this using either method
within code. If you can declaratively specify properties, do that wherever
possible. This helps maintain the separation of code from presentation.

> - Should we be wary of bubbling up events etc...
Don't know anything about this - I guess I'll fall back on answer #2...

Steve

Steven Smith, ASP.NET MVP, MCSE+Internet
Click here to reveal e-mail address
President, ASPAlliance.com
http://aspalliance.com The #1 ASP.NET Community
http://aspsmith.com ASP.NET Training for ASP Developers

Learning ASP.NET? Get My Book: ASP.NET By Example
http://www.amazon.com/exec/obidos/ASIN/0789725622/stevenatorasp/

----- Original Message -----
From: <Click here to reveal e-mail address>
To: "aspngspeed" <Click here to reveal e-mail address>
Sent: Thursday, January 10, 2002 5:52 AM
Subject: [aspngspeed] user control design and performance questions

> -- Moved from [aspngarchitecture] to [aspngspeed] by Charles M. Carroll
<Click here to reveal e-mail address> --
[Original message clipped]

What if I have a user control that contains other user controls and so on
etc...?
[Original message clipped]

rule number one is "don't dynamically load user controls unless you have to" and
rule number two is "don't use too many levels of nested user controls - i.e. a
user control that contains user controls that contain user controls" ?????
[Original message clipped]

no hard and fast rule and it would depend on many factors (how often does the
user control generate new content? i.e. Fragment Caching won't always help...)
[Original message clipped]

in event handling methods more like in classic asp and then innerhtml'ing it?
> Would that technique (building html strings manually and innerHTML'ing it)
perform significantly better?
> What about dynamically manipulating server control properties like building a
table dynamically like this:
[Original message clipped]

instead???) or is it a good idea to take advantage of these capabilities??
[Original message clipped]

Reply to this message...
 
    
Susan Warren
Hope you don't mind if I inject my 2 cents here. =20

The whole point of server controls (of all kinds) is developer
productivity. They promote encapsulatation and reuse, and they let you
implement an application in *many* fewer lines of code. This means your
code will be much cheaper to maintain over the lifetime of the
application. These are such huge wins ($$$ wise) that I'd think twice
before giving them up.

Output caching is definitely the way to go for every page that or user
control that can support it. Who cares if rendering the initial request
takes .009 seconds longer with server controls if the next thousands of
requests server as fast as an HTML page? Or, looking at it another way,
how much are you willing to pay to sqeeze a fraction of a second per
*day* out of that page? It's not so much a matter of hiding a sin, as
Steve suggests, it's just often a genuine non-issue when output caching
is in the picture.

Also look for other ways to optimize your server control use, for
example turning off viewstate for the control when possible.

Even consider writing your own controls to encapsulate your custom
rendering logic. Since it's optimized to your application it will
likely be a little bit faster that the generic ones.

Hth,
Susan

-----Original Message-----
From: Steven A Smith [mailto:Click here to reveal e-mail address]=20
Sent: Thursday, January 10, 2002 10:37 PM
To: aspngspeed
Subject: [aspngspeed] Re: user control design and performance questions

> - Are user controls a performance hit?
Yes. According to
http://aspalliance.com/quickstart/aspplus/doc/perftuning.aspx, #5: Use
server controls sparingly and appropriately: Even though it is extremely
easy to use, a server control might not always be the best choice. In
many cases, a simple rendering or databinding substitution will
accomplish the same thing. For example:

> - Should we be using them anyway?
IMHO, yes. You should be caching everything that can be cached. As
long as you are using caching liberally, the perf hit should only rarely
be an issue. If you have data that is not cacheable and is a major perf
problem, then I'd consider eliminating some controls from that page.
But until there is a problem, let caching cover up your "sins".

> - Should we be wary of designing pages that contain more than x levels

> of
nested user controls?
See #2.
[Original message clipped]

it)? When possible (and assuming you have a separate graphic artist),
you should avoid programmatically manipulating controls like this using
either method within code. If you can declaratively specify properties,
do that wherever possible. This helps maintain the separation of code
from presentation.

> - Should we be wary of bubbling up events etc...
Don't know anything about this - I guess I'll fall back on answer #2...

Steve

Steven Smith, ASP.NET MVP, MCSE+Internet
Click here to reveal e-mail address
President, ASPAlliance.com
http://aspalliance.com The #1 ASP.NET Community
http://aspsmith.com ASP.NET Training for ASP Developers

Learning ASP.NET? Get My Book: ASP.NET By Example
http://www.amazon.com/exec/obidos/ASIN/0789725622/stevenatorasp/

----- Original Message -----
From: <Click here to reveal e-mail address>
To: "aspngspeed" <Click here to reveal e-mail address>
Sent: Thursday, January 10, 2002 5:52 AM
Subject: [aspngspeed] user control design and performance questions

[Original message clipped]

controls? What if I have a user control that contains other user
controls and so on etc...?
[Original message clipped]

;-) that rule number one is "don't dynamically load user controls unless
you have to" and rule number two is "don't use too many levels of nested
user controls - i.e. a user control that contains user controls that
contain user controls" ?????
[Original message clipped]

there's no hard and fast rule and it would depend on many factors (how
often does the user control generate new content? i.e. Fragment Caching
won't always help...)
[Original message clipped]

dynamically in event handling methods more like in classic asp and then
innerhtml'ing it?
> Would that technique (building html strings manually and innerHTML'ing

> it)
perform significantly better?
[Original message clipped]

querystring
instead???) or is it a good idea to take advantage of these
capabilities??
[Original message clipped]

it)?
[Original message clipped]

| [aspngspeed] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.asplists.com/asplists/aspngspeed.asp =3D JOIN/QUIT=20
| http://www.asplists.com/search =3D SEARCH Archives

Reply to this message...
 
 
System.Web.UI.LiteralControl
System.Web.UI.WebControls.TableCell
System.Web.UI.WebControls.TableRow




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification