skip to main content
research-article

Improving JavaScript performance by deconstructing the type system

Published:09 June 2014Publication History
Skip Abstract Section

Abstract

Increased focus on JavaScript performance has resulted in vast performance improvements for many benchmarks. However, for actual code used in websites, the attained improvements often lag far behind those for popular benchmarks.

This paper shows that the main reason behind this short-fall is how the compiler understands types. JavaScript has no concept of types, but the compiler assigns types to objects anyway for ease of code generation. We examine the way that the Chrome V8 compiler defines types, and identify two design decisions that are the main reasons for the lack of improvement: (1) the inherited prototype object is part of the current object's type definition, and (2) method bindings are also part of the type definition. These requirements make types very unpredictable, which hinders type specialization by the compiler. Hence, we modify V8 to remove these requirements, and use it to compile the JavaScript code assembled by JSBench from real websites. On average, we reduce the execution time of JSBench by 36%, and the dynamic instruction count by 49%.

References

  1. Chakra. http://blogs.msdn.com/b/ie/archive/2010/03/18/the-new-javascript-engine-in-internet-explorer-9.aspx.Google ScholarGoogle Scholar
  2. ECMAScript. http://www.ecmascript.org/.Google ScholarGoogle Scholar
  3. JavaScriptCore. http://trac.webkit.org/wiki/JavaScriptCore.Google ScholarGoogle Scholar
  4. Kraken Benchmarks. http://krakenbenchmark.mozilla.org/.Google ScholarGoogle Scholar
  5. Octane Benchmarks. https://developers.google.com/octane.Google ScholarGoogle Scholar
  6. SpiderMonkey Project. https://developer.mozilla.org/en-US/docs/SpiderMonkey.Google ScholarGoogle Scholar
  7. SunSpider Benchmarks. http://www.webkit.org/perf/sunspider/sunspider.html.Google ScholarGoogle Scholar
  8. V8 JavaScript Engine. https://developers.google.com/v8/.Google ScholarGoogle Scholar
  9. O. Anderson, E. Fortuna, L. Ceze, and S. Eggers. Checked load: Architectural support for JavaScript type-checking on mobile processors. In HPCA, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. J. Castanos, D. Edelsohn, K. Ishizaki, P. Nagpurkar, T. Nakatani, T. Ogasawara, and P. Wu. On the benefits and pitfalls of extending a statically typed language JIT compiler for dynamic scripting languages. In OOPSLA, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. C. Chambers, D. Ungar, and E. Lee. An efficient implementation of SELF, a dynamically-typed object-oriented language based on prototypes. In OOPSLA, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. D. Clifford. Breaking the JavaScript limit with V8. http://v8-io12.appspot.com.Google ScholarGoogle Scholar
  13. L. P. Deutsch and A. M. Schiffman. Efficient implementation of the Smalltalk-80 system. In POPL, 1984. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. B. Hackett and S.-Y. Guo. Fast and precise hybrid type inference for JavaScript. In PLDI, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. U. Hölzle, C. Chambers, and D. Ungar. Optimizing dynamically-typed object-oriented languages with polymorphic inline caches. In ECOOP, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. S. Li, B. Cheng, and X.-F. Li. TypeCastor: Demystify dynamic typing of JavaScript applications. In HiPEAC, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. C.-K. Luk, R. Cohn, R. Muth, H. Patil, A. Klauser, G. Lowney, S. Wallace, V. J. Reddi, and K. Hazelwood. Pin: Building customized program analysis tools with dynamic instrumentation. In PLDI, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. M. Mehrara, P.-C. Hsu, M. Samadi, and S. Mahlke. Dynamic parallelization of JavaScript applications using an ultra-lightweight speculation mechanism. In HPCA, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. M. Mehrara and S. Mahlke. Dynamically accelerating client-side web applications through decoupled execution. In CGO, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. P. Ratanaworabhan, B. Livshits, and B. G. Zorn. JSMeter: Comparing the behavior of JavaScript benchmarks with real Web applications. In the USENIX Conference on Web Application Development, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. G. Richards, A. Gal, B. Eich, and J. Vitek. Automated construction of JavaScript benchmarks. In OOPSLA, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. 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, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. G. Richards, S. Lebresne, B. Burg, and J. Vitek. An analysis of the dynamic behavior of JavaScript programs. In PLDI, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Improving JavaScript performance by deconstructing the type system

            Recommendations

            Reviews

            Michael G. Murphy

            JavaScript performance improvement has primarily focused on benchmark measurements. Actual website code tends to resist such improvement as a result of how JavaScript compilers process types. Although JavaScript does not support typing directly, there is an “on the fly” ad hoc typing that takes place during compilation. Based on in-depth analysis of the advanced Chrome V8 compiler, the primary roadblocks to improved performance are inherited prototype objects and method bindings. Changes in the compiler yield significant improvements with the benchmark JSBench applied to JavaScript code from actual websites. After a helpful introduction, the second section provides details on JavaScript and on the Chrome V8 compiler, a sophisticated just-in-time (JIT) compiler associated with the Google Chrome browser. Next, the authors present the motivation for this research, followed by a detailed section on type predictability issues that focuses on prototypes and method bindings. The fifth section proposes changes to Chrome V8 to address identified typing problems. Next, the impact of these changes is considered, together with how they might affect other proprietary browsers. The results are carefully evaluated in the seventh section. The last two sections provide a summary of related work and conclusions. Indications of future work are given at various points throughout the paper. The authors have prepared an insightful and well-written report on performance issues related to JavaScript. Developers and researchers will find much to mull over here. Online Computing Reviews Service

            Access critical reviews of Computing literature here

            Become a reviewer for Computing Reviews.

            Comments

            Login options

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

            Sign in

            Full Access

            PDF Format

            View or Download as a PDF file.

            PDF

            eReader

            View online with eReader.

            eReader
            About Cookies On This Site

            We use cookies to ensure that we give you the best experience on our website.

            Learn more

            Got it!