[GHC] #10535: Float out causes major space leak

GHC ghc-devs at haskell.org
Tue Jun 16 13:37:47 UTC 2015


#10535: Float out causes major space leak
-------------------------------------+-------------------------------------
        Reporter:  AlexET            |                   Owner:
            Type:  bug               |                  Status:  new
        Priority:  normal            |               Milestone:
       Component:  Compiler          |                 Version:  7.10.1
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  None/Unknown      |  Unknown/Multiple
      Blocked By:                    |               Test Case:
 Related Tickets:                    |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------
Description changed by AlexET:

Old description:

> This issue originally was on haskell-cafe
> https://mail.haskell.org/pipermail/haskell-cafe/2015-June/120113.html
>
> The following code has a space leak
>
> {{{
> #!hs
> numbers = [1..200]
>
> replicateM' :: Monad m => Int -> m a -> m [a]
> replicateM' 0 xs = return []
> replicateM' n xs = do
>   a <- xs
>   b <- replicateM' (n-1) xs
>   return (a:b)
>
> test :: [[Int]]
> test = replicateM' 4 numbers
>
> main = print test
> }}}
>
> The recursive call in replicateM' gets floated out. This then causes a
> very large (200^3 elements) list to be kept in memory instead of being
> lazily produced and consumed each time.
>
> A similar thing happens to the replicateM in Control.Monad but it is
> harder to spot as a lot of specialisation and fusion goes on before the
> float-out happens
>
> This is similar to #7367 but in this case we have a huge space-leak
> instead of just adding allocations.

New description:

 This issue originally was on haskell-cafe
 https://mail.haskell.org/pipermail/haskell-cafe/2015-June/120113.html

 The following code has a space leak

 {{{
 #!hs
 numbers = [1..200]

 replicateM' :: Monad m => Int -> m a -> m [a]
 replicateM' 0 xs = return []
 replicateM' n xs = do
   a <- xs
   b <- replicateM' (n-1) xs
   return (a:b)

 test :: [[Int]]
 test = replicateM' 4 numbers

 main = print test
 }}}

 The recursive call in replicateM' gets floated out. This then causes a
 very large (200^3^ elements) list to be kept in memory instead of being
 lazily produced and consumed each time.

 A similar thing happens to the replicateM in Control.Monad but it is
 harder to spot as a lot of specialisation and fusion goes on before the
 float-out happens

 This is similar to #7367 but in this case we have a huge space-leak
 instead of just adding allocations.

--

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10535#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list