-
Notifications
You must be signed in to change notification settings - Fork 178
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
Unboxing and streamlining Map maps #873
base: master
Are you sure you want to change the base?
Conversation
366a181
to
1e2368b
Compare
Hmm.... For compatibility with potential non-GHC implementations, this needs a few changes:
|
Making progress... still don't know if performance will work. Do we have any map/coerce tests? I forget. |
75a721b
to
cefbd15
Compare
* Use an unboxed-sum version of `Maybe` to implement `mapMaybeWithKey`. This potentially (I suspect usually) allows all the `Maybe`s to be erased. * Comprehensive rewrite rules for both strict and lazy versions of `map`, `mapWithKey`, `mapMaybeWithKey`, and `filterWithKey` quickly get out of hand. Following `unordered-containers`, tame the mess by implementing both lazy and strict mapping functions in terms of versions that use unboxed results. Rewrite rules on these underlying functions will then apply uniformly. One concern: I found it a bit tricky to get the unfoldings I wanted; lots of things had to be marked `INLINABLE` explicitly.
cefbd15
to
f287120
Compare
@meooow25 Do you happen to have the bandwidth to see what effect this PR has on the benchmarks? |
I'm not very familiar with rewrite rules, but sure I could try running the benchmarks later today. |
Thanks a lot! My computer is old and wimpy and I have no time right now. I expect some things to slow down slightly, which is probably okay if not too much. I'm hoping some things will get faster. |
Here's what I got with |
Thanks a lot! I'm glad to see that performance does not seem to decrease. Unfortunately, I believe the two apparent improvements are almost certainly benchmarking artifacts. I'm disappointed that there don't seem to be any improvements to |
Hmm.... It's not at all clear to me that having a custom mapMaybeWithKey f = fromDistinctAscList . Data.Maybe.mapMaybe (\(k, v) -> ((,) k) <$> f k v) . toAscList A version of data Assoc k v = NilA | ConsA !k v (Assoc k v) That wouldn't take much more code than the current |
Use an unboxed-sum version of
Maybe
to implementmapMaybeWithKey
. This potentially (I suspect usually) allows all theMaybe
s to be erased.Comprehensive rewrite rules for both strict and lazy versions of
map
,mapWithKey
,mapMaybeWithKey
, andfilterWithKey
quickly get out of hand. Followingunordered-containers
, tame the mess by implementing both lazy and strict mapping functions in terms of versions that use unboxed results. Rewrite rules on these underlying functions will then apply uniformly. One concern: I found it a bit tricky to get the unfoldings I wanted; lots of things had to be markedINLINABLE
explicitly.