[Haskell-cafe] Conduit+GHC high memory use for simple Sink

Roman Cheplyaka roma at ro-che.info
Wed Aug 27 21:55:16 UTC 2014


* Michael Snoyman <michael at snoyman.com> [2014-08-27 23:48:06+0300]
> > The problem is the following Sink, which counts how many even/odd Tokens
> > are
> > seen:
> >
> >   type SinkState = (Integer, Integer)
> >
> >   sink2 :: (Monad m) => SinkState -> Sink Token m SinkState
> >   sink2 state@(!evenCount, !oddCount) = do
> >     maybeToken <- await
> >     case maybeToken of
> >       Nothing     -> return state
> >       (Just Even) -> sink2 (evenCount + 1, oddCount    )
> >       (Just Odd ) -> sink2 (evenCount    , oddCount + 1)
> 
> Wow, talk about timing! What you've run into here is expensive monadic
> bindings. As it turns out, this is exactly what my blog post from last
> week[1] covered. You have three options to fix this:
> 
> 1. Just upgrade to conduit 1.2.0, which I released a few hours ago, and
> uses the codensity transform to avoid the problem. (I just tested your
> code; you get constant memory usage under conduit 1.2.0, seemingly without
> any code change necessary.)

Interesting. From looking at sink2, it seems that it produces a good,
right-associated bind tree. Am I missing something?

And what occupies the memory in this case?

Roman
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140828/a77e6740/attachment.sig>


More information about the Haskell-Cafe mailing list