Asp. NET Performance Optimization Eight recommendations _ Practical tips

Source: Internet
Author: User
1, Database access performance optimization
A, minimize database connectivity and make the most of each database connection: the creation, opening, and closing of the connection is overhead. You can use connection pooling
B, reasonable use of stored procedures: Stored procedures are stored on the server side of a set of precompiled SQL. Use stored procedures to avoid multiple compilations of SQL, and subsequent queries can reuse previous execution plans. Additionally stored procedures can reduce the network transport overhead of SQL statements
C, optimizing SQL statements: This is too much, such as the rational use of indexes, views, to avoid complex subqueries
2, string operation performance optimization
A, the ToString () method using value types
When a + connection is made to a different type, a boxing operation is converted to a reference type and added to the string. The boxing operation assigns a new object to the managed heap, and the original value is copied to the new object at a high price. Use the ToString () method to avoid boxing, thereby improving performance
B, the use of StringBuilder class
3. Disable Debug mode
4, as long as appropriate, as far as possible to cache data and page output
5, do not rely on the exception in the code to control the normal process
The overhead of the exception is very large. So use exceptions with caution.
6, use Page.IsPostBack to avoid the need to deal with the round-trip process
Copy Code code as follows:

void Page_Load (Object sender, EventArgs e)//Set up a connection and command
{
if (! Page.IsPostBack)////////////////First load
{
String query = "SELECT * from Authors where FirstName like '%justin% '";
Mycommand.fill (ds, "Authors");
Mydatagrid.databind ();
}
}

7. If you do not use session state, you can disable it or set the read-only
A, to disable the session state of a page, set the EnableSessionState property in the @ Page directive to false. For example:
Copy Code code as follows:

<%@ Page enablesessionstate= "false"%>

B, note If the page requires access to session variables, but does not intend to create or modify them, set the EnableSessionState property in the @ Page directive to ReadOnly.
8, the use of sophisticated tools for performance testing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.