
I have a program that, to all appearances, is behaving properly. It uses very little memory to run, it has the profile I would expect looking at +RTS -hc. I have no reason to believe there is a memory leak (in the sense that it's not lazily holding on to things it no longer needs or strictly generating things it doesn't need yet). But it's slow, and according to -sstderr, most of the time is spent garbage-collecting. Why is the garbage-collector consuming so much running time? How can I deal with it? The program is a solution to this problem: https://open.kattis.com/problems/tourist The input data can be found here: http://heim.ifi.uio.no/~db/nm-i-programmering/nm2004/testdata/h.in

Can't try your code now, but have you tried using threadscope? Just a thought, but maybe the garbage collection is blocked waiting for a thread to finish.

Hi David, On 23/12/14 10:59, David Spies wrote:
I have a program that, to all appearances, is behaving properly. It uses very little memory to run, it has the profile I would expect looking at +RTS -hc. I have no reason to believe there is a memory leak (in the sense that it's not lazily holding on to things it no longer needs or strictly generating things it doesn't need yet). But it's slow, and according to -sstderr, most of the time is spent garbage-collecting.
Why is the garbage-collector consuming so much running time? How can I deal with it?
It's entirely possible that your program is allocating a lot of data that quickly becomes garbage, even if it is not holding on to it for too long (i.e. leaking memory). Remember that the heap profile shows only data that is being retained, so there might be unnecessary allocation even if the heap profile looks sensible. You can use a time and allocation profile (-p) to find out what is doing most of the allocation. A quick glance at the profile suggests that funArray and mapWithIdx, both of which construct lists and then immediately turn them into arrays, are the likely culprits. Perhaps you can avoid constructing the intermediate lists? Hope this helps, Adam
The program is a solution to this problem: https://open.kattis.com/problems/tourist
The input data can be found here: http://heim.ifi.uio.no/~db/nm-i-programmering/nm2004/testdata/h.in
-- Adam Gundry, Haskell Consultant Well-Typed LLP, http://www.well-typed.com/
participants (3)
-
Adam Gundry
-
David Spies
-
John Lato