on master help sign in
Annotate fold loops with INLINE_LATE

Improves the performance of fileio readStream/cat benchmark by 7x

commit981140d2c01e59b5dba70300f78f2a17652dad31 authorHarendra Kumar <harendra.kumar@gmail.com> dateSun 11 Aug 2019, 04:04 (7 years ago) parent06b0cb1
1 file changed+6
src/Streamly/Streams/StreamD/Type.hs+6
src/Streamly/Streams/StreamD/Type.hs+6
@@ -300,6 +300,7 @@ instance Monad m => Monad (Stream m) where
300300foldrM :: Monad m => (a -> m b -> m b) -> m b -> Stream m a -> m b
301301foldrM f z (Stream step state) = go SPEC state
302302 where
303+ {-# INLINE_LATE go #-}
303304 go !_ st = do
304305 r <- step defState st
305306 case r of
@@ -312,6 +313,7 @@ foldrMx :: Monad m
312313 => (a -> m x -> m x) -> m x -> (m x -> m b) -> Stream m a -> m b
313314foldrMx fstep final convert (Stream step state) = convert $ go SPEC state
314315 where
316+ {-# INLINE_LATE go #-}
315317 go !_ st = do
316318 r <- step defState st
317319 case r of
@@ -349,6 +351,7 @@ foldrS
349351 -> Stream m b
350352foldrS f final (Stream step state) = go SPEC state
351353 where
354+ {-# INLINE_LATE go #-}
352355 go !_ st = do
353356 -- defState??
354357 r <- yieldM $ step defState st
@@ -365,6 +368,7 @@ foldrT :: (Monad m, Monad (t m), MonadTrans t)
365368 => (a -> t m b -> t m b) -> t m b -> Stream m a -> t m b
366369foldrT f final (Stream step state) = go SPEC state
367370 where
371+ {-# INLINE_LATE go #-}
368372 go !_ st = do
369373 r <- lift $ step defState st
370374 case r of
@@ -383,6 +387,7 @@ foldlMx' fstep begin done (Stream step state) =
383387 begin >>= \x -> go SPEC x state
384388 where
385389 -- XXX !acc?
390+ {-# INLINE_LATE go #-}
386391 go !_ acc st = acc `seq` do
387392 r <- step defState st
388393 case r of
@@ -402,6 +407,7 @@ foldlx' fstep begin done m =
402407foldlM' :: Monad m => (b -> a -> m b) -> b -> Stream m a -> m b
403408foldlM' fstep begin (Stream step state) = go SPEC begin state
404409 where
410+ {-# INLINE_LATE go #-}
405411 go !_ acc st = acc `seq` do
406412 r <- step defState st
407413 case r of