Optimisation of Generic Programs Through Inlining
- Cite this paper as:
- Magalhães J.P. (2013) Optimisation of Generic Programs Through Inlining. In: Hinze R. (eds) Implementation and Application of Functional Languages. IFL 2012. Lecture Notes in Computer Science, vol 8241. Springer, Berlin, Heidelberg
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.