Thunk Accumulating Record

Mitsutoshi Aoe
Space Leak Zoo
Published in
1 min readDec 13, 2015

Thunk accumulating records or tuples are probably one of the most popular space leaks in Haskell.

Classification

Thunk accumulating records are classified as a thunk leak.

Habitat

They typically appear in a combination of a recursive (or repeatedly applying) function and a record type which have lazy fields or a standard tuple.

Fix

If the leak is from a field in a record, the easiest fix is to make the fields strict. If it’s a tuple, the thunk needs to be evaluated before putting it into the tuple. You can use either seq or the BangPatterns language extension.

Eyewitness reports

The retry package has introduced the RetryStatus type as of v0.7. In the development of v0.7, there were space leaks associated with this type.

In the retrying and recovering, the recursive functions evaluate their parameters strictly, but the fields in RetryStatus are lazy. Therefore those fields accumulates thunks each iteration.

The fix was to make these fields strict.

--

--