ABSTRACT
Lazy programs are beautiful, but they are slow because they build many thunks. Simple measurements show that most of these thunks are unnecessary: they are in fact always evaluated, or are always cheap. In this paper we describe Optimistic Evaluation --- an evaluation strategy that exploits this observation. Optimistic Evaluation complements compile-time analyses with run-time experiments: it evaluates a thunk speculatively, but has an abortion mechanism to back out if it makes a bad choice. A run-time adaption mechanism records expressions found to be unsuitable for speculative evaluation, and arranges for them to be evaluated more lazily in the future.We have implemented optimistic evaluation in the Glasgow Haskell Compiler. The results are encouraging: many programs speed up significantly (5-25%), some improve dramatically, and none go more than 15% slower.
- L. Augustsson and T. Johnsson. The chalmers lazy-ML compiler. The Computer Journal, 32(2):127--141, Apr. 1989. Google ScholarDigital Library
- T. Ball and J. R. Larus. Branch prediction for free. In ACM Conference on Programming Languages Design and Implementation (PLDI'93), pages 300--313. ACM, June 1993. Google ScholarDigital Library
- U. Boquist. Code Optimisation Techniques for Lazy Functional Languages. PhD thesis, Chalmers University of Technology, Sweden, April 1999.Google Scholar
- M. G. Burke, J.-D. Choi, S. Fink, D. Grove, M. Hind, V. Sarkar, M. J. Serrano, V. Sreedhar, H. Srinivasan, and J. Whaley. The Jalapeno dynamic optimizing compiler for Java. In Proceedings of the ACM Java Grande Conference, 1999. Google ScholarDigital Library
- F. W. Burton. Speculative computation, parallelism and functional programming. IEEE Trans Computers, C-34(12):1190--1193, Dec. 1985.Google ScholarCross Ref
- M. M. T. Chakravarty. Lazy thread and task creation in parallel graph reduction. In International Workshop on Implementing Functional Languages, Lecture Notes in Computer Science. Springer Verlag, 1998. Google ScholarDigital Library
- K.-F. Faxén. Cheap eagerness: Speculative evaluation in a lazy functional language. In ACM SIGPLAN International Conference on Functional Programming (ICFP'00), Montreal, Sept. 2000. ACM. Google ScholarDigital Library
- K.-F. Faxén. Dynamic cheap eagerness. In Proceedings of the 2001 Workshop on Implementing Functional Languages. Springer Verlag, 2001. Google ScholarDigital Library
- ACM Workshop on Feedback Directed and Dynamic Optimization (FDDO), 2001.Google Scholar
- M. Frigo, C. E. Leiserson, and K. H. Randall. The implementation of the Cilk-5 multithreaded language. In ACM Conference on Programming Languages Design and Implementation (PLDI'98), volume~33, pages 212--223, Atlanta, May 1998. ACM. Google ScholarDigital Library
- J. Gustavsson. A type-based sharing analysis for update avoidance and optimisation. In ACM SIGPLAN International Conference on Functional Programming (ICFP'98), volume 34(1) of ACM SIGPLAN Notices, Baltimore, 1998. ACM. Google ScholarDigital Library
- R. H. Halstead. Multilisp - a language for concurrent symbolic computation. ACM Transactions on Programming Languages and Systems, 7(4):501--538, Oct. 1985. Google ScholarDigital Library
- K. Hammond and J. O'Donnell, editors. Functional Programming, Glasgow 1993, Workshops in Computing. Springer Verlag, 1993.Google Scholar
- C. Haynes and D. Friedman. Engines build process abstractions. In Conference Record of the 1984 ACM Symposium on Lisp and Functional Programming, 1984. Google ScholarDigital Library
- U. Hölzle. Adaptive optimization for Self: reconciling high performance with exploratory programming. Ph.D. thesis, Computer Science Department, Stanford University, Mar. 1995. Google ScholarDigital Library
- J. Hughes. Why functional programming matters. The Computer Journal, 32(2):98--107, Apr. 1989. Google ScholarDigital Library
- M. Huntback. Speculative computation and priorities in concurrent logic languages. In ALPUK Conference, 1991. Google ScholarDigital Library
- H. M. J. Gosling. The Java Language Environment: a White Paper. Technical report, Sun Microsystems, 1996.Google Scholar
- J.-W. Maessen. Eager Haskell: Resource-bounded execution yields efficient iteration. In The Haskell Workshop, Pittsburgh, 2002. Google ScholarDigital Library
- J.-W. Maessen. Hybrid Eager and Lazy Evaluation for Efficient Compilation of Haskell. PhD thesis, Massachusetts Institute of Technology, June 2002. Google ScholarDigital Library
- S. Marlow, S. Peyton Jones, A. Moran, and J. Reppy. Asynchronous exceptions in Haskell. In ACM Conference on Programming Languages Design and Implementation (PLDI'01), pages 274--285, Snowbird, Utah, June 2001. ACM. Google ScholarDigital Library
- J. Mattson. An effective speculative evaluation technique for parallel supercombinator graph reduction. Ph.D. thesis, Department of Computer Science and Engineering, University of California, San Diego, Feb. 1993. Google ScholarDigital Library
- J. S. Mattson Jr and W. G. Griswold. Local Speculative Evaluation for Distributed Graph Reduction. In Hammond and O'Donnell {13}, pages 185--192. Google ScholarDigital Library
- L. Maurer. Isn't this tail recursive? Message posted to the Haskell mailing list: http://haskell.org/pipermail/haskell/2002-March/009126.html, Mar. 2002.Google Scholar
- E. Mohr, D. Kranz, and R. Halstead. Lazy task creation - a technique for increasing the granularity of parallel programs. IEEE Transactions on Parallel and Distributed Systems, 2(3), July 1991. Google ScholarDigital Library
- A. Moran, S. Lassen, and S. Peyton Jones. Imprecise exceptions, co-inductively. In Higher Order Operational Techniques in Semantics: Third International Workshop, number~26 in Electronic Notes in Theoretical Computer Science, pages 137--156. Elsevier, 1999.Google ScholarCross Ref
- R. Osbourne. Speculative computation in Multilisp. PhD thesis, MIT Lab for Computer Science, Dec. 1989.Google Scholar
- W. Partain. The nofib benchmark suite of Haskell programs. In J. Launchbury and P. Sansom, editors, Functional Programming, Glasgow 1992, Workshops in Computing, pages 195--202. Springer Verlag, 1992. Google ScholarDigital Library
- S. Peyton Jones, C. Hall, K. Hammond, W. Partain, and P. Wadler. The Glasgow Haskell Compiler: a technical overview. In Proceedings of Joint Framework for Information Technology Technical Conference, Keele, pages 249--257. DTI/SERC, Mar. 1993.Google Scholar
- S. Peyton Jones, S. Marlow, and A. Reid. The STG runtime system (revised). Technical report, Microsoft Research, February 1999. Part of GHC source package.Google Scholar
- S. Peyton Jones and W. Partain. Measuring the effectiveness of a simple strictness analyser. In Hammond and O'Donnell {13}, pages 201--220.Google Scholar
- S. Peyton Jones, A. Reid, C. Hoare, S. Marlow, and F. Henderson. A semantics for imprecise exceptions. In ACM Conference on Programming Languages Design and Implementation (PLDI'99), pages 25--36, Atlanta, May 1999. ACM. Google ScholarDigital Library
- S. Peyton Jones and P. Wadler. Imperative functional programming. In 20th ACM Symposium on Principles of Programming Languages (POPL'93), pages 71--84. ACM, Jan. 1993. Google ScholarDigital Library
- K. Schauser, D. Culler, and S. Goldstein. Separation constraint partitioning: a new algorithm for partitioning non-strict programs into sequential threads. In 22nd ACM Symposium on Principles of Programming Languages (POPL'95), pages 259--271. ACM, Jan. 1995. Google ScholarDigital Library
- P. Sestoft. Deriving a lazy abstract machine. Journal of Functional Programming, 7, 1997. Google ScholarDigital Library
- J. E. Smith. A study of branch prediction strategies. In International Symposium on Computer Architecture, 1981. Google ScholarDigital Library
- Sun Microsystems. The Java HotSpot Virtual machine, White Paper, 2001.Google Scholar
- K. Traub. Sequential implementation of lenient programming languages. Ph.D. thesis, MIT Lab for Computer Science, 1988.Google Scholar
- C. von Dorrien. Stingy evaluation. Licentiate thesis, Chalmers University of Technology, May 1989.Google Scholar
- P. Wadler and J. Hughes. Projections for strictness analysis. In G. Kahn, editor, Functional Programming Languages and Computer Architecture. Springer Verlag LNCS 274, Sept. 1987. Google ScholarDigital Library
Index Terms
- Optimistic evaluation: an adaptive evaluation strategy for non-strict programs
Recommendations
Optimistic evaluation: an adaptive evaluation strategy for non-strict programs
Lazy programs are beautiful, but they are slow because they build many thunks. Simple measurements show that most of these thunks are unnecessary: they are in fact always evaluated, or are always cheap. In this paper we describe Optimistic Evaluation ---...
Lazy Evaluation for Concurrent OLTP and Bulk Transactions
IDEAS '16: Proceedings of the 20th International Database Engineering & Applications SymposiumExisting concurrency control systems cannot execute transactions with overlapping updates concurrently. This is especially problematic for bulk updates, which usually overlap with all concurrent transactions. To solve this, we have developed a ...
Modular, higher-order cardinality analysis in theory and practice
POPL '14Since the mid '80s, compiler writers for functional languages (especially lazy ones) have been writing papers about identifying and exploiting thunks and lambdas that are used only once. However it has proved difficult to achieve both power and ...
Comments