Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Work around poor GHC performance on MinJoinR and ConstUnionR#71

Merged
dwincort merged 2 commits intotarget:masterfrom
UlfNorell:union-performance
Dec 11, 2020
Merged

Work around poor GHC performance on MinJoinR and ConstUnionR#71
dwincort merged 2 commits intotarget:masterfrom
UlfNorell:union-performance

Conversation

@UlfNorell
Copy link
Contributor

GHC uses exponential(?) amounts of memory on MinJoinR and ConstUnionR when there are nested calls with many overlapping keys. This can be worked around by specializing Ifte to the branches we need in the two cases.

GHC uses exponential(?) amounts of memory on MinJoinR and ConstUnionR when there are nested calls with many overlapping keys. This can be worked around by specializing `Ifte` to the branches we need in the two cases.
@dwincort
Copy link
Collaborator

dwincort commented Dec 4, 2020

This seems great! I didn't realize that Ifte was causing performance issues, but now that I think about how type families work (that is, they're not lazy in their arguments), it makes sense. Thanks for putting together this patch!

I should have some time either this weekend or next to play around with the checks and figure out why they're failing, and then I'll happily merge.


As a side note, I wonder if there's a way to upstream Ifte as one of GHC's "magical" type families so that it really does do short-circuiting. I've been meaning to learn about magical type families, and this is just pushing me more in that direction.

@UlfNorell
Copy link
Contributor Author

@goldfirere linked me to this https://gitlab.haskell.org/ghc/ghc/-/issues/18965, which looks like it might solve the problem.

Copy link
Collaborator

@dwincort dwincort left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for upstreaming this change, and thanks also for showing me the neat trick of limiting GHC's memory in the test case to check for memory leaks! I hope GHC gets fixed in the future so that a type family like Ifte is once again usable, but in the mean time, I'll try to be careful.

Also, it's pretty cool to see people using row-types in the wild. I think your team is using variants in a bigger way than I ever have, which is surely how you found this memory bug. Let me know if you run into other issues in the future, as I'd be happy to help if I can.

@dwincort dwincort merged commit f93281a into target:master Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants