After few hours of debugging, I realized that a very simple toy example was not efficient due to a missing !
in an expression return $ 1 + x
(thanks du
There is a specific class of space leaks that can be detected because they use excessive amounts of stack when they unwind the excessive heap usage. The following website lists the specific approaches, along with lots of case studies, but roughly:
+RTS -K10K
to limit the stack to 10Kb.+RTS -xc
to get stack traces.It's not a perfect approach since sometimes you have memory leaks without excessive stack usage, and sometimes you have excessive stack usage without memory leaks, but the correspondence is pretty good and the tooling can be deployed on CI to stop introducing new leaks.