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

Roman Cheplyaka roma at ro-che.info
Fri Nov 20 10:33:06 UTC 2015


On 11/20/2015 12:19 PM, martin wrote:
> 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.

Even for mempty, you're still recursively mappending the "tails" of the
loggers. How about introducing a designated constructor for mempty to
avoid that recursive mappend? (The same constructor will be used when a
logger is "done" and is known not to produce any further output.)

Roman

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20151120/5668dcde/attachment-0001.sig>


More information about the Haskell-Cafe mailing list