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

#10535: Float out causes major space leak -------------------------------------+------------------------------------- Reporter: AlexET | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- 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 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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

#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: -------------------------------------+------------------------------------- Comment (by nomeata): Can you tell whether this is related to the state hack? I.e., does `-fno- state-hack` make a difference? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10535#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: -------------------------------------+------------------------------------- Comment (by AlexET): {{{-fno-state-hack}}} makes no difference {{{-fno-full-laziness}}} does fix the problem. In many ways the float out pass is doing what it is supposed to (floating out a shared value though a lambda) as it now does less work. However the list which is floated out is produced and consumed lazily and hence the floating out causes a major space leak (space leak may be the wrong term as the extra is constant but very large (1GB)). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10535#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: #7367 #7206 | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by nomeata): * related: => #7367 #7206 Comment: Ah, right. Sounds like a case for http://arxiv.org/abs/1207.2017 :-]. Anyways, this is a tricky problem; how could the compiler detect things that are cheaper to recalculate than to share? #7206 is also related. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10535#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #7367 #7206 | Differential Revisions: -------------------------------------+------------------------------------- Comment (by rwbarton): This is a frequently reported issue. The original is #917, and other tickets (#1945, #3273, #4276, #5729) have been closed as duplicates of it. #8457 has a recapitulation of the subject. Should we close this ticket as a duplicate too? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10535#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10535: Float out causes major space leak -------------------------------------+------------------------------------- Reporter: AlexET | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.10.1 Resolution: duplicate | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #7367 #7206 | Differential Revisions: -------------------------------------+------------------------------------- Changes (by simonpj): * status: new => closed * resolution: => duplicate Comment: Yes, that makes sense. I wish I knew what to do about the full-laziness space leak problem! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10535#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10535: Float out causes major space leak -------------------------------------+------------------------------------- Reporter: AlexET | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.10.1 Resolution: duplicate | Keywords: FloatOut Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #7367 #7206 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * keywords: => FloatOut -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10535#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC