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.
Supplemental Material
Available for Download
Appendix
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Isaac Gouy. 2020. Computer Language Benchmarks Game. https://benchmarksgame-team.pages. debian.net/ benchmarksgame/Google Scholar
- 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 Scholar
Digital Library
- Mary Wolcott Hall. 1991. Managing interprocedural optimization. Ph.D. Dissertation. https://hdl.handle.net/ 1911 /16446Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- Antony L Hosking, J Eliot, and B Moss. 1990. Towards compile-time optimisations for persistence. In International Workshop on Persistent Object Systems.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- Friedrich Leisch. 2006. A Toolbox for K-Centroids Cluster Analysis. Computational Statistics and Data Analysis 51, 2 ( 2006 ).Google Scholar
- 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 Scholar
Digital Library
- Stefan Marr. 2018. ReBench: Execute and Document Benchmarks Reproducibly. https://doi.org/10.5281/zenodo. 1311762 Version 1.0. Google Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Michael Paleczny, Christopher Vick, and Clif Click. 2001. The Java Hotspot Server Compiler. In Symposium on Java Virtual Machine Research and Technology (JVM).Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- R Core Team. 2019. R: A Language and Environment for Statistical Computing. https://www.R-project.orgGoogle Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Luke Tierney. 2019. A Byte Code Compiler for R. www.stat.uiowa.edu/~luke/R/compiler/compiler.pdfGoogle Scholar
- John Whaley. 1999. Dynamic optimization through the use of automatic runtime specialization. Ph.D. Dissertation. Stanford.Google Scholar
Index Terms
Contextual dispatch for function specialization
Recommendations
An evaluation of speculative instruction execution on simultaneous multithreaded processors
Modern superscalar processors rely heavily on speculative execution for performance. For example, our measurements show that on a 6-issue superscalar, 93% of committed instructions for SPECINT95 are speculative. Without speculation, processor resources ...
Tuning Compiler Optimizations for Simultaneous Multithreading
Special issue on the 30th annual ACM/IEEE international symposium on microarchitecture, part IISimultaneous Multithreading (SMT) is a processor architectural technique that promises to significantly improve the utilization and performance of modern wide-issue superscalar processors. An SM T processor is capable of issuing multiple instructions ...
The Superthreaded Processor Architecture
The common single-threaded execution model limits processors to exploiting only the relatively small amount of instruction-level parallelism available in application programs. The superthreaded processor, on the other hand, is a concurrent multithreaded ...






Comments