-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Efficient binary serialization #6
Comments
This is now implemented as the store (see also the release announcement). |
So I took a jab at implementing this. In the following screenshot you can see the performance differences. The performance is encoding/decoding 10000 random Wire Packages (with 20-200 bytes payload evenly distributed in microseconds). I put |
The Storable interface was implemented like this for the benchmark: toInt :: Integral a => a -> Int
toInt = fromInteger . toInteger
{-# INLINE toInt #-}
instance Store WirePackage where
size = VarSize $ toInt . wirePackageSize
poke (WirePackage sen size op pl) = do
poke sen
poke op
poke size
let (sourceFp, sourceOffset, sourceLength) = B.toForeignPtr pl
pokeFromForeignPtr sourceFp sourceOffset sourceLength
peek = do
sen <- peek
op <- peek
size <- peek
let payloadSize = toInt size - 8
pl <- peekToPlainForeignPtr "Data.ByteString.ByteString" payloadSize
return $ WirePackage sen size op (B.PS pl 0 payloadSize)
{-# INLINE size #-}
{-# INLINE peek #-}
{-# INLINE poke #-} This implementation is largely derived from the implementation of
|
This is really nice. I'll respond quickly now and more thoroughly later, so that I'm not holding you up:
|
I'll get started on the PR |
Currently we are serializing and deserializing using bytestring builders and attoparsec, respectively. But that seems like overkill, as our grammars are much simpler than what those libraries support.
Michael Snoyman has written an article and library for serialization in Haskell that might be relevant to our use case.
The text was updated successfully, but these errors were encountered: