on master help sign in
Fix O(n) space issue in evalStateT/runStateT

Added strictness annotation. Space consumption now is O(1).

commit8072636a129e51e30247e244f9f43d9207f28fa8 authorHarendra Kumar <harendra@composewell.com> dateWed 2 Jun 2021, 23:04 (5 years ago) parent28e17ee
1 file changed+2−2
src/Streamly/Internal/Data/Stream/StreamD/Lift.hs+2−2
src/Streamly/Internal/Data/Stream/StreamD/Lift.hs+2−2
@@ -92,7 +92,7 @@ evalStateT initial (Stream step state) = Stream step' (state, initial)
9292 {-# INLINE_LATE step' #-}
9393 step' gst (st, action) = do
9494 sv <- action
95− (r, sv') <- State.runStateT (step (adaptState gst) st) sv
95+ (r, !sv') <- State.runStateT (step (adaptState gst) st) sv
9696 return $ case r of
9797 Yield x s -> Yield x (s, return sv')
9898 Skip s -> Skip (s, return sv')
@@ -105,7 +105,7 @@ runStateT initial (Stream step state) = Stream step' (state, initial)
105105 {-# INLINE_LATE step' #-}
106106 step' gst (st, action) = do
107107 sv <- action
108− (r, sv') <- State.runStateT (step (adaptState gst) st) sv
108+ (r, !sv') <- State.runStateT (step (adaptState gst) st) sv
109109 return $ case r of
110110 Yield x s -> Yield (sv', x) (s, return sv')
111111 Skip s -> Skip (s, return sv')