1. Four Basic Data Access Locations in JavaScript: literally, local variables, array elements, and object members. Generally speaking: [literal, local variable] Running Speed & gt; [array, object member] 2. Internal attributes include a set of objects in the scope created by a function. This set is called the scope chain. 3. Execute the function-& gt; create the execution environment-& gt; create the activity object (that is, the variable object during function runtime ). So many
1. Four Basic Data Access Locations in JavaScript: literally, local variables, array elements, and object members.
Generally speaking: [literal, local variable] running speed> [array, object member]
2. The internal attribute contains a set of objects in the scope created by a function. This set is called the scope chain.
3. Execute the function-> Create an execution environment-> Create an activity object (that is, a variable object during function runtime ).
Therefore, multiple calls to the same function may lead to the creation of multiple execution environments.
4. Function Execution Process
Every time a variable is encountered, it will go through an identifier parsing process, where data is obtained or stored. This process searches for the scope chain of the execution environment. This search process affects performance.
5. Performance of identifier resolution
Global variables always exist in the execution environment scope.
End. Local variables are parsed by the first proper position.
Rule of thumb: If a cross-scope value is referenced more than once in a function, it is stored in a local variable.
For example:
Function initUI () {var bd = document. body; // There are multiple calls to the Global Object doucument.} //-> after optimization, function initUI () {var doc = document; bd = doc. body; // store the reference of the Global Object doucument to the local variable doc}
6. Change the scope chain
Generally, the scope chain of an execution environment will not change.
<1> with can temporarily change the scope chain
Width is used to create a variable for all attributes of an object.
function initUI(){ with(document){ var bd=body; }}
When the code is executed to,The scope chain of the execution environment has been temporarily changed. A new variable object is created. It contains all the attributes of the specified object.This object is pushed to the scope chain.FirstSo all the local variables are in the second scope chain object, so the access cost is higher.
<2> try-catch
When an error occurs in the try statement, the execution process automatically jumps to the catch.Then, push the exception object into a variable object and place it at the top of the scope.
Note:: Once the catch sub-statement is executed, the scope chain will return to the previous state.
7. performance problems caused by closures
Closures are one of the most powerful features of JavaScript.
Because the closure contains the reference of the same object executed with the Environment scope chain, the function's activity object will not be destroyed, resulting in more memory overhead.
Performance:When you frequently access cross-scope identifiers, each access will result in performance loss.
Start: 19: 41: 45 2015-11-21 reference from by Aaron:/content/3493261.html
8. Memory leakage
Memory leakage means that a piece of allocated memory can neither be used nor recycled until the browser process ends. In C ++, memory leakage is often caused by manual memory management. Currently, popular languages such as C # and Java use the automatic garbage collection method to manage memory. Normally, there will be almost no memory leakage. The browser also uses the automatic garbage collection method to manage memory. However, memory leakage may occur due to a bug in the browser garbage collection method.
Memory leakage
Loop reference
Javascript Closure
DOM Insertion Sequence
A dom object is referenced by a Javascript object, and the same or other Javascript objects are referenced at the same time. This DOM object may cause memory leakage. Reference of this DOM object will not be reclaimed by the garbage collector when the script is stopped. To break the circular reference, the reference of the DOM element object or DOM object must be assigned null.
The details are discussed in depth. The summary here
JS Memory leakage. It's no wonder that the element is removed from the DOM, but there are still variables or objects that reference the DOM object. Memory cannot be deleted. The browser memory usage remains high. This memory usage will be automatically released as the browser refreshes.
Another case is loop reference, where a DOM object and JS object are referenced to each other. In this case, the situation is more serious, and the memory will not decrease even if it is refreshed. This is strictly the memory leakage.
The above is the content for implementing high-performance JavaScript data storage. For more information, see the PHP Chinese website (www.php1.cn )!