One . Reduce the level of judgment
As you can see from the code below , The same reduction in effect judgment levels can optimize performance
Two . Reduce the scope chain lookup level
A simple explanation , The first one in the figure below runs foo function ,bar Print in function name,bar There is no name, So the scope chain looks up ,foo Internal name,
But it's actually an assignment , And look up , In the global scope name, Compared to the figure below, the second , More than one level up , So it's going to take a little longer .
（ remarks ： Regardless of memory consumption , It depends on the product .）
3、 ... and . Reduce the number of data reads
A simple explanation , For multiple frequent calls , For example, array , The object is relatively slow , Because according to the reference relationship, we first need to find the location in the heap memory , So reduce the consumption of time ,
You should reduce the number of times you find members , For example, cache it in a variable （ remarks ： Regardless of memory consumption , It depends on the product .）
Four . Literal quantity and construction
A simple explanation , The first one in the picture new Object() It's equivalent to calling a function , It's slow , The second one in the figure below is equivalent to opening up space in the heap area , Put attributes and values in it
Again, for example , The first one in the figure below is just a literal string , And the second one creates a string object .
5、 ... and . Cycle optimization
A simple explanation ： In Figure 2, a frequently used value is cached , Improve the efficiency of implementation .
As shown in the figure below ： Regardless of order ,while Cyclic decrement ratio for loop , More efficient execution
6、 ... and . Reduce the number of statements and statements
A brief explanation : For infrequently used data , Caching first is not recommended , Get it when you execute it , To reduce memory consumption during execution, there is a compilation process before running , expression
It's more , We should split words into lexical units , Then do a grammar analysis , Then turn it into code and execute it , Time is wasted here .
Reduce the number of declared variables, as explained above