ASP.NET eight recommendations for performance optimization

  • 2020-05-19 04:40:37
  • OfStack

1, database access performance optimization
A, minimize database connections, and make the most of every database connection: there is an overhead to creating, opening, and closing a connection. You can use connection pooling
B, fair use of stored procedures: a stored procedure is a precompiled set of SQL stored on the server side. Using stored procedures can avoid multiple compilation of SQL, and subsequent queries can reuse the previous execution plan. In addition, stored procedures can reduce network transport overhead for SQL statements
C, optimize SQL statement: this is too much, such as rational use of indexes, views, and avoid complex subqueries
2. String operation performance optimization
A, ToString() method using the value type
When + concatenation occurs for different types, the boxing operation is converted to the reference type and then added to the string. The boxing operation allocates a new object in the managed heap and copies the original value into the new object, which is expensive. Using the ToString() method can improve performance by avoiding boxing
B, using the StringBuilder class
3. Disable debugging mode
4. Cache data and page output as much as possible as appropriate
5. Don't rely on exceptions in your code to control the normal flow of your program
The outliers are expensive. So use exceptions with caution.
6. Use Page.IsPostBack to avoid unnecessary handling of the round-trip process
 
void Page_Load(Object sender, EventArgs e) // Set up a connection and command 
{ 
if (!Page.IsPostBack) //  The first 1 The data is not populated until the second load  
{ 
String query = "select * from Authors where FirstName like '%JUSTIN%'"; 
myCommand.Fill(ds, "Authors"); 
myDataGrid.DataBind(); 
} 
} 

7. If session state is not used, you can disable it or set it to read only
A. To disable the page's session state, set the EnableSessionState property in the @Page directive to false. Such as:
 
<%@ Page EnableSessionState="false" %> 

B. Note that if the page needs to access session variables, but does not intend to create or modify them, set the EnableSessionState property in the @Page directive to ReadOnly.
8. Use mature tools for performance testing

Related articles: