[Haskell-cafe] HasCallStack - runtime costs?

Johannes Waldmann johannes.waldmann at htwk-leipzig.de
Fri Mar 4 14:53:36 UTC 2016


Dear Cafe,

the new (8.*) call stack feature
https://downloads.haskell.org/~ghc/8.0.1-rc2/docs/html/users_guide/glasgow_exts.html#hascallstack
is certainly nice for debugging during development.

But how costly is it at runtime? I notice a 5 percent slowdown.

That's not a problem if there's an easy way to switch
this off for production (without changing the code).

Related: how to make code that uses it,
compile with older ghcs that don't have it.

I made this hack: do not import GHC.Stack.Types, but instead

{-# language CPP, MultiParamTypeClasses #-}

#if (__GLASGOW_HASKELL__ < 710)
{-# language NullaryTypeClasses #-}
#endif

module Stack
( HasCallStack )
where

#if (__GLASGOW_HASKELL__ >= 800)
import GHC.Stack.Types
#else
class HasCallStack
instance HasCallStack
#endif

When I compile with 8.rc2, and change ">= 800" to ">= 900",
I am getting the 5 percent speedup mentioned above.

But does it really do what I hope it does
(remove all runtime overhead that call stacks may have)?

When I compile with 7.10.3, I am getting 5 .. 10 percent faster again.

My code does nothing fancy (w.r.t. types and libraries),
it just uses Data.IntMap heavily. And it has some

class Semiring s where
  zero :: s
  one  :: s
  plus :: HasCallStack => s -> s -> s
  times :: HasCallStack => s -> s -> s

- J.W.


More information about the Haskell-Cafe mailing list