Improve page performance in asp.net

1. Disable the Debug Mode or Set Debug ="false" How it affect performance: By default this attribute is "true" when you create new application and is useful when you are developing the application. Debug = true means that pdb information to be inserted into file and this results a larger file size and it's performance issue. Before deployment you should set the following tag 2. Set trace enabled="false" With help of tracing, we can track the application's and the sequences. Enabling tracing adds performance overhead and might expose private information, so it should be enabled only while an application is being build. You can turn off tracing when your application is done. Using below code you can turn off 3. While developing using Visual Studio.NET When you set Configurations Option as "debug" mode, it creates pdb file to store the debug information hence before deploying the application set it to the "Release" mode. You can set using Select Menu Build -> Configuration Manager -- > Set the configuration option of project to the "Release" mode. 4. Disable the viewstate: With the help of automatic state management feature, the server control is re-populate their values without writing any code. And it affects the performance. The always set EnableViewState = false when not requires. For control For Page <%@ Page EnableViewState="false" %> 5. Use Caching to improve the performance of your application. OutputCaching enables your page to be cached for specific duration and can be made invalid based on various parameters that can be specified. The Cache exists for the duration you specify and until that time, the requests do not go to the server and are served from the Cache. Do not assign cached items a short expiration. Items that expire quickly cause unnecessary turnover in the cache and frequently cause more work for cleanup code and the garbage collector. In case you have static as well as dynamic sections of your page, try to use Partial Caching (Fragment Caching) by breaking up your page into user controls and specify Caching for only those Controls which are more-or-less static. 6. Validate all Input received from the Users. Validate all Input received from the users at client side to avoid the server round trip. 7. Use Finally Method to kill resources. Always use the finally block to kill resources like closing database connection, closing files etc. 8. Always use the String builder to concatenate string The memory representation of string is an array of characters, So on re-assigning the new array of Char is formed & the start address is changed. Thus keeping the old string in memory for garbage collector to be disposed. Hence application is slow down. Always use the string builder for concatenating string. 9. Enable the web gardening for multiprocessors computers The ASP.NET process model helps enable scalability on multiprocessor machines by distributing the work to several processes, one for each CPU, each with processor affinity set to its CPU. The technique is called Web gardening, and can dramatically improve the performance of some applications 10. Enable Page Buffering. Be sure that buffering enables to your page level. Buffering causes the server to buffer the output and send it only after it has finished the processing of the page. If buffering is disabled, the worker process needs to continuously stream responses from all concurrent requests; this can be a significant overhead on memory and the processor, especially when you use the ASP.NET process model. 11. Avoid Server Side validations. In most of the cased we do not look forward about the perforamace of using server side validation, actually it is very time consuming and round trip process to validate the control. So use client side validations and avoid server side validations. 12. Check Page.Isvalid when using validation controls. Always use Page.Isvalid while using validation control to prevent unneccessary it process the page request and goes into the memory. 13. Deploy with the release mode. You should always deploy your application in release mode it actually give your application a 100% performance. 14. Always use if (!IsPostBack) property in your codebehind. It is very good habit to use (!isPostBack) property in your code behind. It prevents unneccessary round trip to your events. 15.Turn off ViewState, SessionState. Turn off ViewState or Session State if it is not required. It gives a speed to your page. 16. Avoid recursive functions / nested loops. Most probabaly we use nested loop, actualy it gives a bad performance on our pages. So avoid using nested loops and recursive functions while you are binding any controls and all. <%@ Page Language="C#" AutoEventWireup="true" Debug="false" Trace="false" Buffer="true" CodeFile="MyPage.aspx.cs" Inherits="MyPage" %> <%@ OutputCache Duration="10" VaryByParam="None" %>

Comments