Also be warned that the following is my own interpretation of the video and I might have missed or could have interpreted some point differently 🙂
I am not going to get into the details of these optimization techniques, but just going to give the list the suggestions.
- Initialize all object members in the constructor functions
- Initialize all object members in the same order.
- Avoid adding new properties at runtime
V8 internally uses 31 bit signed integers (refer to the video for the full explanation). So the suggestion is
- Prefer numeric values that can be represented as 31 bit signed integers
V8 uses two types of objects to represent arrays
- Fast Elements – linear storage for compact key sets
- Dict Elements – hash table storage.
Out of these two, Fast Elements are generally preferred. So the suggestions are
- Use contiguous keys starting at 0 for arrays
- Don’t pre-allocate large arrays, instead grow them
- Don’t delete elements in an array if possible
- Don’t load uninitialized or deleted elements
- Use array literals instead for small fixed arrays
- Preallocate small arrays to correct size before using them
- Don’t store non-numeric values (objects) in numeric arrays
- Prefer monomorphic operations over polymorphic operations
- Don’t have performance sensitive code inside a try..catch block. Instead use a separate function and then enclose the function inside try..catch block.
Some V8 logging commands
And finally here is the full video.
So my dear readers what you think about my notes. Also let me know if you like notes for videos in this format. If there is a demand, then I can post some of my notes on other videos which I have already viewed.
Leave a Reply