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

Run alter in one pass #471

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

oberblastmeister
Copy link
Contributor

@oberblastmeister oberblastmeister commented May 26, 2022

Resolves #404

@oberblastmeister oberblastmeister changed the title Alter now runs in one pass Run alter now runs in one pass May 26, 2022
@oberblastmeister oberblastmeister changed the title Run alter now runs in one pass Run alter in one pass May 26, 2022
Copy link
Member

@sjakobi sjakobi left a comment

Choose a reason for hiding this comment

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

Thanks! I have only minor comments! :)

Please update Strict.alter and Strict.update similarly. I'm curious what impact this will have on the benchmarks.

Data/HashMap/Internal.hs Outdated Show resolved Hide resolved
Data/HashMap/Internal.hs Outdated Show resolved Hide resolved
Just v' -> Collision hy $ A.snoc ls $ L k v'
| otherwise = case f Nothing of
Nothing -> t
Just v' -> runST $ two s h k v' hy t
Copy link
Member

Choose a reason for hiding this comment

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

If we use two for Collision nodes, we'll need to update its documentation. Could you do that?

#447 is related.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What should I put in the documentation? I think the function may also need a more descriptive name, like bitmapIndexedFromTwo or something.

Data/HashMap/Internal.hs Outdated Show resolved Hide resolved
Data/HashMap/Internal.hs Show resolved Hide resolved
unordered-containers.cabal Outdated Show resolved Hide resolved
@oberblastmeister
Copy link
Contributor Author

I bet we could implement delete in terms of alter with some inlining.

@sjakobi
Copy link
Member

sjakobi commented May 28, 2022

I bet we could implement delete in terms of alter with some inlining.

Probably. My inclination is not to rely on GHC optimizations more than necessary though.

Also, wouldn't this increase the size of the unfolding and thereby make it less likely that delete is inlined in user code?!

@oberblastmeister
Copy link
Contributor Author

My inclination is not to rely on GHC optimizations more than necessary though.

I think these are very simple optimizations, beta reduction and case simplification, which are performed by the ghc simplifier, and I am pretty sure these are very likely to fire. We also rely on these sorts of optimizations throughout the library anyways. It doesn't matter that much though, but would reduce a lot of code duplication, as alter is pretty much a direct copy of delete.

Why would this increase the size of the unfolding?

@sjakobi
Copy link
Member

sjakobi commented Jun 6, 2022

Sorry for the late response!

My inclination is not to rely on GHC optimizations more than necessary though.

I think these are very simple optimizations, beta reduction and case simplification, which are performed by the ghc simplifier, and I am pretty sure these are very likely to fire. We also rely on these sorts of optimizations throughout the library anyways. It doesn't matter that much though, but would reduce a lot of code duplication, as alter is pretty much a direct copy of delete.

I think this means that GHC will need to spend more cycles on optimizing usage of delete in user code. So the effect will be an increase in compile time and possibly a failure to perform other optimization once GHC runs out of simplifier iterations.

Feel free to give it a try in a follow-up PR though. I'm curious what effects this will have on the Core for delete.

Why would this increase the size of the unfolding?

My bad. Briefly, I had thought that the unfolding for delete would contain the unoptimized unfolding of alter.

@oberblastmeister
Copy link
Contributor Author

I can't really tell if the benchmarks get faster or not, which is a bit weird.

@oberblastmeister
Copy link
Contributor Author

I wonder if the old alter inlines, thus removing the closure and simplifying the cases. I am pretty sure the new alter will never inline.

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.

2 participants