on master help sign in
Mv bemchmarks & change INLINABLE to INLINE - lastN

* Move benchmarks of lastN under serially/fold * Changing INLINEABLE to INLINE on lastN allows fusion, increasing the perf

commit5faf292267e99a5ba062ffa9bc7ce95613e2959c authoradithyaov <adi.obilisetty@gmail.com> dateTue 31 Dec 2019, 17:49 (7 years ago) parent665e7df
2 files changed+6−8
benchmark/Linear.hs+3−3 src/Streamly/Internal/Data/Stream/StreamD.hs+3−5
benchmark/Linear.hs+3−3
@@ -201,9 +201,6 @@ main =
201201 -- this is too low and causes all benchmarks reported in ns
202202 -- , benchIOSink "head" Ops.head
203203 , benchIOSink "last" Ops.last
204− , benchIOSink "lastN.1" (S.fold (IA.lastN 1))
205− , benchIOSink "lastN.10" (S.fold (IA.lastN 10))
206− , benchIOSink "lastN.Max" (S.fold (IA.lastN Ops.maxValue))
207204 -- , benchIOSink "lookup" Ops.lookup
208205 , benchIOSink "find" Ops.find
209206 , benchIOSink "findIndex" Ops.findIndex
@@ -238,6 +235,9 @@ main =
238235 , benchIOSink "drainWhileFalse" (S.fold (IFL.drainWhile $ (>=) Ops.maxValue))
239236 , benchIOSink "sink" (S.fold $ Sink.toFold Sink.drain)
240237 , benchIOSink "last" (S.fold FL.last)
238+ , benchIOSink "lastN.1" (S.fold (IA.lastN 1))
239+ , benchIOSink "lastN.10" (S.fold (IA.lastN 10))
240+ , benchIOSink "lastN.Max" (S.fold (IA.lastN Ops.maxValue))
241241 , benchIOSink "length" (S.fold FL.length)
242242 , benchIOSink "sum" (S.fold FL.sum)
243243 , benchIOSink "product" (S.fold FL.product)
src/Streamly/Internal/Data/Stream/StreamD.hs+3−5
@@ -306,8 +306,6 @@ module Streamly.Internal.Data.Stream.StreamD
306306 , applyParallel
307307 , foldParallel
308308
309− -- XXX Move this later
310− -- XXX Exported from Array again
311309 , lastN
312310 )
313311where
@@ -4019,16 +4017,16 @@ tapAsync f (Stream step1 state1) = Stream step TapInit
40194017 Skip s -> Skip (TapDone s)
40204018 Stop -> Stop
40214019
4022−-- XXX Is there room for improvement?
4020+-- XXX Exported from Array again as this fold is specific to Array
40234021-- | Take last 'n' elements from the stream and discard the rest.
4024−{-# INLINABLE lastN #-}
4022+{-# INLINE lastN #-}
40254023lastN :: (Storable a, MonadIO m) => Int -> Fold m a (Array a)
40264024lastN n = Fold step initial done
40274025 where
40284026 step (Tuple3' rb rh i) a = do
40294027 rh1 <- liftIO $ RB.unsafeInsert rb rh a
40304028 return $ Tuple3' rb rh1 (i + 1)
4031− initial = fmap (\(a, b) -> Tuple3' a b 0) $ liftIO $ RB.new n
4029+ initial = fmap (\(a, b) -> Tuple3' a b (0 :: Int)) $ liftIO $ RB.new n
40324030 done (Tuple3' rb rh i) = do
40334031 arr <- liftIO $ A.newArray n
40344032 foldFunc i rh snoc' arr rb