Daniel Clifford gave a wonderful speech at Google I/O 2012, "Breaking the Javascript Speed Limit
With V8 ". In his speech, he explained 13 simple CodeThe optimization method allows your code to compile/run your JavaScript code more quickly in Chrome's V8 JavaScript Engine. In his speech, he explained how to optimize and why. The following briefly lists the key points of optimization:
1. Initialize all objects in the constructor
2. Always initialize objects in the same order
3. Use numbers whenever possible
4. Use a continuous primary key starting from 0 for the Array
5. Do not allocate large arrays (> 64 K) in advance. You should expand the array during use.
6. Do not delete elements in the array.
7. Do not install uninitialized or deleted elements.
8. For an array of fixed sizes, use "array literals" to initialize
9. Assign the correct space size to the small array before use
10. Do not store non-numeric content in the numeric Array
11. Try to use a single type (monomorphic) instead of a Multi-type (polymorphic)
12. Do not use try {} catch {}
13. Avoid modifying hidden classes in Methods After Optimization