on master help sign in
Fix foldBreak performance issue
d163459Harendra Kumar
core/src/Streamly/Internal/Data/Stream/StreamD/Type.hs+4−1
@@ -120,6 +120,9 @@ import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
120data Stream m a =
120data Stream m a =
121 forall s. UnStream (State K.Stream m a -> s -> m (Step s a)) s
121 forall s. UnStream (State K.Stream m a -> s -> m (Step s a)) s
122
122
123+-- XXX This causes perf trouble when pattern matching with "Stream" in a
124+-- recursive way, e.g. in uncons, foldBreak, concatMap. We need to get rid of
125+-- this.
123unShare :: Stream m a -> Stream m a
126unShare :: Stream m a -> Stream m a
124unShare (UnStream step state) = UnStream step' state
127unShare (UnStream step state) = UnStream step' state
125 where step' gst = step (adaptState gst)
128 where step' gst = step (adaptState gst)
@@ -273,7 +276,7 @@ fold fld strm = do
273
276
274{-# INLINE_NORMAL foldBreak #-}
277{-# INLINE_NORMAL foldBreak #-}
275foldBreak :: Monad m => Fold m a b -> Stream m a -> m (b, Stream m a)
278foldBreak :: Monad m => Fold m a b -> Stream m a -> m (b, Stream m a)
276−foldBreak (Fold fstep begin done) (Stream step state) = do
279+foldBreak (Fold fstep begin done) (UnStream step state) = do
277 res <- begin
280 res <- begin
278 case res of
281 case res of
279 FL.Partial fs -> go SPEC fs state
282 FL.Partial fs -> go SPEC fs state