[commit: ghc] master: Check for singletons when creating Bag/OrdList from a list. (18cb4f5)
git at git.haskell.org
git at git.haskell.org
Sun Jun 3 03:21:50 UTC 2018
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/18cb4f5e1b88aef7770446a354bfcc1e0a075e89/ghc
>---------------------------------------------------------------
commit 18cb4f5e1b88aef7770446a354bfcc1e0a075e89
Author: klebinger.andreas at gmx.at <klebinger.andreas at gmx.at>
Date: Sat Jun 2 21:18:19 2018 -0400
Check for singletons when creating Bag/OrdList from a list.
This gives us `One x` instead of `Many (x : [])` reducing overhead.
For compiling spectral/simple with -O0 difference was ~ -0.05%
allocations.
The only drawback is that something like toOL (x:panic "") will now
panic. But that seems like a reasonable tradeoff.
Test Plan: ci, looking at +RTS -s
Reviewers: bgamari, jmct
Reviewed By: bgamari
Subscribers: jmct, rwbarton, thomie, carter
Differential Revision: https://phabricator.haskell.org/D4770
>---------------------------------------------------------------
18cb4f5e1b88aef7770446a354bfcc1e0a075e89
compiler/utils/Bag.hs | 1 +
compiler/utils/OrdList.hs | 1 +
2 files changed, 2 insertions(+)
diff --git a/compiler/utils/Bag.hs b/compiler/utils/Bag.hs
index 727d1c5..41c8039 100644
--- a/compiler/utils/Bag.hs
+++ b/compiler/utils/Bag.hs
@@ -328,6 +328,7 @@ mapAccumBagLM f s (ListBag xs) = do { (s', xs') <- mapAccumLM f s xs
listToBag :: [a] -> Bag a
listToBag [] = EmptyBag
+listToBag [x] = UnitBag x
listToBag vs = ListBag vs
bagToList :: Bag a -> [a]
diff --git a/compiler/utils/OrdList.hs b/compiler/utils/OrdList.hs
index 081210a..a573976 100644
--- a/compiler/utils/OrdList.hs
+++ b/compiler/utils/OrdList.hs
@@ -122,4 +122,5 @@ foldlOL k z (Many xs) = foldl k z xs
toOL :: [a] -> OrdList a
toOL [] = None
+toOL [x] = One x
toOL xs = Many xs
More information about the ghc-commits
mailing list