4 ms·
The example is definitely a memory leak, which in Haskell land means that the un-evaluated expressions keep building up into what is known as a "thunk" in memor
by bojo 5y ago
The example is definitely a memory leak, which in Haskell land means that the un-evaluated expressions keep building up into what is known as a "thunk" in memory. Example expression: ((((0+1)+2)+3)... ad infinitum)
Sure, the memory would eventually get freed in one of two cases: 1) your program crashes due to being OOM, or 2) you finally evaluate the thunk (print it, use it somewhere, etc) and spike your CPU as it is computed. Definitely not good when you are expecting linear performance.
The author fixes this by adding the BangPattern language extension, which allows the expressions passed forward to be evaluated on demand to the minimal expression before producing a value itself (also known as Weak Normal Head Form).
That all said, the more interesting part of the article as how they use cachegrind/valgrind to identify the performance characteristics of the underlying machine code, and give us some tips on what to look for if we are diving into deep level performance issues like their example.