[Python-ideas] A Continuations Compromise in Python

Jim Jewett jimjjewett at gmail.com
Wed May 6 05:26:43 CEST 2009


On 5/3/09, Antoine Pitrou <solipsis at pitrou.net> wrote:
> Steven D'Aprano <steve at ...> writes:

>> It's hardly "premature" to notice that recursive code in Python is
>> significantly slower and less efficient than in other languages. This
>> is a known problem, or at least issue, since some people consider that
>> the solution (tail-recursion optimization) is worse that the problem.

> Is there some evidence that this "known issue" has been popping up in
> real-world production Python code

(1)  The overhead of function calls (which are more common in a
recursive style) is a real problem.

That said, it isn't clear that Tail Call Optimization would make
enough of a dent on the cost of calling a function.

(2)  The direct efficiency losses (particularly in space) show up
every time an exception is thrown for excessive recursion depth.  You
could argue that this isn't common in production code, but that is
because people learn to distort their code to avoid that limit.

The counter-argument is that sometimes excessive depth is caused by a
bug, and finding out sooner is a good thing.  Guido (and Greg, earlier
in this thread) have said that hitting the recursion limit is
*usually* a bug.  If that were true (and it might be), then tail call
optimization *in python* would usually just mean "When I write an
infinite loop, take out the breakpoints and debugging information."

-jJ


More information about the Python-ideas mailing list