GithubHelp home page GithubHelp logo

haskell-leb128-cereal's People

Contributors

nomeata avatar blynn avatar

Stargazers

Ballemons avatar Chris Lin avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

andreaspk blynn

haskell-leb128-cereal's Issues

Idea: replace the classes with newtype wrappers

Thus allowing to reuse the coding functionality of cereal by providing instances for Serialize. E.g.,

-- | Wrapper that provides instances of Serialize 
-- that implement LEB128 encoding.
newtype Leb128 n = Leb128 n

instance Serialize (Leb128 Word64) where...
instance Serialize (Leb128 Natural) where...

Make go functions strict in their arguments.

The current go definitions like this:

    go :: Int -> Int -> G.Get Int
    go shift w = do
        byte <- G.getWord8 <|> fail "short encoding"
        let !byteVal = fromIntegral (clearBit byte 7)
        let !hasMore = testBit byte 7
        let !val = w .|. (byteVal `unsafeShiftL` shift)
        let !shift' = shift+7
        if hasMore
            then go shift' val
            else return $! val

result in intermediate Int's being allocated on each iteration.

Avoid excessive overhead from toLazyBytestring in `to*LEB128`

toLazyBytestring preallocates a buffer of 4k bytes. This is highly execessive for this kind of use.

Using toLazyByteStringWith allows giving the size of the inital buffer and avoid this overhead. In practice I imagine something like 32 bytes will do. Numbers far larger than this are better served by a different encoding scheme so leb128 should not be optimized for this case.

You could go further and just compute the required length ahead of doing the encoding which would allow us to limit allocation to a single (strict) bytestring as well.

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.