The following code (proposed by Reid Burton in Criteria that causes a memory explosion, does not see CAFs ) has a control time that scales proportionally with num
when compiling with optimization O0. However, the use O3of optimization, apparently, leads to the reference time , regardless of num. Where in the kernel is the result cached, and what can I do to prevent it from caching?
The code:
{-# OPTIONS_GHC -fno-cse #-}
{-# LANGUAGE BangPatterns #-}
module Main where
import Criterion.Main
import Data.List
num :: Int
num = 100000000
lst :: a -> [Int]
lst _ = [1,2..num]
myadd :: Int -> Int -> Int
myadd !x !y = let !result = x + y in
result
mysum = foldl' myadd 0
main :: IO ()
main = defaultMain [
bgroup "summation"
[bench "mysum" $ whnf (mysum . lst) ()]
]
and the core:
main7
main7 = unpackCString
main8
main8 = unpackCString
Rec {
$wlgo
$wlgo =
\ ww_s6vW w_s6vT ->
case w_s6vT of _ {
[] -> ww_s6vW;
: x_a4dz xs_a4dA ->
case x_a4dz of _ { I
$wlgo (+
}
}
end Rec }
lst1
lst1 = efdtInt 1 2 100000000
lvl_r6yu
lvl_r6yu = case $wlgo 0 lst1 of ww_s6w5 { __DEFAULT -> I
Rec {
main_$s$wa
main_$s$wa =
\ sc_s6xB sc1_s6xC sc2_s6xD ->
case tagToEnum
False ->
case seq
main_$s$wa sc_s6xB (-
};
True -> (
}
end Rec }
main6
main6 =
\ w_s6w9 w1_s6wa ->
case w_s6w9 of _ { I64
main_$s$wa () ww1_s6wd w1_s6wa
}
main5
main5 = Benchmark main7 (main6 `cast` ...)
main4
main4 = : main5 ([])
main3
main3 = BenchGroup main8 main4
main2
main2 = : main3 ([])
main1
main1 = \ eta_B1 -> defaultMain2 defaultConfig main2 eta_B1
main9
main9 = \ eta_B1 -> runMainIO1 (main1 `cast` ...) eta_B1
lst
lst = \ @ a_a40V _ -> lst1
main
main = main1 `cast` ...
myadd
myadd =
\ x_a3Io y_a3Ip ->
case x_a3Io of _ { I
case y_a3Ip of _ { I
}
mysum
mysum =
\ w_s6w2 ->
case $wlgo 0 w_s6w2 of ww_s6w5 { __DEFAULT -> I
num
num = I
main
main = main9 `cast` ...
where I am tagged -ddump-simpl -fforce-recomp -O3 -dsuppress-all
at the end of the command ghc --make -no-link ...called on cabal build. I use criterion 1.1.0.0 and GHC version 7.8.3.