[Git][ghc/ghc][wip/andreask/inline-maximimBy] Mark maximumBy/minimumBy as INLINE.
Andreas Klebinger (@AndreasK)
gitlab at gitlab.haskell.org
Fri Dec 16 19:50:01 UTC 2022
Andreas Klebinger pushed to branch wip/andreask/inline-maximimBy at Glasgow Haskell Compiler / GHC
Commits:
0e4ae488 by Andreas Klebinger at 2022-12-16T20:47:50+01:00
Mark maximumBy/minimumBy as INLINE.
The RHS was too large to inline which often prevented the overhead of the Maybe
from being optimized away. By marking it as INLINE we can eliminate the
overhead of both the maybe and are able to unpack the accumulator when
possible.
Fixes #22609
- - - - -
2 changed files:
- libraries/base/Data/Foldable.hs
- libraries/base/changelog.md
Changes:
=====================================
libraries/base/Data/Foldable.hs
=====================================
@@ -1363,7 +1363,9 @@ maximumBy cmp = fromMaybe (errorWithoutStackTrace "maximumBy: empty structure")
Just x -> case cmp x y of
GT -> x
_ -> y
-{-# INLINEABLE maximumBy #-}
+-- #22609 showed that maximumBy is too large to reliably inline,
+-- even when fully applied. So we force inlining instead.
+{-# INLINE maximumBy #-}
-- | The least element of a non-empty structure with respect to the
-- given comparison function.
@@ -1387,7 +1389,10 @@ minimumBy cmp = fromMaybe (errorWithoutStackTrace "minimumBy: empty structure")
Just x -> case cmp x y of
GT -> y
_ -> x
-{-# INLINEABLE minimumBy #-}
+-- #22609 showed that minimumBy is too large to reliably inline,
+-- even when fully applied. So we force inlining instead.
+{-# INLINE minimumBy #-}
+
-- | 'notElem' is the negation of 'elem'.
--
=====================================
libraries/base/changelog.md
=====================================
@@ -58,6 +58,8 @@
freeing a `Pool`. (#14762) (#18338)
* `Type.Reflection.Unsafe` is now marked as unsafe.
* Add `Data.Typeable.heqT`, a kind-heterogeneous version of `Data.Typeable.eqT`.
+ * `maximumBy`/`minimumBy` are now marked as `INLINE` improving performance for unpackable
+ types significantly.
## 4.17.0.0 *August 2022*
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0e4ae48805f5d5c5dcc01ed6c78b6941e3ba0022
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0e4ae48805f5d5c5dcc01ed6c78b6941e3ba0022
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20221216/9c84548c/attachment-0001.html>
More information about the ghc-commits
mailing list