GHC Profiler Output

I went through a blog discussion of space leaks in Haskell and tried to understand the graph output provided by the ghc profiler (after using hp2ps)

In particular, this is the code I'm looking at:

main = print (f [1..4000000] (0 :: Int, 1 :: Int))

f [] c = c   
f (x:xs) c = f xs (tick x c) 

tick x (c0,c1) | even x = (c0,c1+1)
               | otherwise = (c0+1,c1)

I ran a program with the -hb flag for biographical profiling of the heap:

Heap Biographical Profile

I cannot understand why so much memory is considered in the void category, as this means that most of the memory is allocated for objects that are never used. I limited the manufacturer profile only to void components that get output for the manufacturer profile limited by the invalid component:

Hc output is limited by void

Is there a way to find out what exactly thunks form that lead to the use of emptiness?

+4
1

() .

main = print (f [1..4000000] (0 :: Int, 1 :: Int))

main = print (f list (0 :: Int, 1 :: Int))
   where
   list = [1..4000000]

, main.list/main/Main.CAF, , 4M- . , , , [Integer]. [Int], .

, f/main/... , . , , .

,

f [] c = c   
f (x:xs) c = f xs $! tick x c 

tick x (c0,c1) | even x = (,) c0 $! c1+1
               | otherwise = ((,) $! c0+1) c1

, Int.

GHC 8.0.1 , -O2.

, , , GHC / . .

+1

Source: https://habr.com/ru/post/1679599/


All Articles