[Haskell-cafe] source line annotations

Max Bolingbroke batterseapower at hotmail.com
Thu Jan 20 09:47:19 CET 2011


On 19 January 2011 23:59, Evan Laforge <qdunkan at gmail.com> wrote:
> Another thing is that performance in logging is pretty critical.  When
> I profile, logging functions wind up in the expensive list if I'm not
> careful.  I don't know bad an unsafePerformIO plus a catch for every
> log msg is going to be, but it's not going to be as fast as doing the
> work at compile time.

It is possible that GHC's optimiser will let-float the "getSourceLoc
assert" application to the top level, which would ensure that you only
take the hit the first time. However, I'm not sure about this - do an
experiment!

Since logging is in IO anyway, perhaps GHC could provide a new magic
primitive, (location :: IO String), which was replaced by the compiler
with an expression like (return "MyLocation:42:1"). Your consumer
could then look like

myLogFunction location "extra-info"

(myLogFunction is in IO and would deal with >>=ing in the location).
This would be much less of a potential performance drag than going
through exceptions. Shouldn't be too hard to patch GHC to do this,
either.

Cheers,
Max



More information about the Haskell-Cafe mailing list