[Haskell-cafe] Data.Binary suboptimal instance

Khudyakov Alexey alexey.skladnoy at gmail.com
Sat May 23 13:03:56 EDT 2009

On Saturday 23 May 2009 20:00:25 Henning Thielemann wrote:
> I think the list should be avoided at all costs, because it is so slow.
> I don't know if it is fused away by clever optimizer rules in the binary
> package. Anyway, you can treat a Builder like a list. Just replace (++)
> by 'mappend' and [] by 'mempty'.
> It should work like this:
>    do a <- getWord8
>       b <- getWord8
>       return $ Builder.singleton a `mappend` Builder.singleton b

It worked for me pretty well. Profiling shown that in my program 
{get,put}Stream functions takes less than 1% of execution time.
I don't know which tricks ghc used. 

I think code with list is more clear. Another problem that you can't use 
existing Binary instances with Builder.

  Best regards Khudyakov Alexey

More information about the Haskell-Cafe mailing list