Eight suggestions on ASP. NET performance optimization

Source: Internet
Author: User

1. database access performance optimization
A. Minimize database connections and make full use of each database connection: It is overhead to create, open, and close A connection. Available connection pool
B. Rational Use of stored procedures: stored procedures are a set of pre-compiled SQL statements stored on the server. Using Stored Procedures can avoid SQL compilation multiple times, and subsequent queries can reuse previous execution plans. In addition, stored procedures can reduce the network transmission overhead of SQL statements.
C. Optimize SQL statements: This is too much, such as using indexes and views properly to avoid complicated subqueries.
2. String operation performance optimization
A. Use the ToString () method of the Value Type
During the + connection of different types, the boxing operation is converted to the reference type and then added to the string. The boxing operation will allocate a new object in the managed heap and copy the original value to the new object at a high cost. The ToString () method can be used to avoid packing and thus improve performance.
B. Use the StringBuilder class
3. Disable the debugging mode.
4. cache data and page output whenever possible
5. Do not rely on exceptions in the code to control the normal process of the program.
The exception overhead is large. Therefore, use exceptions with caution.
6. Use Page. IsPostBack to avoid unnecessary handling during the round-trip process.
Copy codeThe Code is as follows:
Void Page_Load (Object sender, EventArgs e) // Set up a connection and command
{
If (! Page. IsPostBack) // data is filled during the first loading.
{
String query = "select * from Authors where FirstName like '% JUSTIN % '";
MyCommand. Fill (ds, "Authors ");
MyDataGrid. DataBind ();
}
}

7. If you do not use the session status, you can disable it or set read-only
A. to disable the session Status of A Page, set the EnableSessionState attribute in the @ Page command to false. For example:
Copy codeThe Code is as follows:
<% @ Page EnableSessionState = "false" %>

B. If the Page needs to access session variables, but you do not want to create or modify them, set the EnableSessionState attribute in the @ Page command to ReadOnly.
8. Use mature tools for Performance Testing

Related Article

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.