Unzip Map and IntMap more strictly#163
Closed
treeowl wants to merge 1 commit intohaskellari:masterfrom
Closed
Conversation
The previous `Map` (same for `IntMap` throughout) instance would first map eagerly over tha `Map`, producing an entire `Map` full of thunks to apply the `unzipWith` function. Then it would build two more entire `Map`s full of thunks to select components of each pair. We can do it eagerly using `Data.Biapplicative.traverseBia` and a simple pair bifunctor.
Author
|
Note: if you really want to be super-lazy, we can at least avoid three entire unzipWith f = unSBPair . traverseBia (SBPair . blah)
where
blah c = let
{-# NOINLINE fc #-} -- make sure the result of f c is shared
{-# NOINLINE a #-} -- make sure we get selector thunks
{-# NOINLINE b #-}
fc = f c
(a, b) = fc
in (a, b) |
treeowl
added a commit
to treeowl/these
that referenced
this pull request
Aug 22, 2021
The previous `Map` (same for `IntMap` throughout) instance would first map eagerly over tha `Map`, producing an entire `Map` full of thunks to apply the `unzipWith` function. Then it would build two more entire `Map`s full of thunks to select components of each pair. Depending on inlining and such, the resulting maps may or may not have contained selector thunks; if not, they could leak memory. Fix that. NOTE: This PR is an alternative to haskellari#163. This one preserves the precise laziness properties of the previous implementation.
Author
|
I've opened #164 with a version that preserves the precise laziness of the current version but without the leak potential and without building a third map structure. |
Author
|
(Personally, I like this version better than that one, but it's not my package.) |
Collaborator
|
Ditto other PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The previous
Map(same forIntMapthroughout) instancewould first map eagerly over tha
Map, producing an entireMapfull of thunks to apply theunzipWithfunction. Thenit would build two more entire
Maps full of thunks to selectcomponents of each pair. We can do it eagerly using
Data.Biapplicative.traverseBiaand a simple pair bifunctor.