Symposium on Implementation and Application of Functional Languages

IFL 2012: Implementation and Application of Functional Languages pp 104-121

Optimisation of Generic Programs Through Inlining

Conference paper

DOI: 10.1007/978-3-642-41582-1_7

Volume 8241 of the book series Lecture Notes in Computer Science (LNCS)
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

Abstract

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.

Copyright information

© Springer-Verlag Berlin Heidelberg 2013

Authors and Affiliations

  1. 1.Department of Computer ScienceUniversity of OxfordOxfordUK