[Haskell-cafe] Re: Strange memory usage problem

John Lato jwlato at gmail.com
Fri Jul 31 19:45:58 EDT 2009

> From: Ketil Malde <ketil at malde.org>
> Hi,
> I'm observing something I find quite strange.  I have a program that
> normally streams through a file, and it runs in the expected constant
> space, consuming about 5MB, according to 'top'.  When I uncomment a
> certain block of code in the library it uses, space consumption
> appears to grow linearly with the input size.
> This is a bit surprising to me, since the code in question isn't used
> by the program at all, and yesterday, Cale confirmed this behavior on
> a recent GHC (6.10.3, I think - mine is 6.8.2 as shipped with Ubuntu
> 9.04).

I can confirm this behavior on GHC 6.10.4 on OSX 10.5.7.

Try adding
{-# INLINE getRB #-}

above the getRB definition.  That fixes it for me.

I think that when the rest of the code is commented out, getRB is only
called in one location, so GHC inlines it automatically.  Since getRB
is also called in the commented-out code, it probably isn't
automatically inlined when that code is available.  I suspect that the
inlining allows GHC to infer some strictness property it otherwise

John Lato

More information about the Haskell-Cafe mailing list