on master help sign in
Fix O(n) space issue in evalStateT/runStateT
8072636Harendra Kumar
src/Streamly/Internal/Data/Stream/StreamD/Lift.hs+2−2
@@ -92,7 +92,7 @@ evalStateT initial (Stream step state) = Stream step' (state, initial)
92 {-# INLINE_LATE step' #-}
92 {-# INLINE_LATE step' #-}
93 step' gst (st, action) = do
93 step' gst (st, action) = do
94 sv <- action
94 sv <- action
95− (r, sv') <- State.runStateT (step (adaptState gst) st) sv
95+ (r, !sv') <- State.runStateT (step (adaptState gst) st) sv
96 return $ case r of
96 return $ case r of
97 Yield x s -> Yield x (s, return sv')
97 Yield x s -> Yield x (s, return sv')
98 Skip s -> Skip (s, return sv')
98 Skip s -> Skip (s, return sv')
@@ -105,7 +105,7 @@ runStateT initial (Stream step state) = Stream step' (state, initial)
105 {-# INLINE_LATE step' #-}
105 {-# INLINE_LATE step' #-}
106 step' gst (st, action) = do
106 step' gst (st, action) = do
107 sv <- action
107 sv <- action
108− (r, sv') <- State.runStateT (step (adaptState gst) st) sv
108+ (r, !sv') <- State.runStateT (step (adaptState gst) st) sv
109 return $ case r of
109 return $ case r of
110 Yield x s -> Yield (sv', x) (s, return sv')
110 Yield x s -> Yield (sv', x) (s, return sv')
111 Skip s -> Skip (s, return sv')
111 Skip s -> Skip (s, return sv')