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

Optimize away profunctor classes when profiling (#324) #325

Merged
merged 1 commit into from Jun 29, 2020
Merged

Conversation

arybczak
Copy link
Collaborator

@arybczak arybczak commented Jun 21, 2020

Fixes #324.

Almost.

-- marked INLINE for GHC to optimize away profunctor classes when profiling.
-- See https://github.com/well-typed/optics/issues/324 for more details.
getOptic (Optic o) = o
{-# INLINE getOptic #-}
Copy link
Contributor

@phadej phadej Jun 22, 2020

Choose a reason for hiding this comment

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

doesn't {-# INLINE getOptic #-} just work when getOptic (selector) function is defined with record syntax? (That's not clear from comment, and maybe worth GHC issue & link).

Copy link

Choose a reason for hiding this comment

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

I think the inline should not be necessary, since newtypes are advertised as "zero cost" wrappers. So one would expect those to be automatically inline. Afaik the newtypes are compiled via coercions. If this gets in the way of optimizations, this feels even more like something GHC could improve.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

doesn't {-# INLINE getOptic #-} just work when getOptic (selector) function is defined with record syntax?

It doesn't seem possible to do that then.

I think the inline should not be necessary, since newtypes are advertised as "zero cost" wrappers.

Yes, it's incredibly bizarre. However, removing the INLINE pragma doesn't improve the situation.

I think it might be connected to this documentation bit:

-fprof-auto

All bindings not marked INLINE, whether exported or not, top level or nested, will be given automatic SCC annotations. Functions marked INLINE must be given a cost centre manually.

@minad
Copy link

minad commented Jun 22, 2020

The newtype unwrap function is the issue? 👀 I will check if this works for me!

@arybczak
Copy link
Collaborator Author

I'll merge after the weekend unless anyone objects.

@arybczak arybczak merged commit 62e01ff into master Jun 29, 2020
@arybczak arybczak deleted the 324-fix branch June 29, 2020 15:24
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.

GHC doesn't optimize away profunctor type classes with profiling enabled
3 participants