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

Nicolas Trangez nicolas at incubaid.com
Thu Feb 28 11:12:00 CET 2013


On Thu, 2013-02-28 at 01:22 -0800, wren ng thornton wrote:
> On 2/27/13 2:17 AM, Vincent Hanquez wrote:
> > 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').
> 
> If you're on a POSIX system, you can always make use of
> unix-bytestring[1]. In particular, for lazy ByteStrings the function you
> want is System.Posix.IO.ByteString.Lazy.fdWritev which performs a single
> syscall to write all the chunks, and without manually concatenating them.
> 
> [1] http://hackage.haskell.org/package/unix-bytestring

FWIW: since I saw Network.Socket.ByteString.Lazy while browsing the
'network' docs I used it ('sendAll'), and when strace'ing my demo-app (a
bad habit of mine) to my pleasant surprise (although it shouldn't have
been much of a surprise given the high-quality of Haskell unix IO
libraries) I noticed it was using writev for the bytestring chunks.

So using plain 'network' (at least the version I'm using, don't know
when this was introduced) should be sufficient to get efficient LBS
socket IO handling.

Nicolas





More information about the Haskell-Cafe mailing list