Visitar URL original
Performance issue with skip · Issue #73 · haskell/binary · GitHub
Skip to content

Performance issue with skip #73

Closed
Closed

Description

@dlichtenberger

I'm using the lazy interface of Data.Binary.Get to parse large binaries from disk, where most parts are skipped on the first pass. When using skip directly, I get a severe performance and space usage problem when the skipped byte count is large (many megabytes). I'm not an expert on lazy bytestring internals, but it seems like the input data is held on for too long before being skipped ("PINNED" memory usage in -hc heap profile). Using this wrapper around skip makes it several orders of magnitude faster and does not explode on the heap (I'm using GHC 7.10.1):

import qualified Data.Binary.Get as G

skipMany :: Int -> G.Get ()
skipMany bytes = 
  replicateM_ rep (G.skip cs) >> G.skip rest
 where
   cs = 1024
   (rep, rest) = bytes `quotRem` cs

Activity

  1. self-assigned this
    on May 11, 2015
  2. kolmodin commented on May 11, 2015

    @kolmodin
    Member

    Right. The current implementation of skip concatenates the bytes to be skipped, and then throws it away.

    This is unnecessarily expensive. I'll work on a more efficient implementation.

  3. kolmodin commented on May 11, 2015

    @kolmodin
    Member

    I might add that even with the more efficient implementation, it will still force to read all the data from disk (or wherever it comes from) which might be inefficient for your case.
    The most efficient implementation would be to seek in the file descriptor and only read the parts needed.

  4. kolmodin commented on May 30, 2015

    @kolmodin
    Member

    Fixed in e46b7b6.

  5. added a commit that references this issue on Jun 1, 2015
  6. added a commit that references this issue on Jun 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions