Mobile development RSS CSDN home> Mobile development

Three behaviors to prevent developers from getting high performance!

Published in11:43 2016-06-12| Time reading| sourceCSDN| ZeroArticle comments| authorIntel

Abstract:Performance is one of the most important non functional requirements. If you are reading this article, then you may be using an application such as a browser or a file reader, so you should understand the importance of performance. In this paper, we will discuss the application of high performance as well as the development of the three kinds of behavior can not achieve high performance.

brief introduction

Performance is one of the most important non functional requirements. If you are reading this article, then you may be using an application such as a browser or a file reader, so you should understand the importance of performance. In this paper, we will discuss the application of high performance as well as the development of the three kinds of behavior can not achieve high performance.

The first act: the lack of understanding of the development of Technology

Whether you are just graduated, or have many years of development experience, when the development, you need to know about the products have been developed. It is best to use the same programming language.

This is not a bad thing. In fact, doing so usually speeds up the development of the speed. But, on the other hand, it also prevents you from learning something. Because this method rarely involves spending time checking the code, as well as understanding the algorithm and the inner workings of each line of code.

This is an example of the first behavior that a developer might have. Besides, there are other ways. For example, when I was young, I just started to develop software, I was the boss of my role model, he no matter what can do the best. I will learn his experience and copy as much as I can for any development. Most of the time I don't quite understand why his method is feasible, but who cares, right? Anyway it is feasible!

There is a developer, I call it "4x4" ". He or she will do whatever it is asked to do, and do it as well as she can. They often find building blocks or completed code fragments, put them together to give up. Things are done! Such developers rarely take time to understand all the fragments of their discovery, do not consider or investigate scalability, maintainability or performance.

There is also a situation that developers do not understand the actual operation of the code: never encountered any problems! When a technology is used for the first time, if you have a problem, you will have a thorough understanding of the technical details, and finally understand how it works.

On this point, we look at some examples, to understand the difference between understanding technology and the use of technology only. Most of the time, I'm a web.NET* developer, and I'm going to put a lot of effort into it.

JavaScript* and document object model (DOM)

We look at the following code fragment. Quite common. The code has just updated the style of an element in the DOM. The problem (which is no longer a problem in modern browsers, where the reference is to explain the point) is that it uses the DOM tree back and forth between the three times. If the code is repeated several times, and the document is larger and complex, it will affect the performance of the application.

To solve this problem is very simple. Let's take a look at the following code fragment. Variable before processing projectMyFieldA direct reference to the. The new code is not too long, can read and understand faster, and has a higher performance, because there is only one DOM tree interface.

We look at another example. The sample source is as follows:Http://

In the following figure, there are two identical code segments. Each code can create one thousand list itemsLiElements. On the right side of the code for eachLiElement to add aIDProperty, but the left side of the code is available to eachLiElement to add aClassProperties.

As you can see, each of the second parts of the code fragment will be accessed by each of the createdLiElement (a total of one thousand). I am in Explorer* Internet 10 and Chrome* 48 in the benchmark test, the average time spent on the left side of the code is 57 MS, the right side of the code is 9 ms, the right side is significantly less. In this case, when you use different ways to access the elements, the difference is very large.

Should be very careful when using the sample! There are a number of other content to be understood in this example, otherwise it will go wrong, such as evaluating the order of the selector (from right to left). If you use jQuery*, then you need to know about the DOM environment. For the conventional CSS selector performance concept, see the following article:Https://

Next we in the last example JavaScript code tree. This example is a greater relationship with memory, but it can help you understand the way you run. High memory consumption in the browser also causes performance problems.

The next picture shows two ways to create an object using two properties and one method. On the left, the class constructor adds two attributes to the object, and then a method is added to the prototype of the class. On the right side, the constructor adds both properties and methods.

After the object is created, it will be created with one thousand objects using two techniques. If you compare the memory used by the object, you will find the difference in memory usage between the two methods in Shallow Size and Size Chrome. The prototype method used in the Size Shallow memory is less 20% (20 VS Kb 24 Kb), in the Memory Retained reference parameters of 66% (20 VS Kb 60 Kb).

For a better understanding of how Size Retained and Size Shallow memory is to be operated, see:

Https:// Hl=en?

By understanding how to use the technology, you can create objects. But understanding how technology works can help you improve your application from memory management and performance.


I am preparing for the theme of the conference presentation, you want to provide a server side code examples. I decided to use LINQ*, because LINQ has become a direct tool for the development of the.NET environment, and is most likely to improve the performance of the field.

Think about this common scene. In the following picture, there are two functionally equivalent code segments. The purpose of the code is to list all of the school's department and all the courses in each department. In the title of the N+1 Select code, we list all the lines, and for each of the series out of its course. This means that if there are 100 lines, we will need to execute the 1+100 call to the database.

There are many ways to solve the problem. The display in a simple way. through the use ofIncludeMethod (in this case, in order to understand, I use a hard coded string), just call a database can call up all of the Department and each department of the course. In this case, the implementation of the secondForeachThe collection of all the classes in each system has been saved to the memory.

By avoiding the N+1 Select problem,

We look at a less obvious example.

In the picture below, there is only one difference between the two code segments: the data type of the second row object list. You might ask, what is the difference between a target type and a target type? When you understand how the technology is running, you will realize that the target data type can define the exact time when the query is executed in the database, and then define the filter for each query when the query is applied.

In the #1 Code example, theIEnumerable, then the query will be inTake<Employee> (10)Execute before execution. This means that if there are 1000 employees, then will be retrieved from the database for all employees, and then only use 10 records.

In the #2 Code example, the query will beTake<Employee> (10)Execute after execution. That is, only 10 records are retrieved from the database.

In the following links, the article explains the difference between using multiple sets.


Server* SQL

In SQL, there are many concepts that need to be learned about the best performance from the database. Server SQL is very complex, because it requires the understanding of how the data is used, which form the most frequent queries, which are the field of inquiry.

However, you can still improve performance by applying some common concepts, such as:

  • Cluster index and non cluster index
  • Properly arranged JOIN
  • Know when to use#tempTable and variable table
  • Using view vs indexed views
  • Using pre compiled statements

For the sake of simplicity, I will not provide a specific use case, but the concept of these types is that you can use, understand and make full use of the.

View full text

For more details please see:Intel developer

step on