summaryrefslogtreecommitdiff
path: root/testsuite/tests/perf/compiler
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2020-06-19 09:05:08 +0100
committerBen Gamari <ben@smart-cactus.org>2020-07-13 14:52:49 -0400
commit7ccb760b1a8034b28171d7540712fd195f65d1fd (patch)
tree2a1a670a396f5dedf25c5f871cf9a27ae313e197 /testsuite/tests/perf/compiler
parente78c4efb8735eb97f17e7b4ca35e305b0766f78a (diff)
downloadhaskell-7ccb760b1a8034b28171d7540712fd195f65d1fd.tar.gz
Reduce result discount in conSize
Ticket #18282 showed that the result discount given by conSize was massively too large. This patch reduces that discount to a constant 10, which just balances the cost of the constructor application itself. Note [Constructor size and result discount] elaborates, as does the ticket #18282. Reducing result discount reduces inlining, which affects perf. I found that I could increase the unfoldingUseThrehold from 80 to 90 in compensation; in combination with the result discount change I get these overall nofib numbers: Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- boyer -0.2% +5.4% -3.2% -3.4% 0.0% cichelli -0.1% +5.9% -11.2% -11.7% 0.0% compress2 -0.2% +9.6% -6.0% -6.8% 0.0% cryptarithm2 -0.1% -3.9% -6.0% -5.7% 0.0% gamteb -0.2% +2.6% -13.8% -14.4% 0.0% genfft -0.1% -1.6% -29.5% -29.9% 0.0% gg -0.0% -2.2% -17.2% -17.8% -20.0% life -0.1% -2.2% -62.3% -63.4% 0.0% mate +0.0% +1.4% -5.1% -5.1% -14.3% parser -0.2% -2.1% +7.4% +6.7% 0.0% primetest -0.2% -12.8% -14.3% -14.2% 0.0% puzzle -0.2% +2.1% -10.0% -10.4% 0.0% rsa -0.2% -11.7% -3.7% -3.8% 0.0% simple -0.2% +2.8% -36.7% -38.3% -2.2% wheel-sieve2 -0.1% -19.2% -48.8% -49.2% -42.9% -------------------------------------------------------------------------------- Min -0.4% -19.2% -62.3% -63.4% -42.9% Max +0.3% +9.6% +7.4% +11.0% +16.7% Geometric Mean -0.1% -0.3% -17.6% -18.0% -0.7% I'm ok with these numbers, remembering that this change removes an *exponential* increase in code size in some in-the-wild cases. I investigated compress2. The difference is entirely caused by this function no longer inlining WriteRoutines.$woutputCodes = \ (w :: [CodeEvent]) -> let result_s1Sr = case WriteRoutines.outputCodes_$s$woutput w 0# 0# 8# 9# of (# ww1, ww2 #) -> (ww1, ww2) in (# case result_s1Sr of (x, _) -> map @Int @Char WriteRoutines.outputCodes1 x , case result_s1Sr of { (_, y) -> y } #) It was right on the cusp before, driven by the excessive result discount. Too bad! Happily, the compiler/perf tests show a number of improvements: T12227 compiler bytes-alloc -6.6% T12545 compiler bytes-alloc -4.7% T13056 compiler bytes-alloc -3.3% T15263 runtime bytes-alloc -13.1% T17499 runtime bytes-alloc -14.3% T3294 compiler bytes-alloc -1.1% T5030 compiler bytes-alloc -11.7% T9872a compiler bytes-alloc -2.0% T9872b compiler bytes-alloc -1.2% T9872c compiler bytes-alloc -1.5% Metric Decrease: T12227 T12545 T13056 T15263 T17499 T3294 T5030 T9872a T9872b T9872c
Diffstat (limited to 'testsuite/tests/perf/compiler')
-rw-r--r--testsuite/tests/perf/compiler/T18282.hs40
-rw-r--r--testsuite/tests/perf/compiler/all.T6
2 files changed, 46 insertions, 0 deletions
diff --git a/testsuite/tests/perf/compiler/T18282.hs b/testsuite/tests/perf/compiler/T18282.hs
new file mode 100644
index 0000000000..9039f0ad0f
--- /dev/null
+++ b/testsuite/tests/perf/compiler/T18282.hs
@@ -0,0 +1,40 @@
+module M
+ ( mkB2
+ ) where
+
+import Control.Monad.Reader
+import Data.Maybe
+
+data A1 = A1 (Maybe String) (Maybe String) (Maybe String) (Maybe String)
+data A2 = A2 A1 (Maybe String) (Maybe String) (Maybe String) (Maybe String)
+ (Maybe String) (Maybe String) (Maybe String) (Maybe String)
+
+data B1 = B1 !String !String !String !String
+data B2 = B2 !B1 !String !String !String !String !String !String !String !String
+
+type M a = ReaderT [(String, String)] (Either String) a
+
+resolve :: Maybe String -> String -> M (Maybe String)
+resolve (Just x) _ = pure (Just x)
+resolve Nothing v = asks $ lookup v
+
+mkB1 :: A1 -> M B1
+mkB1 (A1 a b c d) = do
+ a' <- fromMaybe "" <$> resolve a "A"
+ b' <- fromMaybe "" <$> resolve b "B"
+ c' <- fromMaybe "" <$> resolve c "C"
+ d' <- fromMaybe "" <$> resolve d "D"
+ pure $ B1 a' b' c' d'
+
+mkB2 :: A2 -> M B2
+mkB2 (A2 a b c d e f g h i) = do
+ a' <- mkB1 a
+ b' <- fromMaybe "db" <$> resolve b "B"
+ c' <- fromMaybe "dc" <$> resolve c "C"
+ d' <- fromMaybe "dd" <$> resolve d "D"
+ e' <- fromMaybe "de" <$> resolve e "E"
+ f' <- fromMaybe "df" <$> resolve f "F"
+ g' <- fromMaybe "dg" <$> resolve g "G"
+ h' <- fromMaybe "dh" <$> resolve h "H"
+ i' <- fromMaybe "di" <$> resolve i "I"
+ pure $ B2 a' b' c' d' e' f' g' h' i'
diff --git a/testsuite/tests/perf/compiler/all.T b/testsuite/tests/perf/compiler/all.T
index e993d40587..2755024a9a 100644
--- a/testsuite/tests/perf/compiler/all.T
+++ b/testsuite/tests/perf/compiler/all.T
@@ -382,3 +382,9 @@ test ('T18304',
],
compile,
['-v0 -O'])
+
+test ('T18282',
+ [ collect_compiler_stats('bytes allocated',2)
+ ],
+ compile,
+ ['-v0 -O'])