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

Make two strict in its key arguments #233

Merged
merged 2 commits into from
May 6, 2019

Conversation

treeowl
Copy link
Collaborator

@treeowl treeowl commented 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

`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
Copy link
Collaborator Author

treeowl commented May 6, 2019

@mantasg, could you please test against this commit?

@treeowl
Copy link
Collaborator Author

treeowl commented May 6, 2019

I realized something else.... two should surely be rewritten to take leaves instead of values. That way, we can avoid allocating fresh copies of leaves we already have.

Previously, we passed `two` two unpacked key-value pairs:
`hx`, `kx`, `vx`, `hy`, `ky`, `vy`. But at every call site,
we already have `Leaf hy (L ky vy)`. So instead of building a
new copy of the leaf, we can just pass the one we have to
`two`.
@treeowl
Copy link
Collaborator Author

treeowl commented May 6, 2019

@mantasg, actually, could you test it at the second commit here? I turned things around a bit.

@mantasg
Copy link

mantasg commented May 6, 2019

@treeowl, I ran the tests with the changes (at 0d06c107f017937338b9a16aeb73b6e3ae9058ba) and the HashMap comes out without thunks.

@treeowl
Copy link
Collaborator Author

treeowl commented May 6, 2019

Great! I'll merge.

@treeowl treeowl merged commit 4fe5ed5 into haskell-unordered-containers:master May 6, 2019
@treeowl
Copy link
Collaborator Author

treeowl commented May 6, 2019

Thanks for bringing this to my attention.

@mantasg
Copy link

mantasg commented May 6, 2019

No probs. Thanks for a quick response!

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 this pull request may close these issues.

HashMap has thunks for internal nodes after construction using strict operations
2 participants