Book Image

Haskell High Performance Programming

By : Samuli Thomasson
Book Image

Haskell High Performance Programming

By: Samuli Thomasson

Overview of this book

Haskell, with its power to optimize the code and its high performance, is a natural candidate for high performance programming. It is especially well suited to stacking abstractions high with a relatively low performance cost. This book addresses the challenges of writing efficient code with lazy evaluation and techniques often used to optimize the performance of Haskell programs. We open with an in-depth look at the evaluation of Haskell expressions and discuss optimization and benchmarking. You will learn to use parallelism and we'll explore the concept of streaming. We’ll demonstrate the benefits of running multithreaded and concurrent applications. Next we’ll guide you through various profiling tools that will help you identify performance issues in your program. We’ll end our journey by looking at GPGPU, Cloud and Functional Reactive Programming in Haskell. At the very end there is a catalogue of robust library recommendations with code samples. By the end of the book, you will be able to boost the performance of any app and prepare it to stand up to real-world punishment.
Table of Contents (21 chapters)
Haskell High Performance Programming
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Diagnosing parallelism – ThreadScope


Next we will look at a program visualization tool, ThreadScope. Install the threadscope executable with:

stack install threadscope

To extract the eventlog that ThreadScope uses from a Haskell program, we need to compile with -eventlog and execute with the -l Runtime System option. Running the program then generates a program.eventlog file, which ThreadScope reads. In a convenient single recipe, we lay out these commands:

ghc -O2 -threaded -eventlog -with-rtsopts="-N -l" program.hs

./program

threadscope program.eventlog

ThreadScope provides a graphical user interface. The opening view shows processor core utilization. An example view from some eventlog is:

Along with total utilization, we can see the work split on all processors (four in this case). What we also see in this graph, below each core utilization, is that there is GC activity. The program actually pauses quite often just to do GC for a split second. Sometimes such scenarios might require further...