Closed
Description
I've been trying to check strictness of my model using ppHeapTree
function from (slightly altered) ghc-heap-view package and discovered that there seem to be some thunks in HashMap following a series of insert
using foldl'
. However if I union
it with singleton
it comes out without thunks.
I've create a little project to demonstrate this behaviour: https://github.com/mantasg/hashmap-test. The version of ghc-heap-view
I used doesn't work with GHC 8.6 therefore I used stack lts-11.20 with GHC 8.2. Running it requires stack
and can be invoked by:
cd hashmap-test && stack build hashmap-test && stack exec hashmap-test
HeapTree for test1 = foldl' (\m v -> HM.insert v v m) HM.empty [0..5]
HeapTree for test1
"BitmapIndexed ([ (_thunk (I# 0) (I# 0) 0), (_thunk (I# 1) (I# 1) 1), (Leaf (I# 2) (I# 2) 2), (Leaf (I# 3) (I# 3) 3), (Leaf (I# 4) (I# 4) 4), (Leaf (I# 5) (I# 5) 5) ]) 63"
HeapTree for test2 = foldl' (\m v -> HM.union (HM.singleton v v) m) HM.empty [0..5]
HeapTree for test2
"BitmapIndexed ([ (Leaf (I# 0) (I# 0) 0), (Leaf (I# 1) (I# 1) 1), (Leaf (I# 2) (I# 2) 2), (Leaf (I# 3) (I# 3) 3), (Leaf (I# 4) (I# 4) 4), (Leaf (I# 5) (I# 5) 5) ]) 63"
Metadata
Metadata
Assignees
Labels
No labels