This is the fourth article in a series.
Key points of Code Optimization
Here are the main points based on the previous introduction to V8:
- Objects are added in a particular order to share shapes
- Adding attributes dynamically after instantiation modifies the corresponding Shape, so add them in the constructor.
- Do not modify the array property attribute, otherwise you will need to save the corresponding element in a separate dictionary
- Modifying the stereotype chain invalidityCell, and the corresponding inline cache, should be modified before any other code is executed
- Prevent subsequent memory leaks
A memory leak
A memory leak is a block of memory in the heap that is no longer needed but still has not been released. A large number of memory leaks can cause applications and even systems to slow down or crash without sufficient memory usage.
Since modern browsers no longer use reference counting gc in favor of tag scavenging, methods that cause memory leaks are basically global variables that need to be set to NULL.
Scenarios such as circular references, closures, and so on do not cause memory leaks as long as global references are avoided.