skip to main content

Contextual dispatch for function specialization

Published:13 November 2020Publication History
Skip Abstract Section

Abstract

In order to generate efficient code, dynamic language compilers often need information, such as dynamic types, not readily available in the program source. Leveraging a mixture of static and dynamic information, these compilers speculate on the missing information. Within one compilation unit, they specialize the generated code to the previously observed behaviors, betting that past is prologue. When speculation fails, the execution must jump back to unoptimized code. In this paper, we propose an approach to further the specialization, by disentangling classes of behaviors into separate optimization units. With contextual dispatch, functions are versioned and each version is compiled under different assumptions. When a function is invoked, the implementation dispatches to a version optimized under assumptions matching the dynamic context of the call. As a proof-of-concept, we describe a compiler for the R language which uses this approach. Our implementation is, on average, 1.7× faster than the GNU R reference implementation. We evaluate contextual dispatch on a set of benchmarks and measure additional speedup, on top of traditional speculation with deoptimization techniques. In this setting contextual dispatch improves the performance of 18 out of 46 programs in our benchmark suite.

Skip Supplemental Material Section

Supplemental Material

Auxiliary Presentation Video

In order to generate efficient code, dynamic language compilers often need information, such as dynamic types, not readily available in the program source. Within one compilation unit, they specialize the generated code to the previously observed behaviors, betting that past is prologue. In this paper, we propose an approach to further the specialization, by disentangling classes of behaviors into separate optimization units. With contextual dispatch, functions are versioned and each version is compiled under different assumptions. When a function is invoked, the implementation dispatches to a version optimized under assumptions matching the dynamic context of the call. As a proof-of-concept, we describe a compiler for the R language which uses this approach. Our implementation is, on average, 1.7× faster than the GNU R reference implementation. We evaluate contextual dispatch on a set of benchmarks and measure additional speedup, on top of traditional speculation techniques.

References

  1. Arif Ali Ap and Erven Rohou. 2017. Dynamic Function Specialization. In International Conference on Embedded Computer Systems: Architectures, MOdeling and Simulation. https://doi.org/10.1109/SAMOS. 2017.8344624 Google ScholarGoogle ScholarCross RefCross Ref
  2. Edd Barrett, Carl Friedrich Bolz-Tereick, Rebecca Killick, Sarah Mount, and Laurence Tratt. 2017. Virtual Machine Warmup Blows Hot and Cold. In Conference on Object-Oriented Programming Systems, Languages and Applications (OOPSLA). https://doi.org/10.1145/3133876 Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Jef Bezanson, Jiahao Chen, Ben Chung, Stefan Karpinski, Viral B. Shah, Jan Vitek, and Lionel Zoubritzky. 2018. Julia: Dynamism and Performance Reconciled by Design. Proc. ACM Program. Lang. 2, OOPSLA ( 2018 ). https://doi.org/10. 1145/3276490 Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Robert Cartwright and Guy L Steele Jr. 1998. Compatible genericity with run-time types for the Java programming language. Conference on Object-Oriented Programming Systems, Languages and Applications (OOPSLA). https://doi.org/10.1145/ 286942.286958 Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Craig Chambers and David Ungar. 1989. Customization: Optimizing Compiler Technology for SELF, a Dynamicallytyped Object-oriented Programming Language. In Programming Language Design and Implementation (PLDI). https: //doi.org/10.1145/73141.74831 Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Maxime Chevalier-Boisvert and Marc Feeley. 2015. Simple and Efective Type Check Removal through Lazy Basic Block Versioning. In European Conference on Object-Oriented Programming (ECOOP). https://doi.org/10.4230/LIPIcs.ECOOP. 2015.101 Google ScholarGoogle ScholarCross RefCross Ref
  7. Keith D Cooper, Mary W Hall, and Ken Kennedy. 1993. A methodology for procedure cloning. Computer Languages 19 ( 1993 ). https://doi.org/10.1016/ 0096-0551 ( 93 ) 90005-L Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Igor Costa, Pericles Alves, Henrique Nazaré Santos, and Fernando Magno Quintao Pereira. 2013. Just-in-time value specialization. In Symposium on Code Generation and Optimization (CGO). https://doi.org/10.1109/CGO. 2013.6495006 Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Jefrey Dean, Craig Chambers, and David Grove. 1995. Selective Specialization for Object-Oriented Languages. In Programming Language Design and Implementation (PLDI). https://doi.org/10.1145/223428.207119 Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Iulian Dragos and Martin Odersky. 2009. Compiling generics through user-directed type specialization. In Workshop on the Implementation, Compilation, Optimization of Object-Oriented Languages and Programming Systems (ICOOOLPS). https://doi.org/10.1145/1565824.1565830 Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Olivier Flückiger, Guido Chari, Jan Jecmen, Ming-Ho Yee, Jakob Hain, and Jan Vitek. 2019. R melts brains: an IR for ifrst-class environments and lazy efectful arguments. In International Symposium on Dynamic Languages (DLS). https: //doi.org/10.1145/3359619.3359744 Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Olivier Flückiger, Guido Chari, Ming-Ho Yee, Jan Jecmen, Jakob Hain, and Jan Vitek. 2020. Artifact for “Contextual Dispatch for Function Specialization”. https://doi.org/10.5281/zenodo.3973073 Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Olivier Flückiger, Gabriel Scherer, Ming-Ho Yee, Aviral Goel, Amal Ahmed, and Jan Vitek. 2018. Correctness of speculative optimizations with dynamic deoptimization. Proc. ACM Program. Lang. 2, POPL ( 2018 ). https://doi.org/10.1145/3158137 Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Andreas Gal, Brendan Eich, Mike Shaver, David Anderson, David Mandelin, Mohammad R. Haghighat, Blake Kaplan, Graydon Hoare, Boris Zbarsky, Jason Orendorf, Jesse Ruderman, Edwin W. Smith, Rick Reitmaier, Michael Bebenita, Mason Chang, and Michael Franz. 2009. Trace-based Just-in-time Type Specialization for Dynamic Languages. In Programming Language Design and Implementation (PLDI). https://doi.org/10.1145/1542476.1542528 Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Isaac Gouy. 2020. Computer Language Benchmarks Game. https://benchmarksgame-team.pages. debian.net/ benchmarksgame/Google ScholarGoogle Scholar
  16. Brian Hackett and Shu-yu Guo. 2012. Fast and Precise Hybrid Type Inference for JavaScript. In Programming Language Design and Implementation (PLDI). https://doi.org/10.1145/2254064.2254094 Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Mary Wolcott Hall. 1991. Managing interprocedural optimization. Ph.D. Dissertation. https://hdl.handle.net/ 1911 /16446Google ScholarGoogle Scholar
  18. Urs Hölzle, Craig Chambers, and David Ungar. 1991. Optimizing dynamically-typed object-oriented languages with polymorphic inline caches. In European Conference on Object-Oriented Programming (ECOOP). https://doi.org/10.1007/ BFb0057013 Google ScholarGoogle ScholarCross RefCross Ref
  19. Urs Hölzle, Craig Chambers, and David Ungar. 1992. Debugging Optimized Code with Dynamic Deoptimization. In Programming Language Design and Implementation (PLDI). https://doi.org/10.1145/143095.143114 Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Antony L Hosking, J Eliot, and B Moss. 1990. Towards compile-time optimisations for persistence. In International Workshop on Persistent Object Systems.Google ScholarGoogle Scholar
  21. Toms Kalibera, Petr Maj, Floreal Morandat, and Jan Vitek. 2014. A Fast Abstract Syntax Tree Interpreter for R. In Conference on Virtual Execution Environments (VEE). https://doi.org/10.1145/2576195.2576205 Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Andrew Kennedy and Don Syme. 2001. Design and implementation of generics for the.NET Common language runtime. In Programming Language Design and Implementation (PLDI). https://doi.org/10.1145/378795.378797 Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Chris Lattner and Vikram Adve. 2004. LLVM: A Compilation Framework for Lifelong Program Analysis and Transformation. In Symposium on Code Generation and Optimization (CGO). https://doi.org/10.1109/CGO. 2004.1281665 Google ScholarGoogle ScholarCross RefCross Ref
  24. Friedrich Leisch. 2006. A Toolbox for K-Centroids Cluster Analysis. Computational Statistics and Data Analysis 51, 2 ( 2006 ).Google ScholarGoogle Scholar
  25. Lun Liu, Todd Millstein, and Madanlal Musuvathi. 2019. Accelerating Sequential Consistency for Java with Speculative Compilation. In Programming Language Design and Implementation (PLDI). https://doi.org/10.1145/3314221.3314611 Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Stefan Marr. 2018. ReBench: Execute and Document Benchmarks Reproducibly. https://doi.org/10.5281/zenodo. 1311762 Version 1.0. Google ScholarGoogle ScholarCross RefCross Ref
  27. Stefan Marr, Benoit Daloze, and Hanspeter Mössenböck. 2016. Cross-language Compiler Benchmarking: Are We Fast Yet?. In Symposium on Dynamic Languages (DLS). https://doi.org/10.1145/2989225.2989232 Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Floréal Morandat, Brandon Hill, Leo Osvald, and Jan Vitek. 2012. Evaluating the Design of the R Language: Objects and Functions for Data Analysis. In European Conference on Object-Oriented Programming (ECOOP). https://doi.org/10.1007/ 978-3-642-31057-7_6 Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Michael Paleczny, Christopher Vick, and Clif Click. 2001. The Java Hotspot Server Compiler. In Symposium on Java Virtual Machine Research and Technology (JVM).Google ScholarGoogle Scholar
  30. John Plevyak and Andrew A Chien. 1995. Type directed cloning for object-oriented programs. In International Workshop on Languages and Compilers for Parallel Computing. https://doi.org/10.1007/BFb0014224 Google ScholarGoogle ScholarCross RefCross Ref
  31. Gabriel Poesia and Fernando Magno Quint ao Pereira. 2020. Dynamic Dispatch of Context-Sensitive Optimizations. In Conference on Object-Oriented Programming Systems, Languages and Applications (OOPSLA). https://doi.org/10.1145/ 3428235 Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. R Core Team. 2019. R: A Language and Environment for Statistical Computing. https://www.R-project.orgGoogle ScholarGoogle Scholar
  33. Robert W. Scheifler. 1977. An Analysis of Inline Substitution for a Structured Programming Language. Commun. ACM 20, 9 ( 1977 ). https://doi.org/10.1145/359810.359830 Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Lukas Stadler, Adam Welc, Christian Humer, and Mick Jordan. 2016. Optimizing R Language Execution via Aggressive Speculation. In Symposium on Dynamic Languages (DLS). https://doi.org/10.1145/2989225.2989236 Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Justin Talbot, Zachary DeVito, and Pat Hanrahan. 2012. Riposte: A Trace-driven Compiler and Parallel VM for Vector Code in R. In Conference on Parallel Architectures and Compilation Techniques (PACT). https://doi.org/10.1145/2370816.2370825 Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Luke Tierney. 2019. A Byte Code Compiler for R. www.stat.uiowa.edu/~luke/R/compiler/compiler.pdfGoogle ScholarGoogle Scholar
  37. John Whaley. 1999. Dynamic optimization through the use of automatic runtime specialization. Ph.D. Dissertation. Stanford.Google ScholarGoogle Scholar

Index Terms

  1. Contextual dispatch for function specialization

    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

    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!