skip to main content
10.1145/2254064.2254094acmconferencesArticle/Chapter ViewAbstractPublication PagespldiConference Proceedingsconference-collections
research-article

Fast and precise hybrid type inference for JavaScript

Published:11 June 2012Publication History

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.

References

  1. O. Agesen. Constraint-Based Type Inference and Parametric Polymorphism, 1994.Google ScholarGoogle ScholarCross RefCross Ref
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  4. A. Aiken and B. R. Murphy. Static Type Inference in a Dynamically Typed Language. In POPL, pages 279--290, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. A. Aiken and E. L. Wimmers. Type Inclusion Constraints and Type Inference. In FPCA, pages 31--41, 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. L. O. Andersen. Program Analysis and Specialization for the C Programming Language. PhD thesis, DIKU, University of Copenhagen, 1994.Google ScholarGoogle Scholar
  7. C. Anderson, S. Drossopoulou, and P. Giannini. Towards Type Inference for JavaScript. In ECOOP, pages 428--452, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. R. Cartwright and M. Fagan. Soft Typing. In PLDI, pages 278--292, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. C. Chambers and D. Ungar. Customization: Optimizing Compiler Technology for SELF, A Dynamically-Typed Object-Oriented Programming Language. In PLDI, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. N. Glew and J. Palsberg. Type-Safe Method Inlining. In ECOOP, pages 525--544, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. S. H. Jensen, A. Møller, and P. Thiemann. Type Analysis for JavaScript. In SAS, pages 238--255, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. F. Logozzo and H. Venter. RATA: Rapid Atomic Type Analysis by Abstract Interpretation. Application to JavaScript Optimization. In CC, pages 66--83, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. N. Oxhøj, J. Palsberg, and M. I. Schwartzbach. Making Type Inference Practical. In ECOOP, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. J. Palsberg and M. I. Schwartzbach. Object-Oriented Type Inference. In OOPSLA, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. A. Rastogi, A. Chaudhuri, and B. Homer. The Ins and Outs of Gradual Type Inference. In POPL, pages 481--494, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  21. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  22. J. G. Siek and W. Taha. Gradual Typing for Objects. In ECOOP, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. M. Sridharan and S. J. Fink. The Complexity of Andersen's Analysis in Practice. In SAS, pages 205--221, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. P. Thiemann. Towards a Type System for Analyzing JavaScript Programs. In ESOP, pages 408--422, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. D. Ungar and R. B. Smith. Self: The Power of Simplicity. In OOPSLA, pages 227--242, 1987. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  27. A. K. Wright and R. Cartwright. A Practical Soft Type System for Scheme. ACM Trans. Program. Lang. Syst., 19 (1): 87--152, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Fast and precise hybrid type inference for JavaScript

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in
    • Published in

      cover image ACM Conferences
      PLDI '12: Proceedings of the 33rd ACM SIGPLAN Conference on Programming Language Design and Implementation
      June 2012
      572 pages
      ISBN:9781450312059
      DOI:10.1145/2254064
      • cover image ACM SIGPLAN Notices
        ACM SIGPLAN Notices  Volume 47, Issue 6
        PLDI '12
        June 2012
        534 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/2345156
        Issue’s Table of Contents

      Copyright © 2012 ACM

      Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 11 June 2012

      Permissions

      Request permissions about this article.

      Request Permissions

      Check for updates

      Qualifiers

      • research-article

      Acceptance Rates

      PLDI '12 Paper Acceptance Rate48of255submissions,19%Overall Acceptance Rate406of2,067submissions,20%

      Upcoming Conference

      PLDI '24

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader