Improving the performance of our JavaScript inheritance model

Netflix Technology Blog
5 min readintermediate
--
View Original

Overview

The article discusses the challenges and solutions in improving the performance of Netflix's JavaScript inheritance model. It highlights the inefficiencies of the traditional _super() method and introduces a new approach using named function expressions to enhance performance and reduce memory usage.

What You'll Learn

1

How to optimize JavaScript inheritance for better performance

2

Why using named function expressions can enhance memory efficiency

3

When to replace traditional inheritance methods in JavaScript

Prerequisites & Requirements

  • Understanding of JavaScript inheritance patterns
  • Familiarity with performance optimization techniques in JavaScript(optional)

Key Questions Answered

What are the performance drawbacks of using the _super() method?
The _super() method implementation is about 70% slower than directly calling the super-class function due to the overhead of invoking closures and regular expression tests. This performance penalty accumulates, especially in memory-constrained environments like TV devices.
How does the new inheritance model improve performance?
The new approach uses named function expressions to eliminate the overhead associated with the _super() method. This results in a 45% faster execution of overridden methods and significant memory savings, allowing for a more responsive user interface.
What memory savings were achieved by changing the inheritance model?
By replacing the _super() method, the codebase reduced memory usage by approximately 12.2 MB, which is significant in constrained environments like single-core Blu-ray players. This reduction helps maintain a stable memory footprint during stress testing.

Key Statistics & Figures

Performance penalty of _super() method
70%
Compared to a direct call to the super-class function
Speed improvement with new method
45%
Faster execution of overridden methods compared to the _super(
Memory usage reduction
12.2 MB
Reduced memory consumption after removing _super(

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Key Actionable Insights

1
Transitioning from the _super() method to named function expressions can significantly enhance performance.
This change is particularly beneficial in environments with limited resources, such as TV devices, where every byte of memory counts and performance is critical for user experience.
2
Regularly profile your JavaScript applications to identify performance bottlenecks.
By understanding where your application consumes the most resources, you can make informed decisions about refactoring and optimizing your code.
3
Consider the implications of using aggressive minifiers on your JavaScript code.
As seen in the article, certain minifiers can obfuscate code in ways that break functionality, highlighting the importance of testing after any build process.

Common Pitfalls

1
Relying on the _super() method can lead to significant performance issues.
This method introduces overhead that can slow down execution, especially in performance-sensitive applications. Developers should consider alternative patterns that minimize such overhead.

Related Concepts

Javascript Inheritance Patterns
Performance Optimization Techniques
Memory Management In Javascript