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 --- 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.

[1]  William G. Griswold,et al.  Speculative Evaluation for Parallel Graph Reduction , 1994, IFIP PACT.

[2]  Robert H. Halstead,et al.  MULTILISP: a language for concurrent symbolic computation , 1985, TOPL.

[3]  Jan-Willem Maessen,et al.  Hybrid eager and lazy evaluation for efficient compilation of Haskell , 2002 .

[4]  Jr. James Stewart Mattson An effective speculative evaluation technique for parallel supercomb , 1993 .

[5]  Simon Peyton Jones,et al.  Measuring the effectiveness of a simple strictness analyser , 1993, Functional Programming.

[6]  Matthew M. Huntbach Search in concurrent logic languages , 1995, SAC '95.

[7]  Matthew M. Huntbach Speculative Computation and Priorities in Concurrent Logic Languages , 1991, ALPUK.

[8]  Philip Wadler,et al.  Why no one uses functional languages , 1998, SIGP.

[9]  Will Partain,et al.  The nofib Benchmark Suite of Haskell Programs , 1992, Functional Programming.

[10]  F. Warren Burton,et al.  Speculative computation, parallelism, and functional programming , 1985, IEEE Transactions on Computers.

[11]  Karl-Filip Faxén Dynamic Cheap Eagerness , 2001, IFL.

[12]  Randy B. Osborne Speculative Computation in Multilisp , 1989, Workshop on Parallel Lisp.

[13]  Seth Copen Goldstein,et al.  Separation constraint partitioning: a new algorithm for partitioning non-strict programs into sequential threads , 1995, POPL '95.

[14]  John Hughes,et al.  Why Functional Programming Matters , 1989, Comput. J..

[15]  Simon L. Peyton Jones,et al.  Imprecise Exceptions, Co-Inductively , 1999, Electron. Notes Theor. Comput. Sci..

[16]  Manuel M. T. Chakravarty,et al.  Lazy Thread and Task Creation in Parallel Graph-Reduction , 1997, Implementation of Functional Languages.

[17]  James R. Larus,et al.  Branch prediction for free , 1993, PLDI '93.

[18]  Robert H. Halstead,et al.  Lazy task creation: a technique for increasing the granularity of parallel programs , 1990, LISP and Functional Programming.

[19]  James E. Smith,et al.  A study of branch prediction strategies , 1981, ISCA '98.

[20]  Philip Wadler,et al.  Linear Types can Change the World! , 1990, Programming Concepts and Methods.

[21]  Urs Hölzle,et al.  Adaptive optimization for self: reconciling high performance with exploratory programming , 1994 .

[22]  Simon L. Peyton Jones,et al.  Once upon a polymorphic type , 1999, POPL '99.

[23]  William G. Griswold,et al.  Local Speculative Evaluation for Distributed Graph Reduction , 1993, Functional Programming.

[24]  Karl-Filip Faxén Cheap eagerness: speculative evaluation in a lazy functional language , 2000, ICFP '00.

[25]  Philip Wadler Monads for Functional Programming , 1995, Advanced Functional Programming.

[26]  Thomas Johnsson,et al.  The Chalmers Lazy-ML Compiler , 1989, Computer/law journal.

[27]  Urban Boquist,et al.  Code Optimisation Techniques for Lazy Functional Languages , 1999 .

[28]  Jan-Willem Maessen,et al.  Eager Haskell: resource-bounded execution yields efficient iteration , 2002, Haskell '02.

[29]  Matteo Frigo,et al.  The implementation of the Cilk-5 multithreaded language , 1998, PLDI.

[30]  Philip Wadler,et al.  Projections for strictness analysis , 1987, FPCA.

[31]  Jörgen Gustavsson A type based sharing analysis for update avoidance and optimisation , 1998, ICFP '98.

[32]  Simon L. Peyton Jones,et al.  Asynchronous exceptions in Haskell , 2001, PLDI '01.

[33]  Simon L. Peyton Jones,et al.  A semantics for imprecise exceptions , 1999, PLDI '99.

[34]  K. R. Traub,et al.  Sequential implementation of lenient programming languages , 1988 .

[35]  Philip Wadler,et al.  Strictness analysis aids time analysis , 1988, POPL '88.

[36]  Uday S. Reddy,et al.  Imperative functional programming , 1996, CSUR.

[37]  Peter Sestoft,et al.  Deriving a lazy abstract machine , 1997, Journal of Functional Programming.

[38]  Paul R. Wilson,et al.  Uniprocessor Garbage Collection Techniques , 1992, IWMM.

[39]  Daniel P. Friedman,et al.  Engines build process abstractions , 1984, LFP '84.

[40]  Philip Wadler,et al.  The Glasgow Haskell Compiler: a technical overview , 1993 .

[41]  Philip Wadler,et al.  Deforestation: Transforming Programs to Eliminate Trees , 1990, Theor. Comput. Sci..

[42]  James A. Gosling,et al.  The java language environment: a white paper , 1995 .

[43]  Philip Wadler,et al.  How to declare an imperative , 1997, CSUR.