Abstract
Compilers for functional languages are judged, in part, on how well they handle \(\lambda \)-expressions. The evaluation of \(\lambda \)-expressions traditionally requires closure allocations which can be intensive and can interact poorly with a garbage collector. Work on closure representation and garbage collection has successfully improved this interaction. This work, however, does not address the actual allocation of closures in the first place. This is important, because the only closures that do not have to be garbage collected are the closures that are never allocated. This article explores a novel mechanism to reduce flat-closure allocations based on memoization. To test this new mechanism, a compiler has been developed that uses continuation-passing style as an intermediate representation–which makes closure allocation ubiquitous. Empirical results strongly suggest that flat-closure memoization is an important optimization that significantly reduces running time as well as memory and closure allocation.
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsNotes
- 1.
This study, however, was performed using the imperative C language.
- 2.
The use of bold type signals a reserved word.
References
Patterson, D.A., Hennessy, J.L.: Computer Organization and Design: The Hardware/Software Interface, 5th edn. Morgan Kaufmann Publishers Inc., San Francisco (2013)
Wilson, P.R.: Uniprocessor garbage collection techniques. In: Bekkers, Y., Cohen, J. (eds.) IWMM 1992. LNCS, vol. 637, pp. 1–42. Springer, Heidelberg (1992). https://doi.org/10.1007/BFb0017182
Serrano, M., Boehm, H.J.: Understanding memory allocation of scheme programs. In: Odersky, M., Wadler, P. (eds.) Proceedings of the Fifth International Conference on Functional Programming, pp. 245–256. ACM (2000)
Zorn, B.: The measured cost of conservative garbage collection. Softw. Pract. Exp. 23(7), 733–756 (1993)
Henderson, P.: Functional Programming: Application and Implementation. Prentice-Hall International, Englewood (1980)
Landin, P.J.: The mechanical evaluation of expressions. Comput. J. 6(4), 308–320 (1964)
Kent Dybvig, R.: The development of Chez Scheme. In: Proceedings of the Eleventh ACM SIGPLAN International Conference on Functional Programming, pp. 1–12, September 2006
Cardelli, L.: Compiling a functional language. In: Proceedings of the 1984 ACM Conference on LISP and Functional Programming, pp. 208–217 (1984)
Shao, Z., Appel, A.W.: Space-efficient closure representations. Technical report CS-TR-454-94, Department of Computer Science, Princeton University, Princeton (1994)
Shivers, O.: Control-flow analysis of higher-order languages of taming lambda. Ph.D. thesis, School of Computer Science, Carnegie Mellon University, Pittsburgh, May 1991
Steele Jr., G.L.: Rabbit: a compiler for scheme. Technical report, Massachusetts Institute of Technology, Cambridge (1978)
Adams, N., Kranz, D., Kelsey, R., Rees, J., Hudak, P., Philbin, J.: ORBIT: an optimizing compiler for scheme. In: Proceedings of the 1986 SIGPLAN Symposium on Compiler Construction, SIGPLAN 1986, pp. 219–233. ACM, New York (1986)
Kelsey, R., Hudak, P.: Realistic compilation by program transformation (detailed summary). In: Proceedings of the 16th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 1989, pp. 281–292. ACM, New York (1989)
Appel, A.W.: Compiling with Continuations. Cambridge University Press, New York (2007)
Flanagan, C., Sabry, A., Duba, B.F., Felleisen, M.: The essence of compiling with continuations. In: Proceedings of the ACM SIGPLAN 1993 Conference on Programming Language Design and Implementation, PLDI 1993, pp. 237–247. ACM, New York (1993)
Flanagan, C., Sabry, A., Duba, B.F., Felleisen, M.: The essence of compiling with continuations. SIGPLAN Not. 39(4), 502–514 (2004)
Kennedy, A.: Compiling with continuations, continued. In: Proceedings of the 12th ACM SIGPLAN International Conference on Functional Programming, ICFP 2007, pp. 177–190. ACM, New York (2007)
Fluet, M., Weeks, S.: Contification using dominators. In: Proceedings of the Sixth ACM SIGPLAN International Conference on Functional Programming, ICFP 2001, pp. 2–13. ACM, New York (2001)
Acar, U.A., Blelloch, G.E., Harper, R.: Selective memoization. In: Proceedings of the 30th Annual ACM Symposium on Principles of Programming Languages, pp. 14–25. ACM Press (2003)
Krishnamurthi, S.: Desugaring in practice: opportunities and challenges. In: Proceedings of the 2015 Workshop on Partial Evaluation and Program Manipulation, PEPM 2015, pp. 1–2. ACM, New York (2015)
Johnsson, T.: Lambda lifting: transforming programs to recursive equations. In: Jouannaud, J.-P. (ed.) FPCA 1985. LNCS, vol. 201, pp. 190–203. Springer, Heidelberg (1985). https://doi.org/10.1007/3-540-15975-4_37
Morazán, M.T., Schultz, U.P.: Optimal lambda lifting in quadratic time. In: Chitil, O., Horváth, Z., Zsók, V. (eds.) IFL 2007. LNCS, vol. 5083, pp. 37–56. Springer, Heidelberg (2008). https://doi.org/10.1007/978-3-540-85373-2_3
Venit, S., Bishop, W.: Elementary Linear Algebra, 2nd edn. Prindle, Weber & Schmidt, Boston (1985)
Lewis, H.R., Papadimitriou, C.H.: Elements of the Theory of Computation, 2nd edn. Prentice Hall PTR, Upper Saddle River (1997)
Köbler, J., Schöning, U., Torán, J.: The Graph Isomorphism Problem: Its Structural Complexity. Birkhauser Verlag, Basel (1993)
Morazán, M.T.: Bytecode and memoized closure performance. In: McCarthy, J. (ed.) TFP 2013. LNCS, vol. 8322, pp. 58–75. Springer, Heidelberg (2014). https://doi.org/10.1007/978-3-642-45340-3_4
Goldstein, D.L.: Richard P. Feynman, teacher. Phys. Today 42(2), 70–75 (1989)
Acknowledgements
The Physics Nobel Laureate, Richard Feynman, was once asked to explain why spin one-half particles obey Fermi Dirac statistics [27]. He rose to the challenge and responded that he will prepare a freshman lecture on it. A few days later he returned and stated that “I could not do it. I could not reduce it to the freshman level. That means we really don’t understand it.” The authors thank the Computer Science Department at Seton Hall University for their support that made the development of this work possible and for their support of our continuing efforts to make this material understandable to young and upcoming computer scientists.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2018 Springer International Publishing AG, part of Springer Nature
About this paper
Cite this paper
Morazán, M.T., Reams, L.M., Olson, N.R., Dzhatdoyev, S. (2018). Memoized Flat Closures for CPS. In: Wang, M., Owens, S. (eds) Trends in Functional Programming. TFP 2017. Lecture Notes in Computer Science(), vol 10788. Springer, Cham. https://doi.org/10.1007/978-3-319-89719-6_1
Download citation
DOI: https://doi.org/10.1007/978-3-319-89719-6_1
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-89718-9
Online ISBN: 978-3-319-89719-6
eBook Packages: Computer ScienceComputer Science (R0)