[Haskell-cafe] The state of binary (de)serialization

Johan Tibell johan.tibell at gmail.com
Wed Feb 27 18:32:43 CET 2013


On Tue, Feb 26, 2013 at 11:17 PM, Vincent Hanquez <tab at snarc.org> wrote:

> On Mon, Feb 25, 2013 at 11:59:42AM -0800, Johan Tibell wrote:
> > > - cereal can output a strict bytestring (runPut) or a lazy one
> > > (runPutLazy), whilst binary only outputs lazy ones (runPut)
> > >
> >
> > The lazy one is more general and you can use toStrict (from bytestring)
> to
> > get a strict ByteString from a lazy one, without loss of performance.
>
> Two major problems of lazy bytestrings is that:
>
> * you can't pass it to a C bindings easily.
> * doing IO with it without rewriting the chunks, can sometimes (depending
>   how the lazy bytestring has been produced) result in a serious
> degradation of
>   performance calling syscalls on arbitrary and small chunks (e.g.
> socket's 'send').
>
> Personally, i also like the (obvious) stricter behavior of strict
> bytestring.
>

My point was rather that all cereal does for you is to concat the lazy
chunks it already has to a strict bytestring before returning them. If you
want that behavior with binary just call concat yourself. The benefit of
not concatenating by default is that it costs O(n) time, which you might
avoid if you can consume the lazy bytestring directly (e.g. through writev).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130227/ffded34d/attachment.htm>


More information about the Haskell-Cafe mailing list