Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Garbage Collection in GHC Haskell?

Tags:

haskell

ghc

How can I disable GCs, or vastly decrease the frequency of GCs?

Like giving it an +RTS option for some huge heap or or allocation size maybe?

I want to see how my program behaves when no GCs happen.

like image 893
nh2 Avatar asked Apr 09 '15 15:04

nh2


2 Answers

I had good results combining nh2 and Thomas's answers into

+RTS -I0 -A90G -G1 -m1 -RTS

I have 100 GB of RAM, so I thought 90G was a good allocation area size.

I also used System.Mem.performGC to manually trigger GC at appropriate points and GHC.Stats to keep track of how much time has been spent in GC.

like image 79
Tom Ellis Avatar answered Sep 19 '22 15:09

Tom Ellis


(With the help from carter in #ghc on freenode)

There is no switch to completely disable GC. Instead, use all of the following +RTS runtime options:

  • Disable idle time garbage collection using -I0.
  • Set the "nursery" == "allocation area" size to something very large, e.g. -A100G, as GC will only be done when the allocation area is full.

See https://downloads.haskell.org/~ghc/7.8-latest/docs/html/users_guide/runtime-control.html for a description of these options.

Be aware that you will run out of RAM quickly.

like image 31
nh2 Avatar answered Sep 22 '22 15:09

nh2