JavaScript Internals (521 Qs)•Part 7: Execution Context, Functional JS & V8 Engine (404 - 463)
What are the optimization techniques of V8 engine?
V8 engine uses the below optimization techniques.
- Inline expansion: It is a compiler optimization by replacing the function calls with the corresponding function blocks.
- Copy elision: This is a compiler optimization method to prevent expensive extra objects from being duplicated or copied.
- Inline caching: It is a runtime optimization technique where it caches the execution of older tasks those can be lookup while executing the same task in the future.
Practical Code Example
javascript
// V8 Optimization Techniques:
// 1. Hidden Classes: Creates shared internal shapes for objects initialized with same keys
function Point(x, y) {
this.x = x;
this.y = y; // V8 creates one hidden class C0 -> C1 -> C2
}
// 2. Inline Caching (IC): Caches property offset lookups in machine code