[Haskell-cafe] Sub-optimal [code]

Claude Heiland-Allen claude at goto10.org
Tue Feb 15 22:20:06 CET 2011


On 15/02/11 20:35, Daniel Fischer wrote:
> Which makes me wonder: unwanted sharing of lists [1 .. n] or similar is a
> frequent cause of space leaks, so would it be possible to teach GHC to not
> share such lists (unless they're bound to a name to indicate sharing is
> wanted)?

> In particular for enumerations [a .. b] of type [Int], [Integer] or
> similar, I'm pretty sure that the cost of recomputation is far outweighed
> by the memory consumption of sharing in almost all cases.

Compare with the heap profile graph output from this short program which 
uses a horrible data-dependency hack to force recomputation:

main = do
   print $ length
     [(x,y) | x <- [(1 :: Int) .. 10000], y <- [(1 :: Int) .. 10000]]
   print $ length
     [(x,y) | x <- [(1 :: Int) .. 10000], y <- [x+1-x .. 10000]]

The heap profile graph looks a little like this:

########
########
########
########
########_______

(Tested with ghc 6.12.3 -O2 on linux x86_64)


Claude
-- 
http://claudiusmaximus.goto10.org



More information about the Haskell-Cafe mailing list