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

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 -- Live well, ~wren

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.
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
participants (2)
-
Nicolas Trangez
-
wren ng thornton