[Haskell-cafe] Example programs with ample use of deepseq?

Erik Hesselink hesselink at gmail.com
Wed Jan 9 14:23:34 CET 2013


On Tue, Jan 8, 2013 at 10:54 PM, Joachim Breitner
<mail at joachim-breitner.de> wrote:
> Am Dienstag, den 08.01.2013, 13:01 -0800 schrieb Evan Laforge:
>> > surprisingly, deepseq is not used as much as I thought.
>> > http://packdeps.haskellers.com/reverse/deepseq lists a lot of packages,
>> > but (after grepping through some of the code) most just define NFData
>> > instances and/or use it in tests, but rarely in the „real“ code. For
>> > some reason I expected it to be in more widespread use.
>>
>> I've been using deepseq quite a bit lately, but for the purpose of
>> debugging space leaks.  If, when I deepseq a big structure, the space
>> leak goes away, I can then apply it to some subset.  After much
>> trial-and-error I can find something which is insufficiently strict.
>> Ideally I can then strictify that one thing and stop using the
>> deepseq.  I wish there was a more efficient way to do this.
>
> this is also a possible application of my approach, by providing a „I
> want this data structure to be fully evaluated now, please tell me how
> it currently looks, i.e. where in the data structure still thunks lie
> hidden.“
>
> Do you have a nice, striking example where using your approach (using
> deepseq and comparing efficiency) you could make a difference, and where
> a tool as described above would make the analysis much easier?

We've also used this approach to debug space-leaks, and would have
loved such a tool. We used deepseq, and compared the heap profiles. We
finally found the leaks this way, and fixed them using strictness
annotations. Finally, we verified by running deepseq again at top
level and observing that it didn't change anything anymore.

Erik



More information about the Haskell-Cafe mailing list