Integrating Static Optimization and Dynamic Nature in JavaScript
Abstract
The class definitions and class field declarations in the ECMAScript standard suggest that the JavaScript engines could be optimized like class-based static languages. This paper focuses on two well-known optimizations. One is method specialization, using fixed offsets to access properties. The other is prior hidden class construction, which involves creating runtime class-like structures called hidden classes before creating instances of the classes. However, implementing such optimizations into JavaScript faces difficulties because of its dynamic features. We point out three difficulties that must be overcome and propose reasonable solutions. We implemented these optimizations and solutions in QuickJS, a small, practical JavaScript engine, and obtained promising results.