
I have a program that uses the GHC API to provide a REPL. It winds up taking up 200mb in RAM, as measured by GHC.Stats.currentBytesUsed, but without the GHC API it's 5mb. If I turn on verbose, I can see that GHC is loading 255 modules, all loaded binary ("skipping M ( M.hs, M.hs.o )") except the toplevel, and the memory use is zooming up as it loads them. I expect some memory usage from loading modules, but 195mb seems like a lot. If I do a 'du' on the entire obj directory (which has 401 *.hs.o files... the REPL doesn't expose everything), it's only 76mb on disk. How do loaded modules wind up consuming space, and is there any way to use less space? The thing is, all those loaded modules are part of the application itself, so presumably they've already been linked into the binary and loaded into memory. The ideal would be that I could somehow reuse that. I imagine that I could by writing my own haskell interpreter and making a big symbol table of all the callable functions, but I'd rather not write my own interpreter if I can use an existing one!