You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found and fixed lots of small space leaks in cassava but rewriting several of the combinators like so:
--| Specialized version of 'sepBy1'' which is faster due to not-- accepting an arbitrary separator.sepByDelim1'::AL.Parsera->Word8--^ Field delimiter->AL.Parser [a]
sepByDelim1' p !delim = liftM2' (:) p loop
where
loop =do
mb <-A.peekWord8
case mb ofJust b | b == delim -> liftM2' (:) (A.anyWord8 *> p) loop
_ ->pure[]
{-# INLINE sepByDelim1' #-}
(Ignore the use of peekWord8 instead of <|>, that's an optimization specific to my case.)
Note the use of liftM2' instead of (:) <$> (A.anyWord8 *> p) <*> loop. Without liftM2' we're building up a thunk in the list. This thunk will always be evaluated when we eventually run the parser so creating it here is unnecessary and wastes space. I would guess that (almost) all uses of <$> and <*> should be replaced by strict versions.
The text was updated successfully, but these errors were encountered:
I found and fixed lots of small space leaks in cassava but rewriting several of the combinators like so:
(Ignore the use of
peekWord8
instead of<|>
, that's an optimization specific to my case.)Note the use of
liftM2'
instead of(:) <$> (A.anyWord8 *> p) <*> loop
. WithoutliftM2'
we're building up a thunk in the list. This thunk will always be evaluated when we eventually run the parser so creating it here is unnecessary and wastes space. I would guess that (almost) all uses of<$>
and<*>
should be replaced by strict versions.The text was updated successfully, but these errors were encountered: