Space leak in partsOf #219

Open
shachaf opened this Issue Dec 30, 2012 · 0 comments

Comments

Projects
None yet
1 participant
Collaborator

shachaf commented Dec 30, 2012

partsOf traverse %~ id uses a lot of memory on big lists. Even partsOf traverse .~ [], which just reuses elements from the existing list as it sees them, does (and the same with partsOf'). The issue is outs traversing with State, and forcing the state while traversing. Reduced example:

foo :: [a] -> [a]
foo xs = evalState (traverse (\d -> do { _ <- get; return d }) xs) () -- doesn't leak
foo xs = evalState (traverse (\d -> do { !_ <- get; return d }) xs) () -- leaks

Note that Magma doesn't suffer from the same leak (but the current version does have a large constant-factor overhead).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment