Suppose I have a module like this:
module Explosion where import Pipes.Parse (foldAll, Parser, Producer) import Pipes.ByteString (ByteString, fromLazy) import Pipes.Aeson (DecodingError) import Pipes.Aeson.Unchecked (decoded) import Data.List (intercalate) import Data.ByteString.Lazy.Char8 (pack) import Lens.Family (view) import Lens.Family.State.Strict (zoom) produceString :: Producer ByteString IO () produceString = fromLazy $ pack $ intercalate " " $ map show [1..1000000] produceInts :: Producer Int IO (Either (DecodingError, Producer ByteString IO ()) ()) produceInts = view decoded produceString produceInts' :: Producer Int IO () produceInts' = produceInts >> return () parseBiggest :: Parser ByteString IO Int parseBiggest = zoom decoded (foldAll max 0 id)
The "produString" function is a bytestring producer, and I'm interested in compiling parsing on it to get some kind of result.
The following two programs show various ways to solve the problem of finding the maximum value in a byte table by analyzing it as a series of JSON ints.
Program 1:
module Main where import Explosion (produceInts') import Pipes.Prelude (fold) main :: IO () main = do biggest <- fold max 0 id produceInts' print $ show biggest
Program 2:
module Main where import Explosion (parseBiggest, produceString) import Pipes.Parse (evalStateT) main :: IO () main = do biggest <- evalStateT parseBiggest produceString print $ show biggest
Unfortunately, both programs consume about 200 MB of shared memory, when I project them, the problem is, I was hoping that using streaming parsers would solve it. The first program spends most of its time and memory (> 70%) in (^.) On Lens.Samily, and the second spends it on fmap , called zoom from Lens.Family.State.Strict. Usage schedules are shown below. Both programs spend about 70% of their time collecting garbage.
Am I doing something wrong? Is the Prelude max function not strong enough? I canβt say if library functions are bad, or if I use the library incorrectly! (Probably the last one.)
For completeness, here's a git repo that you can clone and run cabal install if you want to see what I say first hand, and here is the memory usage of two programs:

