What to do when garbage collector is slow?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

What to do when garbage collector is slow?

David Spies
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


_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Main.hs (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: What to do when garbage collector is slow?

John Lato-2

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.


_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: What to do when garbage collector is slow?

John Lato-2

Ah, just took a look.  I think my suggestion is unlikely to be correct.


On 08:40, Tue, Dec 23, 2014 John Lato <[hidden email]> wrote:

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.


_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: What to do when garbage collector is slow?

Adam Gundry-2
In reply to this post by David Spies
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/
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users