
Hello All, The kind people at #haskell suggested I come to haskell-cafe for questions about haskell performance issues. I'm new to haskell, and I'm having a hard time understanding how to deal with memory leaks. I've been playing with some network server examples and I noticed with each new connection, the memory footprint increases by about 7k However, the leaks don't seem to have anything to do with the networking code. Actually I get a huge leak just from using using 'forever'.
import Control.Monad import System.IO
main = forever $ putStrLn "hi"
When I run it for a few seconds with profiling...
total time = 0.36 secs (18 ticks @ 20 ms) total alloc = 54,423,396 bytes (excludes profiling overheads)
Can this be right?

inbuninbu:
Hello All,
The kind people at #haskell suggested I come to haskell-cafe for questions about haskell performance issues. I'm new to haskell, and I'm having a hard time understanding how to deal with memory leaks.
I've been playing with some network server examples and I noticed with each new connection, the memory footprint increases by about 7k However, the leaks don't seem to have anything to do with the networking code. Actually I get a huge leak just from using using 'forever'.
import Control.Monad import System.IO
main = forever $ putStrLn "hi"
When I run it for a few seconds with profiling...
total time = 0.36 secs (18 ticks @ 20 ms) total alloc = 54,423,396 bytes (excludes profiling overheads)
Can this be right?
did you compile with optimisations on? $ ghc -O2 A.hs --make $ time ./A +RTS -sstderr 17,880 bytes maximum residency (1 sample(s)) 18,984 bytes maximum slop 1 MB total memory in use (0 MB lost due to fragmentation) Generation 0: 9951 collections, 0 parallel, 0.07s, 0.07s elapsed Generation 1: 1 collections, 0 parallel, 0.00s, 0.00s elapsed INIT time 0.00s ( 0.00s elapsed) MUT time 4.45s ( 16.08s elapsed) GC time 0.07s ( 0.07s elapsed) EXIT time 0.00s ( 0.00s elapsed) Total time 4.52s ( 16.16s elapsed) %GC time 1.5% (0.5% elapsed) Alloc rate 1,173,414,505 bytes per MUT second Productivity 98.5% of total user, 27.5% of total elapsed ./A +RTS -sstderr 4.52s user 10.61s system 93% cpu 16.161 total So it's allocating small cells, frequently, then discarding them -- and running in constant space. Looking further, forever :: (Monad m) => m a -> m b forever a = a >> forever a Well, here, the result is thrown away anyway. And the result is (), so I'd expect constant space. Looks good to me. Did you run it without optimisations, on , perhaps? -- Don

On 17/02/2009, at 3:56 PM, Jeff Douglas wrote:
Hello All,
The kind people at #haskell suggested I come to haskell-cafe for questions about haskell performance issues. I'm new to haskell, and I'm having a hard time understanding how to deal with memory leaks.
I've been playing with some network server examples and I noticed with each new connection, the memory footprint increases by about 7k However, the leaks don't seem to have anything to do with the networking code. Actually I get a huge leak just from using using 'forever'.
import Control.Monad import System.IO
main = forever $ putStrLn "hi"
When I run it for a few seconds with profiling...
total time = 0.36 secs (18 ticks @ 20 ms) total alloc = 54,423,396 bytes (excludes profiling overheads)
Can this be right?
I don't think there should be a space leak in the code you posted. On my mac, OS X 10.5.6, GHC version 6.8.3, it appears to run in constant space with or without optimisation. GHCi seems to gobble a little bit of memory (but that could be incidental). My terminal application does gobble memory for a while (and then frees it), but that is presumably because it is hammering the buffer (and it nearly sets my lap on fire when running). Perhaps you could post more details about how it is compiled, and what versions of things are being used. How are you detecting the leak (via top?). Cheers, Bernie.

Thanks Guys,
Not only did I not run optimizations, I misread the profile. It looks
like it was an imaginary problem from the beginning. I guess I should
go through all the profiling documentation more carefully.
Jeff
On Tue, Feb 17, 2009 at 2:46 PM, Bernie Pope
On 17/02/2009, at 3:56 PM, Jeff Douglas wrote:
Hello All,
The kind people at #haskell suggested I come to haskell-cafe for questions about haskell performance issues. I'm new to haskell, and I'm having a hard time understanding how to deal with memory leaks.
I've been playing with some network server examples and I noticed with each new connection, the memory footprint increases by about 7k However, the leaks don't seem to have anything to do with the networking code. Actually I get a huge leak just from using using 'forever'.
import Control.Monad import System.IO
main = forever $ putStrLn "hi"
When I run it for a few seconds with profiling...
total time = 0.36 secs (18 ticks @ 20 ms) total alloc = 54,423,396 bytes (excludes profiling overheads)
Can this be right?
I don't think there should be a space leak in the code you posted.
On my mac, OS X 10.5.6, GHC version 6.8.3, it appears to run in constant space with or without optimisation.
GHCi seems to gobble a little bit of memory (but that could be incidental).
My terminal application does gobble memory for a while (and then frees it), but that is presumably because it is hammering the buffer (and it nearly sets my lap on fire when running).
Perhaps you could post more details about how it is compiled, and what versions of things are being used.
How are you detecting the leak (via top?).
Cheers, Bernie.

On Tue, Feb 17, 2009 at 5:53 AM, Jeff Douglas
Thanks Guys,
Not only did I not run optimizations, I misread the profile. It looks like it was an imaginary problem from the beginning. I guess I should go through all the profiling documentation more carefully.
Please share what you find in some way (mail/blog/anything). It'll help me avoid making the same mistakes once I get around to writing something in Haskell where I have to care about resources :-) /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe

I'd love to. I'm thinking of starting a blog once I get more
experience and familiarity with the language.
Jeff
On Wed, Feb 18, 2009 at 6:13 PM, Magnus Therning
On Tue, Feb 17, 2009 at 5:53 AM, Jeff Douglas
wrote: Thanks Guys,
Not only did I not run optimizations, I misread the profile. It looks like it was an imaginary problem from the beginning. I guess I should go through all the profiling documentation more carefully.
Please share what you find in some way (mail/blog/anything). It'll help me avoid making the same mistakes once I get around to writing something in Haskell where I have to care about resources :-)
/M
-- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe
participants (4)
-
Bernie Pope
-
Don Stewart
-
Jeff Douglas
-
Magnus Therning