Stack space used by "body-recursive calls".
Kresten Krab Thorup
Wed Jun 30 10:02:35 CEST 2010
One of my challenges in Erjang is that list comprehensions end up chewing stack space. And today I got a glimpse of hope reading this:
According to http://www.erlang.org/doc/efficiency_guide/myths.html
In R12B and later releases, there is an optimization that will in many cases reduces the number of words used on the stack in body-recursive calls, so that a body-recursive list function and tail-recursive function that calls lists:reverse/1<../man/lists.html#reverse-1> at the end will use exactly the same amount of memory. lists:map/2, lists:filter/2, list comprehensions, and many other recursive functions now use the same amount of space as their tail-recursive equivalents.
Can someone tell me, what exactly is the optimization that was done in R12B? It must be something in the runtime system that recognizes these conditions and does something smart; I'd love to be able to be equally smart.
Kresten Krab Thorup, Trifork
More information about the erlang-questions