polysemy-0.1.2.0: Higher-order, low-boilerplate, zero-cost free monads.

Safe HaskellNone
LanguageHaskell2010

Polysemy.Internal.TH.Performance

Synopsis

Documentation

inlineRecursiveCalls :: Q [Dec] -> Q [Dec] Source #

GHC has a really hard time inlining recursive calls---such as those used in interpreters for higher-order effects. This can have disastrous repercussions for your performance.

Fortunately there's a solution, but it's ugly boilerplate. You can enable -XTemplateHaskell and use inlineRecursiveCalls to convince GHC to make these functions fast again.

inlineRecursiveCalls [d|
  runReader :: i -> Sem (Reader i ': r) a -> Sem r a
  runReader i = interpretH $ \case
    Ask -> pureT i
    Local f m -> do
      mm <- runT m
      raise $ runReader (f i) mm
  |]