on master help sign in
Fix perf regression in zip/zipM benchmarks
f9a7d24Harendra Kumar
benchmark/Streamly/Benchmark/Prelude/ZipSerial.hs+14−2
@@ -22,10 +22,11 @@
22import Prelude hiding (zip)
22import Prelude hiding (zip)
23
23
24import Streamly (zipSerially)
24import Streamly (zipSerially)
25+import qualified Streamly as S
25import qualified Streamly.Prelude as S
26import qualified Streamly.Prelude as S
26
27
27import Streamly.Benchmark.Common
28import Streamly.Benchmark.Common
28−import Streamly.Benchmark.Prelude
29+import Streamly.Benchmark.Prelude hiding (sourceUnfoldrMN)
29
30
30import Gauge
31import Gauge
31
32
@@ -43,11 +44,22 @@ moduleName = "Prelude.ZipSerial"
43-- Zipping
44-- Zipping
44-------------------------------------------------------------------------------
45-------------------------------------------------------------------------------
45
46
47+-- XXX somehow copying this definition here instead of importing it performs
48+-- better. Need to investigate why.
49+{-# INLINE sourceUnfoldrMN #-}
50+sourceUnfoldrMN :: (S.IsStream t, S.MonadAsync m) => Int -> Int -> t m Int
51+sourceUnfoldrMN count start = S.unfoldrM step start
52+ where
53+ step cnt =
54+ if cnt > start + count
55+ then return Nothing
56+ else return (Just (cnt, cnt + 1))
57+
46{-# INLINE zip #-}
58{-# INLINE zip #-}
47zip :: Int -> Int -> IO ()
59zip :: Int -> Int -> IO ()
48zip count n =
60zip count n =
49 S.drain $
61 S.drain $
50− S.zipWith (,) (sourceUnfoldrMN count n) (sourceUnfoldrMN count (n + 1))
62+ S.zipWith (,) (S.serially $ sourceUnfoldrMN count n) (S.serially $ sourceUnfoldrMN count (n + 1))
51
63
52#ifdef INSPECTION
64#ifdef INSPECTION
53inspect $ hasNoTypeClasses 'zip
65inspect $ hasNoTypeClasses 'zip