def-/ghc-datasize

Weird results for values of type Int

Closed this issue · 2 comments

The idea behind this package looks interesting! I've wanted something like this for a long time!

I've tried to play with it in GHCi. And I see very strange results:

λ: x = 3 :: Int
λ: :t x
x :: Int
λ: closureSize x
32
λ: recursiveSize x
168
λ: recursiveSizeNF x
408

When I tried to put this into separate executable and compiled code, I'm always seeing 16 with every function. However, I expect to see 8 which is a size of Int on a 64-bit machine. I could understand 16 for Int: Int is actually I# Int# so one word for the pointer to Int# and one word for Int# itself hence 16 bytes (two words). However, when I'm running executable (compiled with GHC-8.6.5) I see 16 for different types: Bool, (), Int, Double, Char, Nothing :: Maybe Int.

Could you, please, explain, how to interpret these results?

P.S. Exploration motivated by the following issue:

def- commented

In interpreted form x is not fully evaluated yet, but you can force an evaluation as described in the user guide: http://felsin9.de/nnis/ghc-datasize/

λ: recursiveSize $! x
16

Note that you could also use ghc-heap-view or ghc-vis (not sure if it currently works) to see what the actual structures are.

Thank you for your answer!