ABSTRACT
JavaScript performance is often bound by its dynamically typed nature. Compilers do not have access to static type information, making generation of efficient, type-specialized machine code difficult. We seek to solve this problem by inferring types. In this paper we present a hybrid type inference algorithm for JavaScript based on points-to analysis. Our algorithm is fast, in that it pays for itself in the optimizations it enables. Our algorithm is also precise, generating information that closely reflects the program's actual behavior even when analyzing polymorphic code, by augmenting static analysis with run-time type barriers.
We showcase an implementation for Mozilla Firefox's JavaScript engine, demonstrating both performance gains and viability. Through integration with the just-in-time (JIT) compiler in Firefox, we have improved performance on major benchmarks and JavaScript-heavy websites by up to 50%. Inference-enabled compilation is the default compilation mode as of Firefox 9.
- O. Agesen. Constraint-Based Type Inference and Parametric Polymorphism, 1994.Google ScholarCross Ref
- O. Agesen and U. Hölzle. Type feedback vs. concrete type inference: A comparison of optimization techniques for object-oriented languages. In OOPSLA, pages 91--107, 1995. Google ScholarDigital Library
- O. Agesen, J. Palsberg, and M. I. Schwartzbach. Type Inference of Self: Analysis of Objects with Dynamic and Multiple Inheritance. In ECOOP, pages 247--267, 1993. Google ScholarDigital Library
- A. Aiken and B. R. Murphy. Static Type Inference in a Dynamically Typed Language. In POPL, pages 279--290, 1991. Google ScholarDigital Library
- A. Aiken and E. L. Wimmers. Type Inclusion Constraints and Type Inference. In FPCA, pages 31--41, 1993. Google ScholarDigital Library
- L. O. Andersen. Program Analysis and Specialization for the C Programming Language. PhD thesis, DIKU, University of Copenhagen, 1994.Google Scholar
- C. Anderson, S. Drossopoulou, and P. Giannini. Towards Type Inference for JavaScript. In ECOOP, pages 428--452, 2005. Google ScholarDigital Library
- R. Cartwright and M. Fagan. Soft Typing. In PLDI, pages 278--292, 1991. Google ScholarDigital Library
- C. Chambers. The Design and Implementation of the SELF Compiler, an Optimizing Compiler for Object-Oriented Programming Languages. PhD thesis, Department of Computer Science, Stanford, 1992. Google ScholarDigital Library
- C. Chambers and D. Ungar. Customization: Optimizing Compiler Technology for SELF, A Dynamically-Typed Object-Oriented Programming Language. In PLDI, 1989. Google ScholarDigital Library
- M. Chang, E. W. Smith, R. Reitmaier, M. Bebenita, A. Gal, C. Wimmer, B. Eich, and M. Franz. Tracing for Web 3.0: Trace Compilation for the Next Generation Web Applications. In VEE, pages 71--80, 2009. Google ScholarDigital Library
- A. Gal, B. Eich, M. Shaver, D. Anderson, D. Mandelin, M. R. Haghighat, B. Kaplan, G. Hoare, B. Zbarsky, J. Orendorff, J. Ruderman, E. W. Smith, R. Reitmaier, M. Bebenita, M. Chang, and M. Franz. Trace-based just-in-time type specialization for dynamic languages. In PLDI, pages 465--478, 2009. Google ScholarDigital Library
- N. Glew and J. Palsberg. Type-Safe Method Inlining. In ECOOP, pages 525--544, 2002. Google ScholarDigital Library
- U. Hölzle, C. Chambers, and D. Ungar. Optimizing Dynamically-Typed Object-Oriented Languages With Polymorphic Inline Caches. In ECOOP, pages 21--38, 1991. Google ScholarDigital Library
- S. H. Jensen, A. Møller, and P. Thiemann. Type Analysis for JavaScript. In SAS, pages 238--255, 2009. Google ScholarDigital Library
- F. Logozzo and H. Venter. RATA: Rapid Atomic Type Analysis by Abstract Interpretation. Application to JavaScript Optimization. In CC, pages 66--83, 2010. Google ScholarDigital Library
- N. Oxhøj, J. Palsberg, and M. I. Schwartzbach. Making Type Inference Practical. In ECOOP, 1992. Google ScholarDigital Library
- J. Palsberg and M. I. Schwartzbach. Object-Oriented Type Inference. In OOPSLA, 1991. Google ScholarDigital Library
- A. Rastogi, A. Chaudhuri, and B. Homer. The Ins and Outs of Gradual Type Inference. In POPL, pages 481--494, 2012. Google ScholarDigital Library
- G. Richards, S. Lebresne, B. Burg, and J. Vitek. An analysis of the dynamic behavior of JavaScript programs. In PLDI, pages 1--12, 2010. Google ScholarDigital Library
- G. Richards, C. Hammer, B. Burg, and J. Vitek. The Eval That Men Do -- A Large-Scale Study of the Use of Eval in JavaScript Applications. In ECOOP, pages 52--78, 2011. Google ScholarDigital Library
- J. G. Siek and W. Taha. Gradual Typing for Objects. In ECOOP, 2007. Google ScholarDigital Library
- M. Sridharan and S. J. Fink. The Complexity of Andersen's Analysis in Practice. In SAS, pages 205--221, 2009. Google ScholarDigital Library
- P. Thiemann. Towards a Type System for Analyzing JavaScript Programs. In ESOP, pages 408--422, 2005. Google ScholarDigital Library
- D. Ungar and R. B. Smith. Self: The Power of Simplicity. In OOPSLA, pages 227--242, 1987. Google ScholarDigital Library
- D. Ungar, R. B. Smith, C. Chambers, and U. Hölzle. Object, Message, and Performance: How they Coexist in Self. Computer, 25: 53--64, October 1992. ISSN 0018-9162. Google ScholarDigital Library
- A. K. Wright and R. Cartwright. A Practical Soft Type System for Scheme. ACM Trans. Program. Lang. Syst., 19 (1): 87--152, 1997. Google ScholarDigital Library
Index Terms
- Fast and precise hybrid type inference for JavaScript
Recommendations
Type inference for static compilation of JavaScript
OOPSLA 2016: Proceedings of the 2016 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and ApplicationsWe present a type system and inference algorithm for a rich subset of JavaScript equipped with objects, structural subtyping, prototype inheritance, and first-class methods. The type system supports abstract and recursive objects, and is expressive ...
Fast and precise hybrid type inference for JavaScript
PLDI '12JavaScript performance is often bound by its dynamically typed nature. Compilers do not have access to static type information, making generation of efficient, type-specialized machine code difficult. We seek to solve this problem by inferring types. In ...
Deep learning type inference
ESEC/FSE 2018: Proceedings of the 2018 26th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software EngineeringDynamically typed languages such as JavaScript and Python are increasingly popular, yet static typing has not been totally eclipsed: Python now supports type annotations and languages like TypeScript offer a middle-ground for JavaScript: a strict ...
Comments