on master help sign in
Use -funfolding-use-threshold=150 in fileio benchmark

The lines-unlines benchmark does not fuse well without this option.

commit4a367b8d99b094d610bbafcabfee4c82a06a4713 authorHarendra Kumar <harendra.kumar@gmail.com> dateSat 14 Sep 2019, 17:29 (7 years ago) parentd4495c3
4 files changed+10−4
docs/Build.md+5−3 src/Streamly/Benchmark/FileIO/Stream.hs+3−1 src/Streamly/Streams/StreamD.hs+1 streamly.cabal+1
docs/Build.md+5−3
@@ -13,9 +13,11 @@ the `SpecConstr` optimization in more cases.
1313In some cases, you may need to use `-funfolding-use-threshold` to make sure
1414that the combinators fuse. The default value of this option is `60`. Increasing
1515this default value can be detrimental in general, therefore, increase only if
16−you suspect an issue. As an example, a value of `75` is necessary and
17−sufficient to fuse `S.chunksOf n (A.writeN n)`. Hopefully GHC will fix this so
18−that it is not needed in future.
16+you suspect an issue. Hopefully GHC will fix this so that it is not needed in
17+future. Some known examples:
18+
19+* use a value of `75` to fuse `S.chunksOf n (A.writeN n)`.
20+* use a value of `150` to fully fuse `S.splitSuffixOn`.
1921
2022At the very least `-O` compilation option is required. In some cases, the
2123program may exhibit memory hog with default optimization options. For example,
src/Streamly/Benchmark/FileIO/Stream.hs+3−1
@@ -59,6 +59,7 @@ import qualified Streamly.Internal as Internal
5959import qualified Streamly.Streams.StreamD as D
6060
6161#ifdef INSPECTION
62+import Foreign.Storable (Storable)
6263import Streamly.Streams.StreamD.Type (Step(..), GroupState)
6364import Test.Inspection
6465#endif
@@ -233,6 +234,7 @@ inspect $ 'chunksOfD `hasNoType` ''AT.FlattenState
233234inspect $ 'chunksOfD `hasNoType` ''D.ConcatMapUState
234235#endif
235236
237+-- XXX splitSuffixOn requires -funfolding-use-threshold=150 for better fusion
236238-- | Lines and unlines
237239{-# INLINE linesUnlinesCopy #-}
238240linesUnlinesCopy :: Handle -> Handle -> IO ()
@@ -245,7 +247,7 @@ linesUnlinesCopy inh outh =
245247 $ FH.read inh
246248
247249#ifdef INSPECTION
248−-- inspect $ hasNoTypeClasses 'linesUnlinesCopy
250+inspect $ hasNoTypeClassesExcept 'linesUnlinesCopy [''Storable]
249251-- inspect $ 'linesUnlinesCopy `hasNoType` ''Step
250252-- inspect $ 'linesUnlinesCopy `hasNoType` ''AT.FlattenState
251253-- inspect $ 'linesUnlinesCopy `hasNoType` ''D.ConcatMapUState
src/Streamly/Streams/StreamD.hs+1
@@ -1085,6 +1085,7 @@ splitBy predicate f (Stream step state) = Stream (step' f) (Just state)
10851085
10861086 step' _ _ Nothing = return Stop
10871087
1088+-- XXX requires -funfolding-use-threshold=150 in lines-unlines benchmark
10881089{-# INLINE_NORMAL splitSuffixBy #-}
10891090splitSuffixBy :: Monad m
10901091 => (a -> Bool) -> Fold m a b -> Stream m a -> Stream m b
streamly.cabal+1
@@ -598,6 +598,7 @@ benchmark array
598598benchmark fileio
599599 import: bench-options
600600 type: exitcode-stdio-1.0
601+ ghc-options: -funfolding-use-threshold=150
601602 hs-source-dirs: benchmark
602603 main-is: FileIO.hs
603604 if flag(benchmark)