Project Summary (1) -- improve ASP. NET performance

Source: Internet
Author: User
Tags set cookie

Recently, I just finished a B2C e-commerce WEB site. Now let's make a summary of the project. The first thing to talk about is the performance of ASP. NET.

1. When it comes to ASP. NET performance, you can't leave ViewState alone. I don't need to say that everyone knows that this item consumes more system resources, especially when there is a large amount of page data.

Therefore, the most direct method is to disable ViewState in Web. Config. When used, enable it in the page. In fact, the ViewState size also corresponds to the server used

The complexity of the control is related. The more obvious impact on the performance is the GridView. When loading a lot of data, the value of ViewState is very large.

2. We often use Session when storing temporary data, but when the server is overloaded, the server will clear some Session variables. So if we store

It is the user's shopping information, so this is what we do not want to see, the best choice is the Cookie, although some people say that reading the Cookie is slow, but this effect is not particularly obvious

Cookie is a good choice. We can use it to store user information and shopping commodity information, which can reduce the server burden caused by Session usage. But here

One small problem is that when a user exits or submits an order to delete the items in the Cookie, we usually use setting the Cookie. Expires attribute to invalidate the Cookie,

I don't know if this is the case. Using C # to invalidate a Cookie is sometimes different from using JavaScript to invalidate a Cookie, for example... The time for a computer is no longer allowed...

We set the expiration time from the server side, which may not work. So the best way is to use JavaScript to set Cookie expiration. So that the browser can delete the Cookie.

3. A large number of stored procedures in the database will also be high-performance, because the stored procedures are compiled and executed on the database server. The first slow (Compiled) process will run later.

Fast. Creating an index for a table also improves the overall performance of the program. These are all tested. I used to query 6 million records, but the execution time for no index was not set.

So it is more than 70 times.

4. Most of the algorithms that affect performance mainly come from the program itself.

A. N accidental box disassembly operations.

B. The number of cycles is too large (for optimization purposes, most cycles cannot optimize the number of cycles), and the level of objects inside the loop is too deep. I will take JavaScript as an example here, and C # will also have a similar situation.

Function CycTest ()
{
For (var I = 0; I <1000; I ++)
{
Var HtmlObject = document. GetElementById ("EmelentID ");
HtmlObject. innerHTML = "Hello World ";
}

}

 

After the above Code is optimized

1 function CycTest ()
2 {
3 var HtmlObject = document. GetElementById ("EmelentID ");
4
5 for (var I = 0; I <1000; I ++)
6 {
7 HtmlObject. innerHTML = "Hello World ";
8}
9
10}

5. It is the cache, which is known to. NET users. In addition, some frequently-used data can be stored in an XML file, which is much faster than reading an XML file from a database. Or simply put it in the Cache. Read Memory is faster than read files.

6. if a page contains multiple business logic operations, it is best to break them into multiple pages, although it may take longer for a user to click multiple pages in a row than that of multiple business logic on a single page, the user's page in a single business logic is relatively short.

Although the continuous time is longer, it is much better for the user experience to wait for to process multiple business logic. Of course, Ajax technology can also be used to display pending operations. ASP. NET technology is more convenient for real data and has good performance, but if it involves multiple times

It is best to use Ajax for user interaction operations accompanied by PAGE refreshing. In my opinion, JavaScript is used for implementation. I used to bind a group of ImageButton controls dynamically in a Repeater.

As you can imagine, in this era of tight network bandwidth, when the network is poor, it takes about three seconds to wait, later, it was much better to bind the HTML control of the IMG client and then implement style Switching Using JS.

7. If the code structure of the page is chaotic, the HTML code of the design page may also affect the performance. That is, some people say that "spaces" sometimes affect performance. This is related to the control tree generated by ASP. NET. Of course, if it is not especially demanding performance

Ignore. If we do not use the space program, the readability will be deteriorated.

From the macro perspective, there are many ways to improve the program running efficiency, such as int in type conversion. prase () is worse than Convert. toInt32 () is better, and Sdr is also used when SqlDataReader is used. getString (0) is more efficient than Sdr ["DataField"], but has poor maintainability. Different approaches also vary based on different needs.

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.