Is there any way to prevent a computation from being shared?

I've came upon very a strange situation with memory consumption. The smallest test case I've been able to come up with is the following: import Data.List wtf d = head . dropWhile (< 10^100) . map (*d) $ enumFrom 2 main = do print $ wtf 1 print $ wtf 2 -- Everything is ok without this line Expected result is that program runs in constant space. What really happening is that the program consumes memory until killed. If second call to wtf is removed, memory usage stays constant while the program is working. The problem is in that list returned from enumFrom is being saved between calls to wtf. Is there any way to overcome this? -- Regards, Petr

On Sat, Nov 13, 2010 at 2:55 PM, Petr Prokhorenkov
Is there any way to overcome this?
You can add {-# NOINLINE wtf #-} That will prevent the sharing. But I'm not sure if this is the best solution. Cheers, -- Felipe.

On 11/13/2010 08:55 AM, Petr Prokhorenkov wrote:
import Data.List
wtf d = head . dropWhile (< 10^100) . map (*d) $ enumFrom 2
main = do print $ wtf 1 print $ wtf 2 -- Everything is ok without this line
Is there any way to overcome this?
I think this phenomenon is called the "full laziness transform": an optimization that GHC will apply to avoid redundant computation. More details in: "Let-Floating: Moving Bindings to Give Faster Programs" http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.30.9079 So I think you're seeing bug http://hackage.haskell.org/trac/ghc/ticket/917 where the increased sharing only leads to space leaks. You could try the workaround, passing -fno-full-laziness (it might need to come after -O on the command line). I'm not sure if this'd be more or less fragile than disabling inlining as Felipe suggested. I'd also suggest adding yourself as a CC: on bug 917 so GHC HQ knows how many people are being affected by this kind of behavior. Hope this helps, -Brian

On Mon, Nov 15, 2010 at 11:27 PM, Brian Bloniarz
So I think you're seeing bug http://hackage.haskell.org/trac/ghc/ticket/917 where the increased sharing only leads to space leaks. You could try the workaround, passing -fno-full-laziness (it might need to come after -O on the command line).
I'm not sure if this'd be more or less fragile than disabling inlining as Felipe suggested. I'd also suggest adding yourself as a CC: on bug 917 so GHC HQ knows how many people are being affected by this kind of behavior.
Hope this helps, -Brian
Thank you a lot, that is definitely it. I still reckon it would not be resolved anytime soon :( -- Regards, Petr
participants (3)
-
Brian Bloniarz
-
Felipe Almeida Lessa
-
Petr Prokhorenkov