[Haskell-cafe] Why is my mappend so slow?

martin martin.drautzburg at web.de
Fri Nov 20 10:19:35 UTC 2015

Am 11/20/2015 um 10:31 AM schrieb Tom Ellis:
> On Fri, Nov 20, 2015 at 10:18:46AM +0100, martin wrote:
>> (++) is only used in the Wtrs themselves, but these are only called when I am actually logging something, which is only
>> a handful of lines. Adding an mempty Logger does not change the number of lines written but does change the execution
>> time. So I don't think this is it.
> Surely every call logs *something* even if it's []?

Not really. If nothing gets logged, then my loggers return the original log. There is no (++) involved, not even a ([]
++ log). The cost should only be the cost of checking the condition.

logCount' :: Monoid log => Int -> Int -> Int ->  Wtr (Int,a) log -> Logger a log
logCount' dn nxt s wtr = Lgr f
            f a l = if s == nxt
                    then (runWtr wtr (s,a)  <> l, logCount'  dn (nxt+dn) (s+1) wtr)
                    else (l,                      logCount'  dn nxt      (s+1) wtr)

More information about the Haskell-Cafe mailing list