Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HashMap has thunks for internal nodes after construction using strict operations #232

Closed
mantasg opened this issue May 6, 2019 · 0 comments · Fixed by #233
Closed

HashMap has thunks for internal nodes after construction using strict operations #232

mantasg opened this issue May 6, 2019 · 0 comments · Fixed by #233

Comments

@mantasg
Copy link

mantasg commented May 6, 2019

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"
treeowl added a commit to treeowl/unordered-containers that referenced this issue May 6, 2019
`two` wasn't strict in its key arguments. We thought this was okay,
because its key arguments are always in WHNF and it's marked
`INLINE`. But `two` is defined as a *recursive* `go` function
(I haven't looked into why), which can't be inlined. I believe
that's the reason GHC doesn't *realize* that the keys are in WHNF.
Anyway, the end result was that `two` would defer the creation of
the `Leaf` values stored in the array, producing very silly thunks.

Fixes haskell-unordered-containers#232
treeowl added a commit that referenced this issue May 6, 2019
`two` wasn't strict in its key arguments. We thought this was okay,
because its key arguments are always in WHNF and it's marked
`INLINE`. But `two` is defined as a *recursive* `go` function
(I haven't looked into why), which can't be inlined. I believe
that's the reason GHC doesn't *realize* that the keys are in WHNF.
Anyway, the end result was that `two` would defer the creation of
the `Leaf` values stored in the array, producing very silly thunks.

Fixes #232
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant