Asp.net performance optimization Summary (2)

Source: Internet
Author: User

I,Use stored procedures:

    1. Performance:Stored Procedures provide many standardsSQLAdvanced features not available in the language. The function of passing parameters and executing logical expressions helps applicationsProgramThe designer processes complex tasks. In addition, the stored procedure is stored on the local server, reducing the network transmission bandwidth and execution time required to execute the process. (The stored procedure hasSQLThe statement is pre-compiled, so the execution speed is faster than that in the program.SQLStatements are much faster)
    2. Program structure: From the Perspective of program scalability, using stored procedures will facilitate subsequent modifications to the program. For example, if the database structure changes, you only need to modify the corresponding storage structure and the calling part of the program.

This part does not fall into the scope of this article, and belongs to the aspect of program structure design. So do not expand here.

3.Program security: Avoid using Stored ProceduresSQL InjectionAttack.

II,Query statement optimization (SQL Server2000)

Many write for the purpose onlySQLStatement, regardlessSQLStatement execution efficiency. Here I only provide a method to optimize the table order ,(SQLThe statement optimization and principles will be implemented in mySQL Server2000Topic discussion in study notes)

PairSQLStatement execution efficiency availableSQL Server2000Query analyzer to view the statement execution process.

Optimize table sequence: Generally,SqlserverAutomatically optimizes the table connection. For example:

Select name, no from

Join B on A. ID = B. ID

Join C on C. ID = A. ID

Where name = 'wang'

AlthoughATable inFromFirst list, thenB,LastC. HoweverSQL ServerIt may be used firstCTable. Its selection principle is to limit the query to a single row or a few rows to reduce the total data volume to be searched in other tables. In most cases,SQL ServerIt will make the best choice, but if you find that a complex join query is slower than expected, you can useSet forceplanStatement forceSQL ServerUse the table in the order that the table appears. In the preceding example, add:Set Forceplan On ....... Set forceplan offThe table will be executed in the order you write. View in query Analyzer2To select the table connection sequence.

*UseSet forceplanSelect Table join Sequence

III,Page optimization (. Aspx)

Mainly for page attributes

1.Enableviewstate (View status of the page). SetFalse.

UseViewstate, Each object must be serializedViewstateAnd then deserialize it through the return.ViewstateThere is no price. Minimize the number of objects to be used.ViewstateThe number of objects in. In this case, you can disableViewstate:

(1) Page Control (. Ascx)

(2) The page is not returned to itself.

(3) You do not need to process controls.

(4Controls do not have dynamic or data-bound attribute values (or for eachPostpackAll inCodeProcessing in progress)

Single page or every page is disabledViewstate, As shown below:

Single page:<% @ Page enableviewstate = "false" %>

Each page:Web. configMedium<Pages enableviewstate = "false"/>

EnablesessionstateRetain the default value.Sessionstate).

EnableviewstatemacIf there are no special security requirements, keep the default value.

2.Pagelayout.Page layout model. RecommendedFlowlayout (Add element without absolute positioning attribute). Gridlayout (Absolute positioning attribute)Because of the absolute positioningFlowlayoutProduce more code, mainly the positioning information of controls.

3When releasing a project, remember to release the pageDebugStatus.

4.HtmlLanguage optimization. My advice is to be proficientHtml/JavaScript, Less useVs. net2003Automatically generated code, which automatically generates uselessHtmlCode.

5. Setting SMART navigation to true can significantly improve user performance. Enabling this attribute has little impact on the client and server. It intelligently renews new parts that need to be renewed.

IV,Control Selection:

HtmlControls and server controls. The convenience and functional implementation of server controls are as follows:HtmlControl is incomparable. However, it is achieved at the sacrifice of server resources. My personal suggestion: IfHtmlThe control does not provide the functions to be implemented, and it can be used with some scripting languages (suchJavascrpt/VBScript. Select the server control. After selecting the server control, you should also optimize its control as much as possible, such as canceling some page states (For details, refer to the control optimization)

Server Control Selection: describes several common data controls:

DataGrid: Comes with the most powerful data display control, built-in data modification, deletion, addition, paging and many other practical functions. If you only need to display data, try not to selectDataGrid(It stores all data inViewstateMedium).Do not use the built-in paging function,MicrosoftI have done a lot of work on the underlying layer of automatic paging. Although it is easy to use, the performance overhead is high. (One-page control is recommended:Http://webdiyer.europe.webmatrixhosting.net/default.aspx)

Datalist: RatioDataGridA lot fewer features. However, the customization is much stronger. The unique multi-row data display brings us a lot of convenience.DataGridIt can basically implement the functions that can be implemented. We recommend that you use it.

Repeater: The minimum number of features, but the customization is very strong. We recommend that you only display data. Due to the reduction of many functions, the performance of the server is minimized. Therefore, for data display, I usually chooseRepeaterThenDatalistLastDataGrid

*Select as much as possibleHtmlControl. Functions that can be implemented on the client are implemented on the client.(ProficientJavascript)To reduce the pressure on the server. Data Control selection order:Repeater,Datalist,DataGrid

V,Server Control Optimization:

1.Viewstate

ControlViewstateAndViewstateIt is basically consistent. Used to save some status of the control.

Processing principles and processing pageViewstateSame. If you are interested, you can useDataGridData Binding Test

ViewstateWhat is the size of the stored data?DataGridSize of data displayed

Is equivalent.

2.Ispostpack

The default value is false. It must be set to true only when an event is generated.

Control optimization mainly depends on your familiarity with the control. The more you understand the internal operation principle of the control, the more appropriate optimization will be made for it.

 

Performance optimization isThree sentences are unclear. What I wrote is only the tip of the iceberg. Performance Optimization relies on the accumulation of experience and constant recognition of the operating principles of the program.

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.