Haskell Performance Tuning Checklist

(This is a quick check-list from my experience. May turn into an illustrated slideshow when I have time)

  • Common sub-expression elimination
  • Static argument transformation
  • Use unsafe/unboxed operations in tight loops (e.g. quotRem vs divMod)
  • When in doubt, spam some BangPatterns around for experiment

And here is a real life dissection of how I tuned a Haskell program: In Search of Performance in Haskell

Short note on “How to read Core”

This has always been a mysterous subject — a lot of people talking about it but not many people demonstrating it. Basically, what you want to do when reading Core is to make sure the checklist above has been realized by the compiler. For example

  • Are unboxed types really used in inner loops as you thought?
  • Is an argument being passed around but not really used?
  • etc.

With the advance of compilers, reading Core should become less necessary (I suspect reading assembly will become more useful), as a simple experiment by changing the source is often easier.

In summary, when reading Core, you want to “look for anything suspicious”, using the above guideline, just as you would reading high level Haskell.

Conway’s Game of Life with Repa

Download PDF Browse source

Template Haskell Tutorial

Download PDF Browse source code