This weekend a user came into
#ghc asking how to profile their Template Haskell splices using GHC’s cost-center profiler. While this is not so hard in the simple case where you have no dependencies, doing so with a real package took a surprisingly long time and was non-obvious to even GHC developers. Consequently, I felt this might be helpful to write down the prescription.
In short, the method we arrived at takes advantage of GHC’s external interpreter coupled with
cabal-install’s support for producing package environment files. To demonstrate the approach, we will profile the Template Haskell-based lens derivation logic of the
optics-th package, using the
T799 module as our source of splices.
We first start by setting up a working directory of the project:
$ cabal unpack optics-th $ cd optics-th-0.3