on master help sign in
Short circuit Skip case in toStreamK

When fusion does not occur due to conversion to StreamK, the Skip constructor being threaded around StreamK can cause a lot of performance degradation. Skip case is of no use to StreamK. This improved the performance of fasta benchmark from 7 secs to 2.8 secs. Code change suggested by Pranay Sashank.

commit35ba2c3279ccdb441da51f93fed36b69c217c783 authorHarendra Kumar <harendra.kumar@gmail.com> dateSat 23 Nov 2019, 05:08 (7 years ago) parentd0896e1
1 file changed+8−6
src/Streamly/Internal/Data/Stream/StreamD/Type.hs+8−6
src/Streamly/Internal/Data/Stream/StreamD/Type.hs+8−6
@@ -131,12 +131,14 @@ fromStreamK = Stream step
131131toStreamK :: Monad m => Stream m a -> K.Stream m a
132132toStreamK (Stream step state) = go state
133133 where
134− go st = K.mkStream $ \gst yld sng stp -> do
135− r <- step gst st
136− case r of
137− Yield x s -> yld x (go s)
138− Skip s -> K.foldStreamShared gst yld sng stp $ go s
139− Stop -> stp
134+ go st = K.mkStream $ \gst yld _ stp ->
135+ let go' ss = do
136+ r <- step gst ss
137+ case r of
138+ Yield x s -> yld x (go s)
139+ Skip s -> go' s
140+ Stop -> stp
141+ in go' st
140142
141143#ifndef DISABLE_FUSION
142144{-# RULES "fromStreamK/toStreamK fusion"