[Haskell-cafe] Re: Why so slow?

Benjamin Franksen benjamin.franksen at bessy.de
Mon Dec 11 19:16:30 EST 2006

Lyle Kopnicky wrote:
> The code below is using way more RAM than it should. It seems to only
> take so long when I build the 'programs' list - the actual
> reading/parsing is fast. For a 5MB input file, it's using 50MB of RAM!
> Any idea how to combat this?

1) I strongly recommend to work through at least the relevant parts of the
tutorial 'Write yourself a scheme in 48 hours' (google for the title). It
explains how to use efficient parser combinator libraries, how to cleanly
separate IO from pure computations, how to use Error monad (instead of IO)
to recover from errors, etc. pp.

2) Use String or ByteString.Lazy together with readFile to read the input on
demand. Else your program must suck all of the input into memory before
processing can even start. (This works whenever processing of the input
stream is more or less sequential).


More information about the Haskell-Cafe mailing list