How to maximize the improvement. NET Performance (cont.)

Source: Internet
Author: User
Tags comments config static class

Yesterday I sent an article on how to maximize the improvement. NET performance of the article, commented on a lot of people here, thank you very much for your comments, some of which are pointing out some of the mistakes of the article, here thanks to those who patiently write the comments of the boss, younger brother benefited a lot.

Yesterday the article is mainly from the code to improve the speed of some of the details, it may be difficult to actually feel the performance of the improvement, but as a programmer, constantly improve the quality of their code is the constant pursuit of the goal.

In fact, with the development of hardware, now the speed of hardware has been far enough to meet the needs of most people, and even some people have proposed algorithms in the software development is increasingly ineffective. I remember seeing the data structure video of Massachusetts before, and the professor at the lecture asked a question (I don't remember very well, he probably meant it): Now that the algorithms are not important, why do we have to study them here? He gave the answer is "SPEED", we pursue speed as the race car to pursue speed!

Now many system development will not put the speed first, others such as: stability, security, reusability and so on are often the highest priority. Design patterns, development architectures, and so on are not primarily designed to address performance issues. These are the analysts, architects, and some of our little programmers can only optimize the program in small parts of the code, a class, a method, a line of code. I think it's good to pay more attention to the details.

Okay nonsense said a lot, now to say today's theme, now developed a lot of network system performance costs are mainly in the data reading, transmission, faster reading speed, less network bandwidth consumption is our pursuit of the goal. I'll talk about how to improve. NET performance in this respect.

1. Paging data at the data layer. Can be achieved through the excutereader or stored procedures, a lot of ways, I will not say more. (Take a look at what I wrote)

2. Use Excutereader to read data as much as possible, Excutereader is the most efficient, and PetShop 4.0 of all data access in Microsoft is implemented with Excutereader unless you have special requirements for connectionless ( SmartClient smart client, etc.).

3. In disconnected situations, using a DataTable is better than using a dataset unless you want to save multiple relational tables.

4. Use the ImportRow method of the DataTable.
Some occasions need to copy a large amount of data from a DataTable to another DataTable, the use of the ImportRow method of DataTable can greatly improve performance, the data volume is not much different, when the amount of data to more than 10,000 lines can be significantly improved, can reach several times.

    5. Serialize the data into binary files for easy transmission.
     We can serialize to XML files when we process dataset,datatable objects, and if we want to transmit on the network, XML files will generate memory, network bandwidth and other resource problems. Then we can serialize it as a binary file, so the resulting file will be reduced a lot, the code is as follows:
       FileStream fs = new FileStream (@) Xmldata.bin ", FileMode.Create);
       BinaryFormatter bf = new BinaryFormatter ();
       BF. Serialize (Fs,xmldata);
       Fs.colse ();
     This generated binaries are called xmlbinary, open with Winhex, and you can see some XML tags inside, and if the data is large, add a line of code:
      Xmldata.remortingformat = serializationformat.binary;
     The resulting file is called a truebinary file, and the size of the file generated when handling a large number (more than 10000 rows) is one of the xmlbinary. The pattern is automatically saved when serializing, so the process of sequencing is simple. I do not yet know how much the solution will degrade directly from reading XML.
    6. Reasonable use of connection pool. The
    connection pool has a significant effect on performance and is turned on by default. The default min Pool size is 0, which is generally set to a relatively small value, such as 5. Max Pool size defaults to 100, most Web sites are sufficient, and large size increases appropriately.

7. Using SQLCLR Development
If you are focused on the SQL Server series then you should go and study sqlclr, which is very powerful and can improve performance (especially for large enterprise applications) on many occasions.

8. Access to app.config/web.config through static classes
We have a lot of configuration information is placed in the App.config/web.config, Access will be very frequent, when the establishment of a static class, all properties are accessed through static classes, can improve performance to some extent, static class is only instantiated once, and app.config/ Web.config will produce a lot of IO operations.
public static Class Mywebconfig

Static Mywebconfig ()
ConnString =


public static string dbconnectionstring
return connstring;

Well, write here today, there are some mistakes and inadequacies of the place to point out, welcome to put forward better views and common progress.

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: 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.