skip to main content
research-article
Open Access
Artifacts Available
Artifacts Evaluated & Functional

Casts and costs: harmonizing safety and performance in gradual typing

Published:30 July 2018Publication History
Skip Abstract Section

Abstract

Gradual typing allows programmers to use both static and dynamic typing in a single program. However, a well-known problem with sound gradual typing is that the interactions between static and dynamic code can cause significant performance degradation. These performance pitfalls are hard to predict and resolve, and discourage users from using gradual typing features. For example, when migrating to a more statically typed program, often adding a type annotation will trigger a slowdown that can be resolved by adding more annotations elsewhere, but since it is not clear where the additional annotations must be added, the easier solution is to simply remove the annotation. To address these problems, we develop: (1) a static cost semantics that accurately predicts the overhead of static-dynamic interactions in a gradually typed program, (2) a technique for efficiently inferring such costs for all combinations of inferrable type assignments in a program, and (3) a method for translating the results of this analysis into specific recommendations and explanations that can help programmers understand, debug, and optimize the performance of gradually typed programs. We have implemented our approach in Herder, a tool for statically analyzing the performance of different typing configurations for Reticulated Python programs. An evaluation on 15 Python programs shows that Herder can use this analysis to accurately and efficiently recommend type assignments that optimize the performance of these programs without sacrificing the safety guarantees provided by static typing.

Skip Supplemental Material Section

Supplemental Material

a98-campora.webm

webm

83.2 MB

References

  1. Esteban Allende, Johan Fabry, Ronald Garcia, and Éric Tanter. 2014. Confined Gradual Typing. SIGPLAN Not. 49, 10 (Oct. 2014), 251–270. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Spenser Bauman, Carl Friedrich Bolz-Tereick, Jeremy Siek, and Sam Tobin-Hochstadt. 2017. Sound Gradual Typing: Only Mostly Dead. Proc. ACM Program. Lang. 1, OOPSLA, Article 54 (Oct. 2017), 24 pages. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. John Campora, Sheng Chen, Martin Erwig, and Eric Walkingshaw. 2018. Migrating Gradual Types. In Proceedings of the 45th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL ’18) . ACM, New York, NY, USA.Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Ezgi Çiçek, Gilles Barthe, Marco Gaboardi, Deepak Garg, and Jan Hoffmann. 2017. Relational Cost Analysis. SIGPLAN Not. 52, 1 (Jan. 2017), 316–329.Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Ezgi Çiçek, Zoe Paraskevopoulou, and Deepak Garg. 2016. A Type Theory for Incremental Computational Complexity with Control Flow Changes. SIGPLAN Not. 51, 9 (Sept. 2016), 132–145.Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Sheng Chen, Martin Erwig, and Eric Walkingshaw. 2012. An Error-tolerant Type System for Variational Lambda Calculus. In Proceedings of the 17th ACM SIGPLAN International Conference on Functional Programming (ICFP ’12). ACM, New York, NY, USA, 29–40. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Sheng Chen, Martin Erwig, and Eric Walkingshaw. 2014. Extending Type Inference to Variational Programs. ACM Trans. Program. Lang. Syst. 36, 1, Article 1 (March 2014), 54 pages. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Sheng Chen, Martin Erwig, and Eric Walkingshaw. 2016. A Calculus for Variational Programming. In European Conf. on Object-Oriented Programming (ECOOP) (LIPIcs) , Vol. 56. 6:1–6:26.Google ScholarGoogle Scholar
  9. Norman Danner, Daniel R. Licata, and Ramyaa Ramyaa. 2015. Denotational Cost Semantics for Functional Languages with Inductive Types. In Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming (ICFP 2015) . ACM, New York, NY, USA, 140–151. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Norman Danner, Jennifer Paykin, and James S. Royer. 2013. A Static Cost Analysis for a Higher-order Language. In Proceedings of the 7th Workshop on Programming Languages Meets Program Verification (PLPV ’13) . ACM, New York, NY, USA, 25–34. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Martin Erwig and Eric Walkingshaw. 2011. The Choice Calculus: A Representation for Software Variation. ACM Trans. Softw. Eng. Methodol. 21, 1, Article 6 (Dec. 2011), 27 pages. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Martin Erwig and Eric Walkingshaw. 2013. Variation Programming with the Choice Calculus. In Generative and Transformational Techniques in Software Engineering IV (GTTSE 2011), Revised and Extended Papers (LNCS) , Vol. 7680. 55–99.Google ScholarGoogle Scholar
  13. Ronald Garcia and Matteo Cimini. 2015. Principal Type Schemes for Gradual Programs. In Proceedings of the 42Nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’15) . ACM, New York, NY, USA, 303–315. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Ronald Garcia, Alison M. Clark, and Éric Tanter. 2016. Abstracting Gradual Typing. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’16) . ACM, New York, NY, USA, 429–442. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Jan Hoffmann, Ankush Das, and Shu-Chun Weng. 2017. Towards Automatic Resource Bound Analysis for OCaml. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL 2017) . ACM, New York, NY, USA, 359–373. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Jan Hoffmann and Martin Hofmann. 2010. Amortized Resource Analysis with Polynomial Potential - A Static Inference of Polynomial Bounds for Functional Programs. In In Proceedings of the 19th European Symposium on Programming (ESOP’10) (Lecture Notes in Computer Science) , Vol. 6012. Springer, 287–306. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Jan Hoffmann and Zhong Shao. 2015. Automatic Static Cost Analysis for Parallel Programs. In Proceedings of the 24th European Symposium on Programming on Programming Languages and Systems - Volume 9032 . Springer-Verlag New York, Inc., New York, NY, USA, 132–157. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Fabian Muehlboeck and Ross Tate. 2017. Sound Gradual Typing is Nominally Alive and Well. In OOPSLA. ACM, New York, NY, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Aseem Rastogi, Avik Chaudhuri, and Basil Hosmer. 2012. The Ins and Outs of Gradual Type Inference. SIGPLAN Not. 47, 1 (Jan. 2012), 481–494. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Gregor Richards, Ellen Arteca, and Alexi Turcotte. 2017. The VM Already Knew That: Leveraging Compile-time Knowledge to Optimize Gradual Typing. Proc. ACM Program. Lang. 1, OOPSLA, Article 55 (Oct. 2017), 27 pages. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Jeremy Siek, Ronald Garcia, and Walid Taha. 2009. Exploring the Design Space of Higher-Order Casts. In Programming Languages and Systems , Giuseppe Castagna (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg, 17–31. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Jeremy G. Siek and Walid Taha. 2006. Gradual Typing for Functional Languages. In IN SCHEME AND FUNCTIONAL PROGRAMMING WORKSHOP . 81–92.Google ScholarGoogle Scholar
  23. Jeremy G. Siek and Manish Vachharajani. 2008. Gradual Typing with Unification-based Inference. In Proceedings of the 2008 Symposium on Dynamic Languages (DLS ’08) . ACM, New York, NY, USA, Article 7, 12 pages. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. 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 (POPL ’16) . ACM, New York, NY, USA, 456–468. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. 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 (OOPSLA ’06) . ACM, New York, NY, USA, 964–974. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Sam Tobin-Hochstadt, Matthias Felleisen, Robert Findler, Matthew Flatt, Ben Greenman, Andrew M. Kent, Vincent St-Amour, T. Stephen Strickland, and Asumu Takikawa. 2017. Migratory Typing: Ten Years Later. In 2nd Summit on Advances in Programming Languages (SNAPL 2017) (Leibniz International Proceedings in Informatics (LIPIcs)) , Benjamin S. Lerner, Rastislav Bodík, and Shriram Krishnamurthi (Eds.), Vol. 71. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, Dagstuhl, Germany, 17:1–17:17.Google ScholarGoogle Scholar
  27. Guido van Rossum, Jukka Lehtosalo, and Łukasz Langa. 2014. PEP 484 – Type Hints. https://www.python.org/dev/peps/ pep-0484/#rationale-and-goalsGoogle ScholarGoogle Scholar
  28. Michael M. Vitousek, Andrew M. Kent, Jeremy G. Siek, and Jim Baker. 2014. Design and Evaluation of Gradual Typing for Python. (2014), 45–56. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Casts and costs: harmonizing safety and performance in gradual typing

    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