[Haskell-cafe] Space leak with replicateM

Joachim Breitner mail at joachim-breitner.de
Tue Jun 16 09:09:58 UTC 2015


Hi,

Am Dienstag, den 16.06.2015, 03:37 -0400 schrieb Ken Takusagawa II:
> In the following program, the function "test1" results in huge memory 
> usage, but substituting "test2", which does essentially the same 
> thing, does not.  GHC 7.10.1, AMD64.  Is there a different 
> implementation of replicateM that avoids the space leak?
> 
> module Main where {
> import Control.Monad;
> 
> numbers :: [Int];
> numbers=[1..200];
> 
> -- has a space leak
> test1 :: [[Int]];
> test1 = replicateM 4 numbers;
> 
> -- no space leak
> test2 :: [[Int]];
> test2 = do {
> x1 <- numbers;
> x2 <- numbers;
> x3 <- numbers;
> x4 <- numbers;
> return [x1,x2,x3,x4];
> };
> 
> main :: IO();
> main = print $ length $ test1;
> 
> }
> 

Could be the state hack causing `numbers` to inline, see
http://stackoverflow.com/questions/29404065/why-does-this-haskell-code-run-slower-with-o/30603291#30603291
and
https://ghc.haskell.org/trac/ghc/ticket/9349

Greetings,
Joachim

-- 
Joachim “nomeata” Breitner
  mail at joachim-breitner.dehttp://www.joachim-breitner.de/
  Jabber: nomeata at joachim-breitner.de  • GPG-Key: 0xF0FBF51F
  Debian Developer: nomeata at debian.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150616/8c13cafc/attachment.sig>


More information about the Haskell-Cafe mailing list