Summary of performance optimization of asp.net (ii.)

Source: Internet
Author: User
Tags join sql injection
Asp.net| Performance Optimization Summary of optimization asp.net performance

First, use stored procedures:

Performance aspects: Stored procedures provide advanced features that are not available in many standard SQL languages. Its ability to pass parameters and execute logical expressions helps application designers deal with complex tasks. In addition, stored procedures are stored on the local server, reducing the network transmission bandwidth and execution time required to perform the process. (The stored procedure has precompiled the SQL statement so that it executes much faster than executing the SQL statement in the program)
Program structure: From the scalability of the program, the use of stored procedures will be easy to modify the program later. For example, the structure of the database changed, just modify the corresponding storage structure, and the call part of the program can be.
This part does not belong to the scope of this article, which belongs to the design of program structure. So do not unfold here.

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

II. Optimization of query statements (for SQL server2000)

Many people write SQL statements for purposes only, regardless of the execution efficiency of SQL statements. Here I only provide a way to optimize the order of the Tables (SQL statement optimization and principles will be in my SQL server2000 learning notes in the discussion)

Efficiency of SQL statement execution the SQL server2000 Query Analyzer can be used to view the execution of the statement.

Optimize table order: In general, SQL Server automatically optimizes the connection to a table. For example:

Select Name,no from A

Join B on A. id=b.id

Join C on C.id=a.id

Where Name= ' Wang '

Although table A is listed first in from, then B, and finally C. However, SQL Server may first use the C table. Its selection principle is to reduce the total amount of data found in other tables relative to the query by restricting it to a single line or a few rows. In most cases, SQL Server makes the best choice, but if you find that a complex join query is slower than expected, you can use the SET FORCEPLAN statement to force SQL Server to use the table in the order in which it appears. As the previous example adds: Set Forceplan On.......set Forceplan the order in which the off table is executed will be executed in the order you write. View 2 execution efficiencies in Query Analyzer to select the connection order of the tables.

* Use SET Forceplan to select Table Join order

Third, the optimization of the page (. aspx)

Mainly for several page properties

1. EnableViewState (view state of the page). If no special requirements are set to false.

With ViewState, each object must be serialized into the ViewState and then deserialized by a postback, so there is no cost to using ViewState. Minimize the use of objects and, if possible, minimize the number of objects placed in ViewState. The following situation can basically disable ViewState:

(1) Page control (. ascx)

(2) The page is not passed back to itself.

(3) You do not need to handle the control's events.

(4) The control has no dynamic or data-bound property value (or is handled in code for each postpack)

A single page or every page disables ViewState, as follows:

Single page: <%@ page enableviewstate= "False"%>

Each page: <pages enableviewstate= "false" in Web.config/>

EnableSessionState Keep the default value (it will not occupy resources if the page uses sessionstate).

enableViewStateMac Keep the default value if there is no security specific requirement.

2. pagelayout. Page layout model. It is recommended that you use FlowLayout (elements are added without an absolute positioning attribute). Gridlayout (absolute positioning attribute), because of absolute positioning, will produce more code than FlowLayout, mainly the positioning information of the control.

3. Remember to release the debug status of the page when the project is published.

4. Optimization of HTML language. My advice is to master Html/javascript, use less vs.net2003 automatically produced code, it will automatically generate some useless HTML code.

5. Smart navigation is set to true to improve the user's perceived performance. Enabling this property has little impact on the client and server side. It can be smart to rinse new needs to rinse new parts that need to be shabu-shabu.

Iv. Selection of controls:

The selection of HTML controls and server controls. The convenience of server controls and the implementation of functionality are unmatched by HTML controls. But it is achieved at the expense of server-side resources. My personal recommendation: If the HTML control does not reach the functionality that is to be implemented, and some scripting language (such as javascrpt/vbscript) can not achieve the combination. The server control is selected. When you select a server control, you also try to optimize its controls, such as canceling some page state (see the control Optimization)

Server control selection: mainly for several commonly used data controls to explain:

DataGrid: With the most powerful data display control, built-in data modification, deletion, add, paging and many other practical functions. If you only need to show the data, try not to select the DataGrid (it stores the data in ViewState). Also, do not use the paging feature, Microsoft has done a lot of work at the bottom of the automatic paging, although it is convenient to use, but the performance overhead. (Recommended one-page control: http://webdiyer.europe.webmatrixhosting.net/default.aspx)

DataList: A lot less than the DataGrid function. But the customization is much stronger. The unique multiline data show that it brings us a lot of convenience. The function that the DataGrid can achieve, it basically can achieve. So it is recommended to use it.

Repeater: Features are minimal, but customization is very strong. If you only need to show the data, use the recommended. The server's performance is minimized because of the reduced functionality. So if it's on the data, I basically choose Repeater and DataList the final DataGrid.

* Choose HTML controls as much as possible. The functionality that can be implemented on the client side is implemented on the client side (mastering JavaScript) to reduce server pressure. Data Control Selection Order: Repeater, DataList, DataGrid

Five, server control optimization:

1. Viewstate

The viewstate of the control is basically consistent with the viewstate of the page. Used to save some of the state of a control.

The processing principle is the same as the viewstate of the processing page. Interested can be tested with DataGrid binding data

ViewState how much data is saved, the data it holds is basic and the amount of data displayed in the DataGrid

is equivalent.

2. Ispostpack

Default false. Set to True when you need to generate an event.

Control, primarily to see how familiar you are with this control. The more you understand the principle of the internal workings of a control, the better you can optimize it.



Performance optimization is 32 words, I write is only the tip of the iceberg, performance optimization is to rely on the accumulation of experience and the process of the operation of the principle of continuous recognition.

If there is a mistake, please raise it. Due to some irresistible factors. This article is written here. Have time to continue to add.





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.