O'Reilly logo

Real World Haskell by Donald Bruce Stewart, Bryan O'Sullivan, John Goerzen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 25. Profiling and Optimization

Haskell is a high-level language. A really high-level language. We can spend our days programming entirely in abstractions, in monoids, functors, and hylomorphisms, far removed from any specific hardware model of computation. The language specification goes to great lengths to avoid prescribing any particular evaluation model. These layers of abstraction let us treat Haskell as a notation for computation itself, letting us concentrate on the essence of the problem without getting bogged down in low-level implementation decisions. We get to program in pure thought.

However, this is a book about real-world programming, and in the real world, code runs on stock hardware with limited resources. Our programs will have time and space requirements that we may need to enforce. As such, we need a good knowledge of how our program data is represented, the precise consequences of using lazy or strict evaluation strategies, and techniques for analyzing and controlling space and time behavior.

In this chapter, we’ll look at typical space and time problems a Haskell programmer might encounter and how to methodically analyze, understand, and address them. To do this, we’ll use a range of techniques: time and space profiling, runtime statistics, and reasoning about strict and lazy evaluation. We’ll also look at the impact of compiler optimizations on performance and the use of advanced optimization techniques that become feasible in a purely functional language. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required