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:
将Trace =“true”添加到@Page指令中,您将能够看到哪些方法花费的时间最长。
I'd be a bit surprised if simply loading the controls dynamically incurred a large performance cost. However, if there are a lot of controls, and they are deeply nested, ASP.NET can sometimes be quite slow to render them to html. Obviously, do profiling as others have suggested to determine where your bottleneck really lies.
One thing to check, for a complex page, is the size of the rendered html. With many server controls, the page size can climb up to multiple megabytes surprisingly quickly. Turning on or tweaking your http compression may be the answer you're looking for.
The first step in investigating performance issues is identifying the bottleneck: is it network traffic (too many HTTP requests? too much HTML coming down the pipe?) or CPU bound on the server? or too many database calls?
In many cases it's the sheer size of the page that causes slowdowns. If you're including a lot of controls on your page then there will be a lot of HTML, so if you do a view source on the final rendered product and find 20000 lines of HTML/javascript then it's likely that the slowdown is too much data being sent over the network.
I suggest using a tool like YSlow to help gain a better understanding of the final rendered product.
Key items to look at:
loading user controls dynamically is definitely not the reason for slow performance. one thing which generally deters an ASPX page performance dramatically is viewstate. I woudl recommend to take viewstate out of the page [even if you have enabled it on some of the controls].
Store the complete viewstate as a session variable on the server and only transfer the identifier in the viewstate field. you can take a look at the complete article here , the article also gives performance measurement metrics.
I would doubt that its the act of dynamically loading controls that's slowing it down and more the behavior of each control. Do they all hit the DB? I would see if you could streamline the performance of the controls (caching DB calls, etc) before trying to optimize their loading.
I would do some profiling on the page to see where the true slowdowns are occurring. Usually in my experience what I think might be causing the slowdowns in actuality are not the slowest spots. I have found it best to profile my apps/pages when things start running slow, that then gives me very good info on what areas I could best speed up to get dramatic improvents. You could find it is too many DB calls, or the usercontrol loading, or something else that you hadn't considered.
There are so many reasons why a web page can be a slow performer. You really need to use some tools like the Performance Wizard to start nailing down what's going on.
Our latest performance problems boiled down to anonymous types and linq. It is so easy to kill performance with those two things due to all the JIT compiling going on.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.