ASP.NET Performance Optimization Summary (2)

zhaozj2021-02-17  51

ASP.NET performance optimization summary

First, use the stored procedure:

Performance: The stored procedure provides the advanced features that have not been in many standard SQL languages. It passes the function of parameters and performs logical expressions, which helps application designers handle complex tasks. In addition, the stored procedure is stored on the local server, reducing the network transmission broadband and execution time required to perform the process. (The stored procedure has been precompiled by the SQL statement, so its execution speed is more fast than the SQL statement in the program: From the scalability of the program, the use of the stored procedure will make it easy for the program. . For example, the structure of the database changes, just modify the corresponding storage structure, and the call part in the program.

This part does not belong to this article, which belongs to the program structure design. So don't start here.

3. Program security: Use stored procedures to avoid SQL INJECTION attacks.

Second, the optimization of query statement (for SQL Server2000)

Many people only write the SQL statement for the purpose, regardless of the efficiency of the SQL statement. In this way I only provide an optimization method, (the optimization and principle of SQL statements will be discussed in my SQL Server2000 learning note)

Perform efficiency of SQL statements You can use the SQL Server2000 query analyzer to view the execution process of statements.

Optimization Table Order: Under normal circumstances, SQL Server automatically optimizes the table's connection. E.g:

SELECT NAME, NO from A

Join B on A. ID = B.ID

Join C on C.ID = A.ID

Where name = 'wang'

Although a table is listed first in from, then B, finally C. But SQL Server may first use C tables. Its selection principle is that the query is limited to a single or a few lines, and can reduce the total amount of data found in other tables. In most cases, SQL Server will make the best choice, but if you find that a complex junction query speed is longer than the expected slow, you can use the SET FORCEPLAN statement to use the table to use the table in order. As mentioned in the above example: SET

ForcePlan

On

...... The execution order of the .Set ForcePlan Off table will be performed in the order you are writing. View two execution efficiency in the query analyzer, thereby selecting tables.

* Select the table link order using the set forwardplan selection

Third, the page optimization (.aspx)

Mainly for several page properties

1. EnableViewState (view status of the page). If there is no special request to set to false.

Using ViewState, each object must first serial into ViewState and then reverse sequencing by backhaul, so use viewState is free. Try to minimize the use object, if possible, minus the number of objects placed in ViewState. The following conditions can basically disable the viewState:

(1) Page Control (.ascx)

(2) The page does not return to itself.

(3) No need to process the control.

(4) The control does not have a dynamic or data binding attribute value (or processed in the code for each postpack)

A single page or each page disables ViewState as shown below:

Single page: <% @ page enableViewState = "false"%>

Each page: In Web.config EnableSessionState Keep the default value (if the page is used to sessionState it will occupy resources).

EnableViewStatemac maintains the default value if there is no safety special request.

2. PageLayout. Page layout model. It is recommended to use FlowLayout (Element without an absolute positioning attribute). GridLayout (absolute positioning attribute) will produce more code than FlowLayout by using absolute positioning, mainly the control of the control.

3. Remember to release the DEBUG status of the page when the project is released.

4. Optimization of HTML language. My suggestion is to master HTML / JavaScript, automatically produce the code that is automatically produced using the vs.net2003, which automatically generates useless HTML code.

5. Smart Navigation is set to TRUE to improve the user's significant performance performance. It has little effect on the client and the server after enabling this property. It can intelligently install a new part of the new part.

Fourth, the choice of control:

HTML control and server control selection. The convenience and functionality of the server control is that the HTML control cannot be comparable. However, it is obtained by sacrificing the resources of the server. I personally suggested that if the HTML control does not meet the functionality to be implemented, and if you combine with some scripting languages ​​(such as JavaSCRPT / VBScript), it cannot be implemented. Select the server control. After selecting the server control, try to optimize its control, if some page status is canceled (the optimization of the control)

Selection of server controls: mainly for several common data controls:

DataGrid: With the most powerful data display control, built a lot of practical features such as modification, deletion, addition, and paging data. If you only need to display the data, try not to choose DataGrid (it stores the data in viewstate). Do not use your own paging function, Microsoft has done a lot of work in the bottom of the automatic paging, although it is convenient, but Performance overhead is large. (Recommended a paging control: http://webdiyer.europe.webmatrixhosting.net/default.aspx)

Datalist: There are a lot more than the DataGrid function. But the customity has a lot. The unique multi-line data shows that we have brought us a lot of convenience. DataGrid can be implemented, it is basically possible. So it is recommended to use it.

Repeater: The ability is very functional, but the customization is very strong. If you only need to display the data, it is recommended to use it. Due to a lot of functions, the performance of the server is minimized. Therefore, if it is displayed for data, I basically select Repeater and then Datalist last DataGrid.

* Try to choose HTML controls. The functionality implemented in the client is implemented in the client (skilled in master JavaScript), reducing the pressure of the server. Data Control Selection Order: Repeater, DataList, DataGrid

V. Optimization of server controls:

1. ViewState

The ViewState of the control is basically consistent with the viewstate of the page. Use to save some status of the control.

Treatment principles and viewstate of the processing page. Interested in data testing with DataGrid binding data

How big is the amount of data saved by ViewState, and the data size it saved and the amount of data displayed by DataGrid.

It is equivalent.

2. ISPOSTPACK

Default false. You need to be set to true when you need an event.

The control is optimized, mainly to see your familiarity of this control. The more understanding the principle of the internal operation of the control, the appropriate optimization will be made. Performance optimization is three or two sentences unclear. I am written is only the angle of the iceberg. The performance of performance is a constant recognition of the accumulation of ordinary experience and the continuous understanding of the procedures.

If there is any error, please ask. Because some irresistible factors. This article is written first. Sometimes continue to add.

转载请注明原文地址:https://www.9cbs.com/read-30574.html

New Post(0)