[Haskell-cafe] ANNOUNCE: binary: high performance, pure binary serialisation

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Sat Jan 27 16:40:12 EST 2007

On Sat, 2007-01-27 at 19:11 +0100, Henning Thielemann wrote:
> On Sat, 27 Jan 2007, Donald Bruce Stewart wrote:

> > The underlying Get and Put monads support explicit endian writes and
> > reads, which you can add to your instances explicitly:
> > 
> >     http://www.cse.unsw.edu.au/~dons/binary/Data-Binary-Get.html#5
> >     http://www.cse.unsw.edu.au/~dons/binary/Data-Binary-Put.html#5
> > 
> > So you can do that now. 
> Of course, I can check for the machine's endianess, then decide whether to
> use putWord16be and putWord16le. But I assume that it is more efficient,
> if there would be some function putWord16native, which writes out in the
> machine's native endianess.

Note that actually taking advantage of aligned word reads/writes is not
especially simple since one has to guarantee alignment. So that means no
byte writes, everything, chars, bools, record tags would have to be word
sized. While it's not so hard to arrange alignment for writes (since we
get to allocate the buffers) for reads we have no guarantee since the
user supplies the byte string input and they could have uses say 'tail'
so the data may be all unaligned. Dealing with both aligned and
unaligned makes it more complex.

We did a performance experiment with this and found that it gained us
very little. There are bigger performance bottlenecks at the moment than
the penalty of always doing byte reads/writes.


More information about the Haskell-Cafe mailing list