Reputation: 6798
So this has to have come up several thousand times before, but I just read this article that goes into great detail why garbage collection on Android and iOS is terrible slow.
One of the main points is that garbage collection is fine as long as there is plenty of free space for the collectors to work in.
My question is: is the memory managment implementation of GHC also susceptible to this?
Upvotes: 4
Views: 245
Reputation: 28097
It can be, although the full situation is more complicated. GHC primarily uses a copying collector. GC's are triggered when the heap grows by some amount, currently 2x. Since the strategy of a copying collector is to copy live objects into new memory, it's very important that you have free RAM available, although not 6x your live data size as that article indicates. IIRC for GHC about 2.5-3x is about the minimum.
GHC also provides a compacting collector, which does not require nearly so much extra RAM. The choice between compacting and copying collection schemes is made dynamically depending on memory usage and the RTS's -c
and -M
flags.
Upvotes: 2