Search code examples
haskellgarbage-collectiondelay

How long pauses can occur in a Haskell program due to garbage collection?


Relating to my other question Haskell collections with guaranteed worst-case bounds for every single operation?, I'm curious: How long pauses can be caused by garbage collection?

Does Haskell use some kind of incremental garbage collection so that a program is stopped only for small periods at a time, or can it stop for several seconds in an extreme case?

I found two SPJ's papers on the subject: https://research.microsoft.com/en-us/um/people/simonpj/papers/non-stop/index.htm. But I didn't find a reference if these ideas were actually adopted by GHC (or other Haskell implementations).


Solution

  • GHC is designed for computational throughput, not latency. As a result, GHC uses a generational, multi-threaded garbage collector with thread-local heaps. Garbage collection of thread-local objects does not stop other threads. The occasional major GC of the global heap will pause all threads.

    Typically the pauses are in the small number of milliseconds, however there is no guarantee of latency.

    You can control the frequency of GC via several runtime flags (e.g. the gc -I interval).