The application server or load-balanced servers might enhance Web application performance; however, there are ways to enhance performance on the developer side as well. By following certain optimization techniques while you are writing your application code, you can also reduce a lot of performance issues. It is essential to understand which parts of your code can be optimized, and how you can measure improvements in performance compared to a baseline.
- Use the connection pooling so that the connections can be re-used when future requests to the database are required.
- Dispose of objects properly from the caller method than in the called method.
- Reduce page load times by techniques such as minimizing the scripts. Use script file references in pages to enable the client to cache these scripts for subsequent requests.
- Remove white spaces and extra tags to dramatically reduce the size of your pages. Limit the use of graphics and consider using compressed graphics.
- Consider using cascading style sheets to avoid sending the same formatting directives to the client repeatedly.
- Control names should be short because they generate unique HTMLID names. If a control is used inside nested controls, a 10-character control name can easily turn into 30 to 40 characters.
- Use Page.IsPostBack to minimize redundant processing.
- Use for each loop in place of a for loop if possible.
- You should avoid using ViewState to facilitate faster page loads. Remove the runat="server" form tag from your Web page if you don't need to use ViewState to save bytes of the page size. Enabling its ViewState would incur, for every byte that is added, becoming two bytes due to network traffic that is from the server to the client and the other from the client to the server.
- Cache the Web pages or portion of the Web pages if the page is large. Use data caching for boosting the application performance instead of fetching data from a file or database.
- As the datasets store data in memory, write efficient SQL queries or procedures that fetch only the information needed. Analyze the WHERE clause in your queries and be specific to ensure that the needed number of rows and columns are returned and take the advantage of indexes while writing queries.
- Consider Using Server.Transfer instead of Response.Redirect because Response.Redirect sends a metatag to the client that makes the client send a new request to the server by using the new URL. Server.Transfer avoids this re-direction by making a server-side call.
- Avoid using Page.DataBind. Instead, call data bind on specific controls because the page-level method in turn calls the DataBind method of every control on the page that supports data binding.
- Minimize calls to DataBinder.Eval because this method uses reflection to evaluate the arguments that are passed in and to return the results. For example, if a page has a table with 50 rows and 10 columns, DataBinder.Eval will be called 500 times if you use DataBinder.Eval on each column. Instead, using explicit casting offers better performance by avoiding the cost of reflection. Cast the Container.DataItem as a DataRowView, as shown in the following code snippet.
- Use SqlDataReader to visit the read-only data instead of DataSet.
- Although you can return multiple result sets by using dynamic SQL, it is preferable to use stored procedures to get multiple result sets.
- Using gzip compression can decrease the number of bytes sent by the server. This gives the perception of faster page loads and also cuts down on bandwidth usage.
- If you got a bunch of .NET Web services running in one IIS Application and consumed by another IIS application, the first call to Web services, in many cases, can be pretty slow, about 5 to 10 seconds or more sometimes; subsequent calls will be in milliseconds. To speed up the initial call, you can create the XmlSerializers DLL at compile time.
Conclusion
In my previous article, "ASP.NET Performance Improvements and VS2015 Profiler," I showed how you can use the Visual Studio 2015 diagnostic tools that integrate application profiling with the debugging so that you can observe the CPU usage, memory usage, HTML UI responsiveness, thread activity timeline, and profiler for performance. By using what I presented in that article along with the optimization tips you've learned here, you have the tools for writing high quality code where you can catch and fix performance and other issues in development as well as after deployment.
Copy From http://www.codeguru.com/csharp/.net/net_asp/asp.net-application-optimization-tips.html
No comments:
Post a Comment