Abstract
While gradual typing has proven itself attractive to programmers, many systems have avoided sound gradual typing due to the run time overhead of enforcement. In the context of sound gradual typing, both anecdotal and systematic evidence has suggested that run time costs are quite high, and often unacceptable, casting doubt on the viability of soundness as an approach.
We show that these overheads are not fundamental, and that with appropriate improvements, just-in-time compilers can greatly reduce the overhead of sound gradual typing. Our study takes benchmarks published in a recent paper on gradual typing performance in Typed Racket (Takikawa et al., POPL 2016) and evaluates them using a experimental tracing JIT compiler for Racket, called Pycket. On typical benchmarks, Pycket is able to eliminate more than 90% of the gradual typing overhead. While our current results are not the final word in optimizing gradual typing, we show that the situation is not dire, and where more work is needed.
Pycket's performance comes from several sources, which we detail and measure individually. First, we apply a sophisticated tracing JIT compiler and optimizer, automatically generated in Pycket using the RPython framework originally created for PyPy. Second, we focus our optimization efforts on the challenges posed by run time checks, implemented in Racket by chaperones and impersonators. We introduce representation improvements, including a novel use of hidden classes to optimize these data structures.
Supplemental Material
Available for Download
- Norman Adams, David Kranz, Richard Kelsey, Jonathan Rees, Paul Hudak, and James Philbin. 1986. ORBIT: An Optimizing Compiler for Scheme. In Proceedings of the 1986 SIGPLAN Symposium on Compiler Construction (SIGPLAN ’86). ACM, 219–233.Google Scholar
Digital Library
- Esteban Allende, Oscar Callau, Johan Fabry, Éric Tanter, and Marcus Denker. 2014. Gradual typing for Smalltalk. Science of Computer Programming 96 (2014), 52–69. Google Scholar
Digital Library
- Esteban Allende and Johan Fabry. 2011. Application optimization when using gradual typing. In Proceedings of the 6th Workshop on Implementation, Compilation, Optimization of Object-Oriented Languages, Programs and Systems. ACM, 3. Google Scholar
Digital Library
- Esteban Allende, Johan Fabry, and Éric Tanter. 2013. Cast Insertion Strategies for Gradually-typed Objects. In Proceedings of the 9th Symposium on Dynamic Languages (DLS ’13). ACM, 27–36. Google Scholar
Digital Library
- Håkan Ardö, Carl Friedrich Bolz, and Maciej Fijałkowski. 2012. Loop-aware Optimizations in PyPy’s Tracing JIT. In Proceedings of the 8th Symposium on Dynamic Languages (DLS ’12). ACM, New York, NY, USA, 63–72. Google Scholar
Digital Library
- Edd Barrett, Carl Friedrich Bolz, Rebecca Killick, Vincent Knight, Sarah Mount, and Laurence Tratt. 2016. Virtual machine warmup blows hot and cold. arXiv preprint arXiv:1602.00602 (2016).Google Scholar
- Spenser Bauman, Carl Friedrich Bolz, Robert Hirschfeld, Vasily Kirilichev, Tobias Pape, Jeremy G Siek, and Sam TobinHochstadt. 2015. Pycket: A tracing JIT for a functional language. In Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming. ACM, 22–34.Google Scholar
Digital Library
- Gavin Bierman, Martín Abadi, and Mads Torgersen. 2014. Understanding TypeScript. In ECOOP 2014–Object-Oriented Programming. Springer, 257–281. Google Scholar
Digital Library
- Gavin Bierman, Erik Meijer, and Mads Torgersen. 2010. Adding Dynamic Types to C#. In European Conference on ObjectOriented Programming. Springer, 76–100.Google Scholar
- Carl Friedrich Bolz, Antonio Cuni, Maciej Fijakowski, Michael Leuschel, Samuele Pedroni, and Armin Rigo. 2011. Runtime Feedback in a Meta-Tracing JIT for Efficient Dynamic Languages. In Proc. ICOOOLPS. 9:19:8. Google Scholar
Digital Library
- Carl Friedrich Bolz, Antonio Cuni, Maciej Fijakowski, and Armin Rigo. 2009. Tracing the Meta-Level: PyPy’s Tracing JIT Compiler. In Proc. ICOOOLPS. 18–25. Google Scholar
Digital Library
- Carl Friedrich Bolz, Tobias Pape, Jeremy G. Siek, and Sam Tobin-Hochstadt. 2014. Meta-tracing makes a fast Racket. In Workshop on Dynamic Languages and Applications.Google Scholar
- Ambrose Bonnaire-Sergeant, Rowan Davies, and Sam Tobin-Hochstadt. 2016. Practical Optional Types for Clojure. European Symposium on Programming 25 (2016).Google Scholar
- C. Chambers, D. Ungar, and E. Lee. 1989. An Efficient Implementation of SELF a Dynamically-typed Object-oriented Language Based on Prototypes. In Conference Proceedings on Object-oriented Programming Systems, Languages and Applications (OOPSLA ’89). ACM, 49–70. Google Scholar
Digital Library
- Olivier Danvy. 1991. Three Steps for the CPS Transformation. Technical Report CIS-92-02. Kansas State University.Google Scholar
- Facebook. 2017a. Flow Documentation. (2017). http://flowtype.org/docs/about-flow.htmlGoogle Scholar
- Facebook. 2017b. Hack Documentation. (2017). https://docs.hhvm.com/hack/Google Scholar
- Matthias Felleisen and Daniel P. Friedman. 1987. Control operators, the SECD-machine and the lambda-calculus. In Working Conf. on Formal Description of Programming Concepts - III. Elsevier, 193–217.Google Scholar
- R. B. Findler and M. Felleisen. 2002. Contracts for higher-order functions. In International Conference on Functional Programming (ICFP). 48–59. Google Scholar
Digital Library
- Cormac Flanagan, Amr Sabry, Bruce F. Duba, and Matthias Felleisen. 1993. The essence of compiling with continuations. In Proc. PLDI. 502–514. Google Scholar
Digital Library
- Google. 2015. Dart Programming Language Specification. Technical Report. EMCA International. https://www.dartlang. org/docs/spec/Google Scholar
- Brian Hackett and Shu-yu Guo. 2012. Fast and Precise Hybrid Type Inference for JavaScript. In Proceedings of the 33rd ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI ’12). ACM, New York, NY, USA, 239–250. Google Scholar
Digital Library
- Jukka Lehtosalo and David J Greaves. 2011. Language with a Pluggable Type System and Optional Runtime Monitoring of Type Errors. In Proceedings of International Workshop on Scripts to Programs (STOP).Google Scholar
- André Murbach Maidl, Fabio Mascarenhas, and Roberto Ierusalimschy. 2014. Typed lua: An optional type system for lua. In Proceedings of the Workshop on Dynamic Languages and Applications. ACM, 1–10. Google Scholar
Digital Library
- Kevin Millikin and Florian Schneider. 2010. A New Crankshaft for V8. The Chromium Blog 7 (2010).Google Scholar
- Aseem Rastogi, Nikhil Swamy, Cédric Fournet, Gavin Bierman, and Panagiotis Vekris. 2015. Safe & Efficient Gradual Typing for TypeScript. In Proceedings of the 42Nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’15). ACM, 167–180.Google Scholar
Digital Library
- Rob Reiner. 1987. The Princess Bride. (1987).Google Scholar
- Gregor Richards, Francesco Zappa Nardelli, and Jan Vitek. 2015. Concrete types for TypeScript. In LIPIcs-Leibniz International Proceedings in Informatics, Vol. 37. Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik.Google Scholar
- Armin Rigo and Samuele Pedroni. 2006. PyPy’s Approach to Virtual Machine Construction. In Proc. DLS. 944–953. Google Scholar
Digital Library
- Thomas Schilling. 2013. Trace-based Just-in-time Compilation for Lazy Functional Programming Languages. Ph.D. Dissertation. University of Kent.Google Scholar
- Jeremy G Siek and Walid Taha. 2006. Gradual typing for functional languages. In Scheme and Functional Programming Workshop, Vol. 6. 81–92.Google Scholar
- Jeremy G Siek, Michael M Vitousek, Matteo Cimini, Sam Tobin-Hochstadt, and Ronald Garcia. 2015. Monotonic references for efficient gradual typing. In Programming Languages and Systems. Springer, 432–456.Google Scholar
- T. Stephen Strickland, Sam Tobin-Hochstadt, Robert Bruce Findler, and Matthew Flatt. 2012. Chaperones and impersonators: run-time support for reasonable interposition. In Object Oriented Programming Systems Languages and Applications (OOPSLA ’12). Google Scholar
Digital Library
- Asumu Takikawa, Daniel Feltey, Earl Dean, Matthew Flatt, Robert Bruce Findler, Sam Tobin-Hochstadt, and Matthias Felleisen. 2015. Towards practical gradual typing. In LIPIcs-Leibniz International Proceedings in Informatics, Vol. 37. Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik.Google Scholar
- Asumu Takikawa, Daniel Feltey, Ben Greenman, Max S New, Jan Vitek, and Matthias Felleisen. 2016. Is sound gradual typing dead?. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM, 456–468. Google Scholar
Digital Library
- Sam Tobin-Hochstadt and Matthias Felleisen. 2006. Interlanguage migration: from scripts to programs. In Companion to the 21st ACM SIGPLAN symposium on Object-oriented programming systems, languages, and applications. ACM, 964–974. Google Scholar
Digital Library
- Sam Tobin-Hochstadt and Matthias Felleisen. 2008. The Design and Implementation of Typed Scheme. In Proceedings of the 35th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’08). ACM, New York, NY, USA, 395–406. Google Scholar
Digital Library
- Sam Tobin-Hochstadt, Vincent St-Amour, Ryan Culpepper, Matthew Flatt, and Matthias Felleisen. 2011. Languages as libraries. In Proceedings of the 32nd ACM SIGPLAN conference on Programming language design and implementation (PLDI ’11). ACM, 132–141. Google Scholar
Digital Library
- Michael M. Vitousek, Andrew M. Kent, Jeremy G. Siek, and Jim Baker. 2014. Design and Evaluation of Gradual Typing for Python. In Proceedings of the 10th ACM Symposium on Dynamic Languages (DLS ’14). ACM, 45–56. Google Scholar
Digital Library
- Michael M. Vitousek, Cameron Swords, and Jeremy G. Siek. 2017. Big Types in Little Runtime: Open-world Soundness and Collaborative Blame for Gradual Type Systems. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL 2017). ACM, New York, NY, USA, 762–774. Google Scholar
Digital Library
- Tobias Wrigstad, Francesco Zappa Nardelli, Sylvain Lebresne, Johan Östlund, and Jan Vitek. 2010. Integrating Typed and Untyped Code in a Scripting Language. In Proceedings of the 37th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’10). ACM, 377–388. Google Scholar
Digital Library
Index Terms
Sound gradual typing: only mostly dead
Recommendations
Sound gradual typing is nominally alive and well
Recent research has identified significant performance hurdles that sound gradual typing needs to overcome. These performance hurdles stem from the fact that the run-time checks gradual type systems insert into code can cause significant overhead. We ...
Gradual typing: a new perspective
We define a new, more semantic interpretation of gradual types and use it to ``gradualize'' two forms of polymorphism: subtyping polymorphism and implicit parametric polymorphism. In particular, we use the new interpretation to define three gradual type ...
Is sound gradual typing dead?
POPL '16: Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming LanguagesProgrammers have come to embrace dynamically-typed languages for prototyping and delivering large and complex systems. When it comes to maintaining and evolving these systems, the lack of explicit static typing becomes a bottleneck. In response, ...






Comments