Inlining
Inlining is the most important compiler optimisation pass as it enables most other optimisation opportunities. The pass is simple, saturated names are replaced with their definitions, the details are complicated. The compiler must make judgements as to whether inlining a function will lead to further optimisations, if not then it is easy to increase the code size needlessly.
Getting Started
- Secrets of the GHC inliner -- quite an old paper but a great description of the main ideas
-
GHC User Guide -- Provides a description of
INLINE
,INLINABLE
andNOINLINE
pragmas. - Inlining and Specialisation -- A blog post explaining the basic operation of the inliner and specialiser and the interaction of different pragmas and options.
Generics and Inlining
Inlining is essential to remove intermediate representations from generic programs. There are a number of papers about the topic.
Debugging the inliner
Firstly, remember that the inliner only fires with optimisations turns on (at least -O1
). This will save you a lot of time wondering why nothing is happening!
There are several flags which are useful when working with the inliner.
Flag | Usage |
---|---|
`--show-iface` | Shows the contents of an interface file. Can be useful to check which unfoldings are being included. |
`-dshow-passes` | Shows the size of the program after each optimisation pass. |
`-ddump-inlinings` | Shows inlinings which take place |
`-ddump-simpl` | Dump the (core) output of the simplifer |
Relevant Tickets
See the inlining label.
There are also lots of old relevant tickets related to inlining. Perfect for a keen newcomer! Look for tickets labelled with both inlining and newcomer.
Relevant Wiki Pages
- Commentary/Compiler/DesugaringInstances -- About how default methods can lead to poor inliner performance due to recursion
- Proposal/SelfExplinatoryInlinePragmas