Giter Club home page Giter Club logo

Comments (5)

abooij avatar abooij commented on June 27, 2024

This is now implemented as the store (see also the release announcement).

from sudbury.

tclv avatar tclv commented on June 27, 2024

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 map id in there as well to give an idea of the cost of traversing the entire structure and forcing it to normal form.

screen shot 2016-12-10 at 20 58 25

from sudbury.

tclv avatar tclv commented on June 27, 2024

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 ByteString in Store itself.
Before I can write a PR implementing this in Sudbury itself, I have a couple of things that need to be discussed:

  • It might be nice to derive Generic on WirePackages and other applicable data structures as that allows a variety of useful classes to be used (like NFData). Probably more relevant for things that actually get exposed for the users.

  • The implementation uses internals from ByteString.Internal. This module is "unsafe", and thus breaks the Safe pragmas. Is there a obvious solution to this? I'm not too familiar with the Safe pragmas.

  • What does the Wayland protocol require with regards to Endianness? The people from Store were talking about implementing store in such a way that it will always write to Little Endian ByteString format (from both LE and BE machines). Is this desirable?

  • Any ideas for more interesting tests than decodeEx . encode == id

  • Is there a more idiomatic approach to toInt 😞

from sudbury.

abooij avatar abooij commented on June 27, 2024

This is really nice.

I'll respond quickly now and more thoroughly later, so that I'm not holding you up:

  • I'd like to err on the side of caution wrt Generic and NFData. When you need to do a full forcing of your objects explicitly, you're probably solving the wrong problem (I'd prefer an approach like the one taken here). But of course such instances are acceptable for benchmarks and tests. Note that you can add a "deriving instance" after the fact using the StandaloneDeriving language extension.
  • The obvious solution is to stop using the safety pragmas as these are sort of deprecated anyway. Feel free to remove any safety pragma that gets in your way.
  • The wayland wire protocol specifies that encoding is based on the host's encoding. I believe this is what store does anyway (but it'd be worth checking+documenting).
  • Well perhaps we could hard-code some sample packages, and package streams. I think the easiest way to record them is to use sudbury itself.
  • fromIntegral is perhaps what you are looking for.

from sudbury.

tclv avatar tclv commented on June 27, 2024
  • StandaloneDeriving is indeed what I was looking for, thanks!
  • Okay I'll be liberal in removing them
  • I think they do indeed. There's currently this issue: mgsloan/store#31, where indeed HostEndianness is assumed.
  • Alright, I think that might be worth doing in a separate PR (related to #2 I guess)
  • Crap

I'll get started on the PR

from sudbury.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.