This page is concerned with the memory footprint of Haskell data structures stored in the heap.
The heap is the garbage collected area of memory in which the running program introduces heap nodes.
An in-depth explanation of the GHC internals can be found in the GHC Commentary: The Layout of Heap Objects.
A good introduction on how to compute the size of Haskell datastructures can be found in Johan Tibell's Computing the size of a HashMap.
Memory Footprints of common data types
See also Memory footprints of some common data types which is the origin of the table below.
The following tables assumes fully evaluated data structures (i.e. no thunks).
A "word" is 4 bytes on 32=bit architectures, and 8 bytes on 64-bit architectures. Sizes are usually rounded up to word-boundaries.
|()||0 words||Single shared ()|
|Bool||0 words||Single shared True/False|
|Char||2 words||Char-sharing pool|
|Int8||2 words||Due to alignment|
|Int16||2 words||Due to alignment|
|Int32||2 words||Due to alignment|
|Int64 (on 64-bit arch)||2 words|
|Int64 (on 32-bit arch)||3 words|
|Word8||2 words||Due to alignment|
|Word16||2 words||Due to alignment|
|Word32||2 words||Due to alignment|
|Word64 (on 64-bit arch)||2 words|
|Word64 (on 32-bit arch)||3 words|
|Double (on 64-bit arch)||2 words|
|Double (on 32-bit arch)||3 words|
|Integer (small)||2 words|
|Integer (bignum rep.)||3 words + sizeof(bignum-repr)||FIXME|
|(va,vb)||3 words + sizeof(va) + sizeof(vb)|
|[v]||(1 + 3N) words + N * sizeof(v)||Single shared |
|Data.ByteString||9 words + N bytes|
|Data.Text||6 words + 2N bytes|
|Data.Map k v||6N words + N * (sizeof(k) + sizeof(v))|
|Data.Set v||5N words + N * sizeof(v)|
|Data.IntMap v||(3N + 5(N-1) words) + sizeof(v)|
|Data.IntSet||(2N + 5(N-1)) words|
|Data.HashMap k v||4.5N words + N * (sizeof(k) + sizeof(v))|
|Data.HashSet||4.5N words + N * sizeof(v)|
|Data.Vector v||(7 + N) words + N * sizeof(v)||Slices take 3N words + N * sizeof(v)|