We have a rather complex page that loads the user controls dynamically (some of them are nested). It is a very slow performing page.
Could adding the controls dynamically be adding to the bottleneck? Would it help if we add the control in the .NET cache object and not use LoadControl if it already exists in the cache?
Any other tips/strategies on making the page faster?
We once improved an ASP.Net project performance by an order of magnitude. Here is a list of the things we tried:
- Set SessionState to false or ReadOnly when possible. Note that the method for setting session state is different for ASPages, web services, and applications.
- Store session state in-process if possible.
- Set EnableViewState to false when possible.
- Use caching when possible.
- Use HTML controls instead of server-side controls if you do not need access to the control from the server.
- Avoid round trips (submitting data to the server and reloading the page) when possible. Note that you only need to round-trip to read data from, or write data to, the server. Validation and feedback can be done client-side. Use the IsPostBack property in Page_Load to avoid regenerating data on postback.
- Use the StringBuilder class for repetitive concatenation.
- Use try/catch blocks only for unexpected situations; do not use them as general control constructs.
- Use early binding as much as possible. In other words, avoid reflection.
- Avoid unmanaged code such as COM.
- Disable debug mode for shipping apps.
- Use stored procedures for database access rather than SQL strings.
- Use the DataReader classes for reading data rather than DataSets.
- Use the most restrictive classes possible, such as SqlDataReader rather than DbDataReader.