[Haskell-cafe] Data.Binary suboptimal instance

Henning Thielemann lemming at henning-thielemann.de
Sat May 23 15:22:48 EDT 2009


Khudyakov Alexey schrieb:
> 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.

You can since there is

http://hackage.haskell.org/packages/archive/binary/0.5.0.1/doc/html/Data-Binary-Put.html#v%3AexecPut


More information about the Haskell-Cafe mailing list