haskellfoundation / hs-opt-handbook.github.io

The Haskell Optimization Handbook
https://haskell.foundation/hs-opt-handbook.github.io/
Creative Commons Attribution 4.0 International
170 stars 12 forks source link

Inlining, no inline, inlinable, pragmas chapter #44

Open doyougnu opened 2 years ago

doyougnu commented 2 years ago

Show core and stg.

doyougnu commented 1 year ago

Bonus: try to correlate to too much improper inlining to more pressure on instruction caches which then cause reigster spills. Would be great to get numbers on this!

doyougnu commented 1 year ago

be sure to mention the part about unsafePerformIO here: https://markkarpov.com/tutorial/ghc-optimization-and-fusion.html#how-to-control-inlining

also: https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/core-to-core-pipeline

doyougnu commented 1 year ago

See this ticket as a case study: https://gitlab.haskell.org/ghc/ghc/-/issues/23122#note_487215

and also a good example of reading core and join point manipulation.

doyougnu commented 11 months ago

Also this ticket on the implications of -fexpose-all-unfoldings vs INLINEABLE https://gitlab.haskell.org/ghc/ghc/-/issues/21715#note_437347 with background here: https://github.com/haskell-unordered-containers/unordered-containers/pull/357

The basic gist is that INLINEABLE stores the unoptimized unfolding so that it can be later optimized is say another package, whereas -fexpose-all-unfoldings stores the optimized unfolding in the interface file so that it can be inlined later. Notice the subtle difference here, it is entirely possible that INLINEABLE optimizes better that the flag because GHC will have access to the call site, whereas the flag just says: here is your optimized version and now Im done.

doyougnu commented 11 months ago

Also this ticket which contemplates the consequences of INLINE: https://gitlab.haskell.org/ghc/ghc/-/issues/23823

One major one being that with an INLINE pragma the float out pass is skipped