Optimisation of Generic Programs Through Inlining

It is known that datatype-generic programs often run slower than type-specific variants, and this factor can prevent adoption of generic programming altogether. There can be multiple reasons for the performance penalty, but often it is caused by conversions to and from representation types that do not get eliminated during compilation. However, it is also known that generic functions can be specialised to specific datatypes, removing any overhead from the use of generic programming. In this paper, we investigate compilation techniques to specialise generic functions and remove the performance overhead of generic programs in Haskell. We pick a representative generic programming library and look at the generated code for a number of example generic functions. After understanding the necessary compiler optimisations for producing efficient generic code, we benchmark the runtime of our generic functions against handwritten variants, and conclude that the overhead can indeed be removed automatically by the compiler.

[1]  Johan Jeuring,et al.  A lightweight approach to datatype-generic rewriting , 2008, WGP '08.

[2]  David Sands,et al.  Improvement theory and its applications , 1999 .

[3]  Bruno C. d. S. Oliveira,et al.  Comparing libraries for generic programming in haskell , 2008, Haskell '08.

[4]  A. R. Alim Improved Fusion for Optimizing Generics , 2005 .

[5]  Simon Peyton Jones,et al.  Playing by the rules: rewriting as a practical optimisation technique in GHC , 2001 .

[6]  Simon L. Peyton Jones,et al.  Scrap your boilerplate: a practical design pattern for generic programming , 2003, TLDI '03.

[7]  Ralf Hinze,et al.  Comparing Approaches to Generic Programming in Haskell , 2006, SSDGP.

[8]  José P. Rodrigues Magalhães Less Is More : Generic Programming Theory and Practice , 2012 .

[9]  Manuel M. T. Chakravarty,et al.  Instant Generics: Fast and Easy , 2009 .

[10]  Philip Wadler,et al.  Theorems for free! , 1989, FPCA.

[11]  Simon L. Peyton Jones,et al.  Scrap more boilerplate: reflection, zips, and generalised casts , 2004, ICFP '04.

[12]  Sjaak Smetsers,et al.  Optimizing Generic Functions , 2004, MPC.

[13]  Simon L. Peyton Jones,et al.  Giving Haskell a promotion , 2012, TLDI '12.

[14]  Johan Jeuring,et al.  Optimizing generics is easy! , 2010, PEPM '10.

[15]  S. Jones,et al.  A Transformation-Based Optimiser for Haskell , 1998, Sci. Comput. Program..

[16]  Simon L. Peyton Jones,et al.  Secrets of the Glasgow Haskell Compiler inliner , 2002, Journal of Functional Programming.