Adaptive evaluation of non-strict programs

Most popular programming languages are strict. In a strict language, the binding of a variable to an expression coincides with the evaluation of the expression. Non-strict languages attempt to make life easier for programmers by decoupling expression binding and expression evaluation. In a non-strict language, a variable can be bound to an unevaluated expression, and such expressions can be passed around just like values in a strict language. This separation allows the programmer to declare a variable at the point that makes most logical sense, rather than at the point at which its value is known to be needed. Non-strict languages are usually evaluated using a technique called Lazy Evaluation. Lazy Evaluation will only evaluate an expression when its value is known to be needed. While Lazy Evaluation minimises the total number of expressions evaluated, it imposes a considerable bookkeeping overhead, and has unpredictable space behaviour. In this thesis, we present a new evaluation strategy which we call Optimistic Evaluation. Optimistic Evaluation blends lazy and eager evaluation under the guidance of an online profiler. The online profiler observes the running program and decides which expressions should be evaluated lazily, and which should be evaluated eagerly. We show that the worst case performance of Optimistic Evaluation relative to Lazy Evaluation can be bounded with an upper bound chosen by the user. Increasing this upper bound allows the profiler to take greater risks and potentially achieve better average performance. This thesis describes both the theory and practice of Optimistic Evaluation. We start by giving an overview of Optimistic Evaluation. We go on to present formal model, which we use to justify our design. We then detail how we have implemented Optimistic Evaluation as part of an industrial-strength compiler. Finally, we provide experimental results to back up our claims.

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

[2]  Alan Mycroft,et al.  The Theory and Practice of Transforming Call-by-need into Call-by-value , 1980, Symposium on Programming.

[3]  Lance M. Berc,et al.  Continuous profiling: where have all the cycles gone? , 1997, TOCS.

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

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

[6]  Stephen A. Jarvis,et al.  Profiling Large-Scale Lazy Functional Programs , 1996, J. Funct. Program..

[7]  Marko C. J. D. van Eekelen,et al.  CLEAN: A language for functional graph writing , 1987, FPCA.

[8]  李幼升,et al.  Ph , 1989 .

[9]  Gurindar S. Sohi,et al.  A programmable co-processor for profiling , 2001, Proceedings HPCA Seventh International Symposium on High-Performance Computer Architecture.

[10]  Manfred Broy,et al.  Engineering Theories of Software Construction , 2001 .

[11]  Carl Hewitt,et al.  The incremental garbage collection of processes , 1977 .

[12]  Simon Peyton Jones,et al.  The STG runtime system (revised) , 2008 .

[13]  Alan Mycroft,et al.  Abstract interpretation and optimising transformations for applicative programs , 1982 .

[14]  Peyton Jones,et al.  Haskell 98 language and libraries : the revised report , 2003 .

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

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

[17]  Joseph Robert Horgan,et al.  Dynamic program slicing , 1990, PLDI '90.

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

[19]  Samson Abramsky,et al.  Domain theory , 1995, LICS 1995.

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

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

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

[23]  Jan Sparud,et al.  Fixing some space leaks without a garbage collector , 1993, FPCA '93.

[24]  Roy Dz-Ching Ju,et al.  A compiler framework for speculative analysis and optimizations , 2003, PLDI '03.

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

[26]  Hans-Wolfgang Loidl,et al.  Cost Analysis Using Automatic Size and Time Inference , 2002, IFL.

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

[28]  Niklas Röjemo,et al.  Lag, drag, void and use—heap profiling and space-efficient compilation revisited , 1996, ICFP '96.

[29]  Henrik Nilsson,et al.  The Evaluation Dependence Tree as a Basis for Lazy Functional Debugging , 1997, Automated Software Engineering.

[30]  Philip Wadler,et al.  Fixing some space leaks with a garbage collector , 1987, Softw. Pract. Exp..

[31]  Matthew Arnold,et al.  Online profiling and feedback-directed optimization of java , 2002 .

[32]  Patrick M. Sansom,et al.  Execution profiling for non-strict functional languages , 1994 .

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

[34]  Jonathan Rees,et al.  Revised3 report on the algorithmic language scheme , 1986, SIGP.

[35]  Henrik Nilsson,et al.  Algorithmic debugging for lazy functional languages , 1992, Journal of Functional Programming.

[36]  Guy E. Blelloch,et al.  A provably time-efficient parallel implementation of full speculation , 1999, TOPL.

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

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

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

[40]  John Launchbury,et al.  A natural semantics for lazy evaluation , 1993, POPL '93.

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

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

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

[44]  Paul Roe,et al.  Calculating lenient programs' performance , 1990, Functional Programming.

[45]  Claus Reinke GHood -- Graphical Visualisation and Animation of Haskell Object Observations , 2001 .

[46]  Susan L. Graham,et al.  An execution profiler for modular programs , 1983, Softw. Pract. Exp..

[47]  Simon Peyton Jones,et al.  The New GHC/Hugs Runtime System , 1998 .

[48]  Simon L. Peyton Jones,et al.  Imperative functional programming , 1993, POPL '93.

[49]  John Lamping,et al.  An algorithm for optimal lambda calculus reduction , 1989, POPL '90.

[50]  Simon L. Peyton Jones,et al.  Implementing lazy functional languages on stock hardware: the Spineless Tagless G-machine , 1992, Journal of Functional Programming.

[51]  André L. M. Santos,et al.  Compilation by transformation in non-strict functional languages , 1995 .

[52]  Andrea Asperti,et al.  Safe Operators: Brackets Closed Forever Optimizing Optimal lambda-Calculus Implementations - Optimizing Optimal lambda-Calculus Implementations , 1997, Appl. Algebra Eng. Commun. Comput..

[53]  Venkata Krishnan Speculative Multithreading Architectures , 1998 .

[54]  Andrew W. Appel,et al.  Debugging standard ML without reverse engineering , 1990, LISP and Functional Programming.

[55]  Simon L. Peyton Jones,et al.  A short cut to deforestation , 1993, FPCA '93.

[56]  Stephen Brookes,et al.  Intensional investigations , 1998 .

[57]  Joseph A. Fisher,et al.  Predicting conditional branch directions from previous runs of a program , 1992, ASPLOS V.

[58]  Peter Sestoft,et al.  Partial evaluation and automatic program generation , 1993, Prentice Hall international series in computer science.

[59]  Garth A. Gibson,et al.  Automatic I/O hint generation through speculative execution , 1999, OSDI '99.

[60]  Simon L. Peyton Jones,et al.  Making a fast curry: push/enter vs. eval/apply for higher-order languages , 2004, ICFP '04.

[61]  Simon L. Peyton Jones,et al.  HsDebug: debugging lazy programs by not being lazy , 2003, Haskell '03.

[62]  Kunle Olukotun,et al.  Using thread-level speculation to simplify manual parallelization , 2003, PPoPP '03.

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

[64]  Margaret Martonosi,et al.  Effectiveness of trace sampling for performance debugging tools , 1993, SIGMETRICS '93.

[65]  Andrew Simon Partridge,et al.  Speculative evaluation in parallel implementations of lazy functional languages , 1991 .

[66]  Mads Rosendahl,et al.  Automatic complexity analysis , 1989, FPCA.

[67]  Henry G. Baker,et al.  “Use-once” variables and linear objects: storage management, reflection and multi-threading , 1995, SIGP.

[68]  Simon Peyton Jones,et al.  Implementing Functional Languages: a tutorial , 2000 .

[69]  Simon Peyton Jones,et al.  Tackling the Awkward Squad: monadic input/output, concurrency, exceptions, and foreign-language calls in Haskell , 2005 .

[70]  Olivier Danvy,et al.  Tutorial notes on partial evaluation , 1993, POPL '93.

[71]  Thomas Johnsson,et al.  Lambda Lifting: Treansforming Programs to Recursive Equations , 1985, FPCA.

[72]  Antonio González,et al.  Clustered speculative multithreaded processors , 1999, ICS '99.

[73]  Simon L. Peyton Jones,et al.  Optimistic evaluation: an adaptive evaluation strategy for non-strict programs , 2003, ICFP '03.

[74]  Dean M. Tullsen,et al.  Simultaneous multithreading: Maximizing on-chip parallelism , 1995, Proceedings 22nd Annual International Symposium on Computer Architecture.

[75]  John Launchbury,et al.  Unboxed values as first class citizens , 1991 .

[76]  Harry G. Mairson From Hilbert Spaces to Dilbert Spaces: Context Semantics Made Simple , 2002, FSTTCS.

[77]  Niklas Röjemo,et al.  New dimensions in heap profiling , 1996, Journal of Functional Programming.

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

[79]  Manoj Franklin,et al.  A general compiler framework for speculative multithreading , 2002, SPAA '02.

[80]  S. Abramsky The lazy lambda calculus , 1990 .

[81]  Simon L. Peyton Jones,et al.  Generational garbage collection for Haskell , 1993, FPCA '93.

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

[83]  Amr Sabry,et al.  The essence of compiling with continuations , 1993, PLDI '93.

[84]  Jong-Deok Choi,et al.  The Jalape�o Dynamic Optimizing Compiler for JavaTM , 1999, JAVA '99.

[85]  Friedrich L. Bauer,et al.  Revised report on the algorithm language ALGOL 60 , 1963, CACM.

[86]  Henrik Nilsson,et al.  The Evaluation Dependence Tree: An Execution Record for Lazy Functional Debugging , 1996 .

[87]  Colin Runciman,et al.  Tracing Lazy Functional Computations Using Redex Trails , 1997, PLILP.

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

[89]  Matthias Felleisen,et al.  The semantics of future and its use in program optimization , 1995, POPL '95.

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

[91]  Philip Wadler,et al.  Once upon a type , 1995, FPCA '95.

[92]  Richard E. Jones,et al.  Tail recursion without space leaks , 1992, Journal of Functional Programming.

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

[94]  Henrik Nilsson,et al.  How to look busy while being as lazy as ever: the Implementation of a lazy functional debugger , 2001, Journal of Functional Programming.

[95]  Andrew W. Appel,et al.  Garbage Collection can be Faster than Stack Allocation , 1987, Inf. Process. Lett..

[96]  David Sands,et al.  A Naïve Time Analysis and its Theory of Cost Equivalence , 1995, J. Log. Comput..

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

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

[99]  Gill Andy Debugging Haskell by Observing Intermediate Data Structures , 2001 .

[100]  A. H. Dekker,et al.  Speculative parallelism in a distributed graph reduction machine , 1989, [1989] Proceedings of the Twenty-Second Annual Hawaii International Conference on System Sciences. Volume II: Software Track.

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

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

[103]  Matthew Arnold,et al.  A framework for reducing the cost of instrumented code , 2001, PLDI '01.

[104]  John Hughes,et al.  Report on the Programming Language Haskell 98 , 1999 .

[105]  Marko C. J. D. van Eekelen,et al.  Concurrent Clean , 1991, PARLE.

[106]  C.-H. Luke Ong The Lazy Lambda Calculus : an investigation into the foundations of functional programming , 1988 .

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

[108]  Keith Wansbrough,et al.  Simple polymorphic usage analysis , 2003 .

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

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

[111]  Rex L. Page,et al.  Deleting Irrelevant Tasks in an Expression-Oriented Multiprocessor System , 1981, TOPL.

[112]  Colin Runciman,et al.  Complete and Partial Redex Trails of Functional Computations , 1997, Implementation of Functional Languages.

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

[114]  Philip Wadler,et al.  Monads for functional programming , 1995, NATO ASI PDC.

[115]  Colin Runciman,et al.  Multiple-View Tracing for Haskell: a New Hat , 2001 .

[116]  Fay W. Chang,et al.  Operating System I/O Speculation: How Two Invocations Are Faster Than One , 2003, USENIX Annual Technical Conference, General Track.

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

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

[119]  Brian W. Kernighan,et al.  The C Programming Language , 1978 .

[120]  Arvind,et al.  Implicit parallel programming in pH , 2001 .

[121]  Andrew W. Appel,et al.  A Debugger for Standard ML , 1995, Journal of Functional Programming.

[122]  Chris Hankin,et al.  Strictness Analysis for Higher-Order Functions , 1986, Sci. Comput. Program..