You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]
`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.
Fixeshaskell-unordered-containers#232
`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
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 ofinsert
usingfoldl'
. However if Iunion
it withsingleton
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 requiresstack
and can be invoked by:HeapTree for
test1 = foldl' (\m v -> HM.insert v v m) HM.empty [0..5]
HeapTree for
test2 = foldl' (\m v -> HM.union (HM.singleton v v) m) HM.empty [0..5]
The text was updated successfully, but these errors were encountered: