[Python-Dev] Proper tail recursion (original) (raw)

Chris King colanderman at gmail.com
Fri Jul 16 14:55:08 CEST 2004


On Fri, 16 Jul 2004 15:55:32 +1200, Greg Ewing <greg at cosc.canterbury.ac.nz> wrote:

We could get the benefits of that just by eliminating recursive calls to ceval() when a Python function calls a Python function. I think that would be a worthwhile thing to do on its own, because it would mean recursion in pure Python would be limited only by available memory and not an arbitrary recursion limit, which has always seemed like a kludge to me.

The recursion limit isn't imposed so much by the C stack as it is by an an actual, arbitrary limit enforced by the interpreter (presumably to protect the C stack), one which can be effectively nullified in Python by feeding a proper value to sys.setrecursionlimit().

The point of my patch is not to eliminate the recursive nature of the interpreter (that's what Stackless is for), but to eliminate the memory usage required by recursive functions -- after 100,000 recursions, normal Python eats up nearly 80MB, whereas with this patch, it just eats up its standard 4 or 5MB or what-have-you. An unfortunate side effect of this is, of course, the elimination of correct stack traces.



More information about the Python-Dev mailing list