Skip to content

Performance issue with skip #73

@dlichtenberger

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

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